diff --git a/README.md b/README.md index 8e6c4f5b..afc53b50 100644 --- a/README.md +++ b/README.md @@ -140,8 +140,6 @@ USAGE: OPTIONS: --file value, -f value specify the path to markdown file. (default: stdin) - --two-spaces, --ts set this option when the markdown indent is 2 spaces. (default: tab spaces) - --four-spaces, --fs set this option when the markdown indent is 4 spaces. (default: tab spaces) --massive, -m set this option when there are very many blocks of markdown. (default: false) --massive-timeout value, --mt value set this option if you want to set a timeout. (default: 0s) --json, -j set this option when outputting JSON. (default: tree) @@ -176,7 +174,7 @@ gtree └── tree.go ``` -When Markdown is indented as a tab. +Other pattern. ``` ├── gtree output -f testdata/sample1.md @@ -213,35 +211,6 @@ k8s_resources └── container(s) ``` -#### Two spaces indent - -```console -$ cat testdata/sample4.md | gtree output -ts -a -├── i -│ ├── u -│ │ ├── k -│ │ └── kk -│ └── t -├── e -│ └── o -└── g -``` - -#### Four spaces indent - -```console -$ cat testdata/sample5.md | gtree output -fs -a -├── i -│ ├── u -│ │ ├── k -│ │ └── kk -│ └── t -├── e -│ └── o -└── g -``` #### Multiple roots @@ -383,8 +352,6 @@ USAGE: OPTIONS: --file value, -f value specify the path to markdown file. (default: stdin) - --two-spaces, --ts set this option when the markdown indent is 2 spaces. (default: tab spaces) - --four-spaces, --fs set this option when the markdown indent is 4 spaces. (default: tab spaces) --dry-run, -d, --dr dry run. detects node that is invalid for directory generation. the order of the output and made directories does not always match. (default: false) --extension value, -e value, --ext value [ --extension value, -e value, --ext value ] set this option if you want to create file instead of directory. @@ -502,8 +469,6 @@ USAGE: OPTIONS: --file value, -f value specify the path to markdown file. (default: stdin) - --two-spaces, --ts set this option when the markdown indent is 2 spaces. (default: tab spaces) - --four-spaces, --fs set this option when the markdown indent is 4 spaces. (default: tab spaces) --target-dir value set this option if you want to specify the directory you want to verify. (default: current directory) --strict set this option if you want strict directory match validation. (default: non strict) --help, -h show help @@ -582,7 +547,6 @@ import ( ) func main() { - // input Markdown is tab indented r1 := bytes.NewBufferString(strings.TrimSpace(` - root - dddd @@ -616,7 +580,6 @@ func main() { // │ └── AAAAAAA // └── eee - // input Markdown is two spaces indented r2 := bytes.NewBufferString(strings.TrimSpace(` - a - i @@ -627,10 +590,9 @@ func main() { - e - o - g`)) - // When indentation is four spaces, use WithIndentFourSpaces func instead of WithIndentTwoSpaces func. - // and, you can customize branch format. + + // You can customize branch format. if err := gtree.Output(os.Stdout, r2, - gtree.WithIndentTwoSpaces(), gtree.WithBranchFormatIntermedialNode("+->", ": "), gtree.WithBranchFormatLastNode("+->", " "), ); err != nil { diff --git a/assets/demo.gif b/assets/demo.gif index d0389ea8..c76e9544 100644 Binary files a/assets/demo.gif and b/assets/demo.gif differ diff --git a/assets/demo.tape b/assets/demo.tape index ca7dcfd5..84008ec7 100644 --- a/assets/demo.tape +++ b/assets/demo.tape @@ -23,34 +23,18 @@ Hide Type "clear" Enter Show -Type "cat testdata/sample4.md" +Type "cat testdata/sample2.md" Sleep 2s Enter -Sleep 2s +Sleep 4s Hide -Type "cat testdata/sample4.md" +Type "cat testdata/sample2.md" Show Sleep 2s -Type " | gtree output --two-spaces" -Sleep 2s -Enter -Sleep 5s -Hide -Type "clear" Enter -Show - -Type "cat testdata/sample5.md" -Sleep 2s -Enter -Sleep 2s -Hide -Type "cat testdata/sample5.md" -Show -Sleep 2s -Type " | gtree output --four-spaces" +Type " | gtree output" Sleep 2s Enter -Sleep 5s +Sleep 6s Hide Type "clear" Enter Show diff --git a/cmd/gtree-wasm/main.go b/cmd/gtree-wasm/main.go index c8bc5d4f..6be58bf8 100644 --- a/cmd/gtree-wasm/main.go +++ b/cmd/gtree-wasm/main.go @@ -38,7 +38,6 @@ func gtree(this js.Value, args []js.Value) interface{} { r := strings.NewReader(rawInput) w := &strings.Builder{} options := []gt.Option{ - gt.WithIndentTwoSpaces(), gt.WithBranchFormatLastNode(lastNodeBranchDirectly, lastNodeBranchIndirectly), gt.WithBranchFormatIntermedialNode(intermedialNodeBranchDirectly, intermedialNodeBranchIndirectly), } diff --git a/cmd/gtree-wasm/service_worker.js b/cmd/gtree-wasm/service_worker.js index 02049a5f..00355e89 100644 --- a/cmd/gtree-wasm/service_worker.js +++ b/cmd/gtree-wasm/service_worker.js @@ -1,7 +1,7 @@ // copied by https://laboradian.com/create-offline-site-using-sw/ // TODO: ファイル変更したらCACHE_VERSIONを変えてデプロイすること -const CACHE_VERSION = 'v1.1.7'; +const CACHE_VERSION = 'v1.1.8'; const CACHE_NAME = `${registration.scope}!${CACHE_VERSION}`; // キャッシュするファイルをセットする diff --git a/cmd/gtree/indent.go b/cmd/gtree/indent.go deleted file mode 100644 index fa094080..00000000 --- a/cmd/gtree/indent.go +++ /dev/null @@ -1,55 +0,0 @@ -package main - -import ( - "errors" - - "github.com/ddddddO/gtree" - "github.com/urfave/cli/v2" -) - -type spacesType uint - -const ( - spacesTwo spacesType = 1 << iota - spacesFour -) - -type stateIndentation struct { - spaces spacesType -} - -func optionIndentation(c *cli.Context) (gtree.Option, error) { - s := &stateIndentation{} - if c.Bool("two-spaces") { - s.spaces |= spacesTwo - } - if c.Bool("four-spaces") { - s.spaces |= spacesFour - } - - return s.decideOption() -} - -func (s *stateIndentation) decideOption() (gtree.Option, error) { - if err := s.validate(); err != nil { - return nil, err - } - - switch s.spaces { - case spacesTwo: - return gtree.WithIndentTwoSpaces(), nil - case spacesFour: - return gtree.WithIndentFourSpaces(), nil - } - return nil, nil -} - -const spacesTab = spacesType(0) - -func (s *stateIndentation) validate() error { - switch s.spaces { - case spacesTab, spacesTwo, spacesFour: - return nil - } - return errors.New(`choose either "two-spaces(ts)" or "four-spaces(fs)" or blank.`) -} diff --git a/cmd/gtree/main.go b/cmd/gtree/main.go index 6bab7233..05ca7694 100644 --- a/cmd/gtree/main.go +++ b/cmd/gtree/main.go @@ -26,18 +26,6 @@ func main() { Usage: "specify the path to markdown file.", DefaultText: "stdin", }, - &cli.BoolFlag{ - Name: "two-spaces", - Aliases: []string{"ts"}, - Usage: "set this option when the markdown indent is 2 spaces.", - DefaultText: "tab spaces", - }, - &cli.BoolFlag{ - Name: "four-spaces", - Aliases: []string{"fs"}, - Usage: "set this option when the markdown indent is 4 spaces.", - DefaultText: "tab spaces", - }, } outputFlags := []cli.Flag{ @@ -217,10 +205,6 @@ func notExistArgs(c *cli.Context) error { } func actionOutput(c *cli.Context) error { - oi, err := optionIndentation(c) - if err != nil { - return exitErrOpts(err) - } oo, err := optionOutput(c) if err != nil { return exitErrOpts(err) @@ -234,7 +218,7 @@ func actionOutput(c *cli.Context) error { defer cancel() om = gtree.WithMassive(ctx) } - options := []gtree.Option{oi, oo, om} + options := []gtree.Option{oo, om} markdownPath := c.Path("file") if isInputStdin(markdownPath) { @@ -276,12 +260,7 @@ func actionMkdir(c *cli.Context) error { defer in.Close() } - oi, err := optionIndentation(c) - if err != nil { - return exitErrOpts(err) - } - oe := gtree.WithFileExtensions(c.StringSlice("extension")) - options := []gtree.Option{oi, oe} + options := []gtree.Option{gtree.WithFileExtensions(c.StringSlice("extension"))} if c.Bool("massive") { options = append(options, gtree.WithMassive(context.Background())) } @@ -317,11 +296,7 @@ func actionVerify(c *cli.Context) error { defer in.Close() } - oi, err := optionIndentation(c) - if err != nil { - return exitErrOpts(err) - } - options := []gtree.Option{oi, gtree.WithTargetDir(c.String("target-dir"))} + options := []gtree.Option{gtree.WithTargetDir(c.String("target-dir"))} if c.Bool("strict") { options = append(options, gtree.WithStrictVerify()) } diff --git a/config.go b/config.go index 286e6dfd..27f4953e 100644 --- a/config.go +++ b/config.go @@ -6,7 +6,6 @@ type config struct { lastNodeFormat branchFormat intermedialNodeFormat branchFormat - space spaceType massive bool ctx context.Context encode encode @@ -26,7 +25,6 @@ func newConfig(options []Option) *config { directly: "├──", indirectly: "│ ", }, - space: spacesTab, massive: false, encode: encodeDefault, targetDir: ".", @@ -43,20 +41,6 @@ func newConfig(options []Option) *config { // Option is functional options pattern type Option func(*config) -// WithIndentTwoSpaces returns function for two spaces indent input. -func WithIndentTwoSpaces() Option { - return func(c *config) { - c.space = spacesTwo - } -} - -// WithIndentFourSpaces returns function for four spaces indent input. -func WithIndentFourSpaces() Option { - return func(c *config) { - c.space = spacesFour - } -} - // WithBranchFormatIntermedialNode returns function for branch format. func WithBranchFormatIntermedialNode(directly, indirectly string) Option { return func(c *config) { diff --git a/docs/main.wasm b/docs/main.wasm index 250bcb74..61e381c0 100644 Binary files a/docs/main.wasm and b/docs/main.wasm differ diff --git a/docs/service_worker.js b/docs/service_worker.js index 02049a5f..00355e89 100644 --- a/docs/service_worker.js +++ b/docs/service_worker.js @@ -1,7 +1,7 @@ // copied by https://laboradian.com/create-offline-site-using-sw/ // TODO: ファイル変更したらCACHE_VERSIONを変えてデプロイすること -const CACHE_VERSION = 'v1.1.7'; +const CACHE_VERSION = 'v1.1.8'; const CACHE_NAME = `${registration.scope}!${CACHE_VERSION}`; // キャッシュするファイルをセットする diff --git a/example/like_cli/adapter/indentation.go b/example/like_cli/adapter/indentation.go index 44485cf2..26951084 100644 --- a/example/like_cli/adapter/indentation.go +++ b/example/like_cli/adapter/indentation.go @@ -33,7 +33,7 @@ type TwoSpaces struct { // Output is ... func (ts *TwoSpaces) Output() error { buf := &bytes.Buffer{} - if err := gtree.Output(buf, ts.Data, gtree.WithIndentTwoSpaces()); err != nil { + if err := gtree.Output(buf, ts.Data); err != nil { return err } fmt.Printf("%s\n\n", buf.String()) @@ -47,5 +47,5 @@ type FourSpaces struct { // Output is ... func (fs *FourSpaces) Output() error { - return gtree.Output(os.Stdout, fs.Data, gtree.WithIndentFourSpaces()) + return gtree.Output(os.Stdout, fs.Data) } diff --git a/markdown/parser.go b/markdown/parser.go index e3da33e4..b3379418 100644 --- a/markdown/parser.go +++ b/markdown/parser.go @@ -3,6 +3,7 @@ package markdown import ( "errors" "strings" + "sync" ) // 一旦簡易なパーサー @@ -10,21 +11,14 @@ type Parser struct { // rootが#要素かフラグ // #であれば次の#までのhierarchyは+=1 isSharpRoot bool + mu sync.RWMutex spaces int sep string } // TODO: 要リファクタ -func NewParser(spaces int) *Parser { - sep := space - if spaces == 1 { - sep = tab - } - - return &Parser{ - spaces: spaces, - sep: sep, - } +func NewParser() *Parser { + return &Parser{} } const ( @@ -63,6 +57,9 @@ func (p *Parser) Parse(row string) (*Markdown, error) { }, nil } + p.mu.Lock() + defer p.mu.Unlock() + spaceCount, afterText, err := p.separateRow(row) if err != nil { return nil, err @@ -94,13 +91,43 @@ func (p *Parser) separateRow(row string) (int, string, error) { err = ErrIncorrectFormat continue } + + if len(before) != 0 { + sep := strings.Split(before, "")[0] + if sep == space || sep == tab { + if p.sep == "" { + p.sep = sep + } + } else { + err = ErrIncorrectFormat + // p.sep = "" + continue + } + } else { + p.sep = "" + } + spaceCount := strings.Count(before, p.sep) - if spaceCount != len(before) { + if p.sep != "" && spaceCount != len(before) { err = ErrIncorrectFormat + // p.sep = "" continue } + + if p.sep == "" { + spaceCount = 0 + } + + // Root行だとspaceCountは0にしかならない + // Rootの次行のスペース数を一度だけ取得し、それをMarkdown全体のパースで利用する + if spaceCount > 0 && p.spaces == 0 { + p.spaces = spaceCount + } + if e := p.validateSpaces(spaceCount); e != nil { err = e + // p.sep = "" + // p.spaces = 0 continue } @@ -111,7 +138,7 @@ func (p *Parser) separateRow(row string) (int, string, error) { } func (p *Parser) validateSpaces(spaceCount int) error { - if p.isTab() { + if p.spaces <= 1 { return nil } if spaceCount%p.spaces != 0 { @@ -122,7 +149,7 @@ func (p *Parser) validateSpaces(spaceCount int) error { func (p *Parser) calculateHierarchy(spaceCount int) uint { var hierarchy uint - if p.isTab() { + if p.spaces == 0 || p.sep == "" { hierarchy = uint(spaceCount) + rootHierarchyNum } else { hierarchy = uint(spaceCount/p.spaces) + rootHierarchyNum @@ -133,7 +160,3 @@ func (p *Parser) calculateHierarchy(spaceCount int) uint { } return hierarchy } - -func (p *Parser) isTab() bool { - return p.spaces == 1 -} diff --git a/markdown/parser_test.go b/markdown/parser_test.go index 6b303d3b..a2032fc4 100644 --- a/markdown/parser_test.go +++ b/markdown/parser_test.go @@ -83,10 +83,9 @@ func TestParser_ParseTab(t *testing.T) { }, } - indentSpaces := 1 for name, tt := range tests { tt := tt - parser := NewParser(indentSpaces) + parser := NewParser() t.Run(name, func(t *testing.T) { t.Parallel() @@ -177,10 +176,9 @@ func TestParser_ParseTwoSpaces(t *testing.T) { }, } - indentSpaces := 2 for name, tt := range tests { tt := tt - parser := NewParser(indentSpaces) + parser := NewParser() t.Run(name, func(t *testing.T) { t.Parallel() @@ -271,10 +269,9 @@ func TestParser_ParseFourSpaces(t *testing.T) { }, } - indentSpaces := 4 for name, tt := range tests { tt := tt - parser := NewParser(indentSpaces) + parser := NewParser() t.Run(name, func(t *testing.T) { t.Parallel() diff --git a/node_generator.go b/node_generator.go index 1f43bba5..f5d1ff22 100644 --- a/node_generator.go +++ b/node_generator.go @@ -7,30 +7,13 @@ import ( md "github.com/ddddddO/gtree/markdown" ) -type spaceType int - -const ( - spacesTab spaceType = iota - spacesTwo - spacesFour -) - type nodeGenerator struct { parser *md.Parser } -func newNodeGenerator(st spaceType) *nodeGenerator { - var p *md.Parser - switch st { - case spacesTwo: - p = md.NewParser(2) - case spacesFour: - p = md.NewParser(4) - default: - p = md.NewParser(1) - } +func newNodeGenerator() *nodeGenerator { return &nodeGenerator{ - parser: p, + parser: md.NewParser(), } } diff --git a/node_generator_test.go b/node_generator_test.go index c262253e..e1b80f78 100644 --- a/node_generator_test.go +++ b/node_generator_test.go @@ -23,13 +23,14 @@ func TestGenerateTab(t *testing.T) { "root/hierarchy=1": {"- aaa bb", &want{name: "aaa bb", hierarchy: 1, index: fixedIndex, err: nil}}, "child/hierarchy=2": {" - aaa bb", &want{name: "aaa bb", hierarchy: 2, index: fixedIndex, err: nil}}, "child/hierarchy=2/tab on the way": {" - aaa bb", &want{name: "aaa bb", hierarchy: 2, index: fixedIndex, err: nil}}, - "invalid/hierarchy=0/prefix space": {" - aaa bb", &want{err: &inputFormatError{row: " - aaa bb"}}}, "invalid/hierarchy=0/prefix chars": {"xx- aaa bb", &want{err: &inputFormatError{row: "xx- aaa bb"}}}, "invalid/hierarchy=0/no hyphen": {"xx aaa bb", &want{err: &inputFormatError{row: "xx aaa bb"}}}, "invalid/hierarchy=0/tab only": {" ", nil}, } - nodeGenerator := newNodeGenerator(spacesTab) + nodeGenerator := newNodeGenerator() + _, _ = nodeGenerator.generate(" - xxx", fixedIndex) // Parserのインデントスペース数を決めるために必要 + for name, tt := range tests { tt := tt t.Run(name, func(t *testing.T) { @@ -72,7 +73,9 @@ func TestGenerateTwoSpaces(t *testing.T) { "invalid/hierarchy=0/space only": {" ", nil}, } - nodeGenerator := newNodeGenerator(spacesTwo) + nodeGenerator := newNodeGenerator() + _, _ = nodeGenerator.generate(" - xxx", fixedIndex) // Parserのインデントスペース数を決めるために必要 + for name, tt := range tests { tt := tt t.Run(name, func(t *testing.T) { @@ -116,7 +119,9 @@ func TestGenerateFourSpaces(t *testing.T) { "invalid/hierarchy=0/space only": {" ", nil}, } - nodeGenerator := newNodeGenerator(spacesFour) + nodeGenerator := newNodeGenerator() + _, _ = nodeGenerator.generate(" - xxx", fixedIndex) // Parserのインデントスペース数を決めるために必要 + for name, tt := range tests { tt := tt t.Run(name, func(t *testing.T) { diff --git a/pipeline_tree.go b/pipeline_tree.go index bcd33952..b43ee631 100644 --- a/pipeline_tree.go +++ b/pipeline_tree.go @@ -69,7 +69,7 @@ func (t *treePipeline) output(w io.Writer, r io.Reader, cfg *config) error { defer cancel() splitStream, errcsl := split(ctx, r) - rootStream, errcr := newRootGeneratorPipeline(cfg.space).generate(ctx, splitStream) + rootStream, errcr := newRootGeneratorPipeline().generate(ctx, splitStream) growStream, errcg := t.grower.grow(ctx, rootStream) errcs := t.spreader.spread(ctx, w, growStream) return t.handlePipelineErr(ctx, errcsl, errcr, errcg, errcs) @@ -94,7 +94,7 @@ func (t *treePipeline) mkdir(r io.Reader, cfg *config) error { defer cancel() splitStream, errcsl := split(ctx, r) - rootStream, errcr := newRootGeneratorPipeline(cfg.space).generate(ctx, splitStream) + rootStream, errcr := newRootGeneratorPipeline().generate(ctx, splitStream) growStream, errcg := t.grower.grow(ctx, rootStream) errcm := t.mkdirer.mkdir(ctx, growStream) return t.handlePipelineErr(ctx, errcsl, errcr, errcg, errcm) @@ -128,7 +128,7 @@ func (t *treePipeline) verify(r io.Reader, cfg *config) error { t.grower.enableValidation() splitStream, errcsl := split(ctx, r) - rootStream, errcr := newRootGeneratorPipeline(cfg.space).generate(ctx, splitStream) + rootStream, errcr := newRootGeneratorPipeline().generate(ctx, splitStream) growStream, errcg := t.grower.grow(ctx, rootStream) errcv := t.verifier.verify(ctx, growStream) return t.handlePipelineErr(ctx, errcsl, errcr, errcg, errcv) diff --git a/pipeline_tree_verifier.go b/pipeline_tree_verifier.go index 7845c987..39bd9639 100644 --- a/pipeline_tree_verifier.go +++ b/pipeline_tree_verifier.go @@ -1,3 +1,5 @@ +//go:build !wasm + package gtree import ( diff --git a/root_generator.go b/root_generator.go index e7ebfa50..aa0862dd 100644 --- a/root_generator.go +++ b/root_generator.go @@ -16,11 +16,11 @@ type rootGeneratorSimple struct { nodeGenerator *nodeGenerator } -func newRootGeneratorSimple(r io.Reader, st spaceType) *rootGeneratorSimple { +func newRootGeneratorSimple(r io.Reader) *rootGeneratorSimple { return &rootGeneratorSimple{ counter: newCounter(), scanner: bufio.NewScanner(r), - nodeGenerator: newNodeGenerator(st), + nodeGenerator: newNodeGenerator(), } } @@ -61,9 +61,9 @@ type rootGeneratorPipeline struct { nodeGenerator *nodeGenerator } -func newRootGeneratorPipeline(st spaceType) *rootGeneratorPipeline { +func newRootGeneratorPipeline() *rootGeneratorPipeline { return &rootGeneratorPipeline{ - nodeGenerator: newNodeGenerator(st), + nodeGenerator: newNodeGenerator(), } } diff --git a/simple_tree.go b/simple_tree.go index e9757741..78720d82 100644 --- a/simple_tree.go +++ b/simple_tree.go @@ -63,7 +63,7 @@ func newTreeSimple(cfg *config) tree { } func (t *treeSimple) output(w io.Writer, r io.Reader, cfg *config) error { - roots, err := newRootGeneratorSimple(r, cfg.space).generate() + roots, err := newRootGeneratorSimple(r).generate() if err != nil { return err } @@ -82,7 +82,7 @@ func (t *treeSimple) outputProgrammably(w io.Writer, root *Node, cfg *config) er } func (t *treeSimple) mkdir(r io.Reader, cfg *config) error { - roots, err := newRootGeneratorSimple(r, cfg.space).generate() + roots, err := newRootGeneratorSimple(r).generate() if err != nil { return err } @@ -108,7 +108,7 @@ func (t *treeSimple) mkdirProgrammably(root *Node, cfg *config) error { } func (t *treeSimple) verify(r io.Reader, cfg *config) error { - roots, err := newRootGeneratorSimple(r, cfg.space).generate() + roots, err := newRootGeneratorSimple(r).generate() if err != nil { return err } diff --git a/simple_tree_verifier.go b/simple_tree_verifier.go index 4ace8472..ecccc24a 100644 --- a/simple_tree_verifier.go +++ b/simple_tree_verifier.go @@ -1,3 +1,5 @@ +//go:build !wasm + package gtree import ( diff --git a/stack.go b/stack.go index ab915330..d4f3819a 100644 --- a/stack.go +++ b/stack.go @@ -38,21 +38,19 @@ func (s *stack) dfs(current *Node) { size := s.size() for i := 0; i < size; i++ { parent := s.pop() + if !current.isDirectlyUnder(parent) { + continue + } // for same name on the same hierarchy if child := parent.findChildByText(current.name); child != nil { - if !child.isDirectlyUnder(parent) { - continue - } s.push(parent).push(child) - } else { - if !current.isDirectlyUnder(parent) { - continue - } - parent.addChild(current) - current.setParent(parent) - s.push(parent).push(current) + return } + + parent.addChild(current) + current.setParent(parent) + s.push(parent).push(current) return } } diff --git a/testdata/sample2.md b/testdata/sample2.md index a6e21372..44e17e00 100644 --- a/testdata/sample2.md +++ b/testdata/sample2.md @@ -1,21 +1,21 @@ - k8s_resources - - (Tier3) - - (Tier2) - - (Tier1) - - (Tier0) - - Deployment - - ReplicaSet - - Pod - - container(s) - - CronJob - - Job - - Pod - - container(s) - - (empty) - - DaemonSet - - Pod - - container(s) - - (empty) - - StatefulSet - - Pod - - container(s) + - (Tier3) + - (Tier2) + - (Tier1) + - (Tier0) + - Deployment + - ReplicaSet + - Pod + - container(s) + - CronJob + - Job + - Pod + - container(s) + - (empty) + - DaemonSet + - Pod + - container(s) + - (empty) + - StatefulSet + - Pod + - container(s) diff --git a/tree_handler_mkdir_test.go b/tree_handler_mkdir_test.go index 86a45b88..7320c84d 100644 --- a/tree_handler_mkdir_test.go +++ b/tree_handler_mkdir_test.go @@ -23,7 +23,7 @@ func TestMkdir(t *testing.T) { - b - bb - lll - -ff`)), + - ff`)), }, wantErr: nil, }, @@ -35,7 +35,7 @@ func TestMkdir(t *testing.T) { - b - bb - lll - -ff`)), + - ff`)), options: []gtree.Option{gtree.WithDryRun()}, }, wantErr: gtree.ErrExistPath, @@ -48,7 +48,7 @@ func TestMkdir(t *testing.T) { - b - bb - lll - -ff`)), + - ff`)), options: []gtree.Option{gtree.WithMassive(context.Background())}, }, wantErr: gtree.ErrExistPath, @@ -61,7 +61,7 @@ func TestMkdir(t *testing.T) { - b - b/b - lll - -ff`)), + - ff`)), options: []gtree.Option{gtree.WithDryRun()}, }, wantErr: errors.New("invalid node name: b/b"), @@ -105,7 +105,7 @@ func TestMkdir(t *testing.T) { - b.go - bb - lll - -Makefile`)), + - Makefile`)), options: []gtree.Option{gtree.WithFileExtensions([]string{".go", "Makefile"})}, }, wantErr: nil, @@ -146,6 +146,7 @@ func TestMkdir(t *testing.T) { gotErr := gtree.Mkdir(tt.in.input, tt.in.options...) if gotErr != nil { + t.Log(gotErr.Error()) if gotErr.Error() != tt.wantErr.Error() { t.Errorf("\ngotErr: \n%v\nwantErr: \n%v", gotErr, tt.wantErr) } diff --git a/tree_handler_output_test.go b/tree_handler_output_test.go index 932413c1..a0431a3c 100644 --- a/tree_handler_output_test.go +++ b/tree_handler_output_test.go @@ -280,7 +280,6 @@ root - e - o - g`)), - options: []gtree.Option{gtree.WithIndentTwoSpaces()}, }, out: out{ output: strings.TrimPrefix(` @@ -310,7 +309,6 @@ a - e - o - g`)), - options: []gtree.Option{gtree.WithIndentFourSpaces()}, }, out: out{ output: strings.TrimPrefix(` @@ -561,7 +559,6 @@ a - o - g`)), options: []gtree.Option{ - gtree.WithIndentTwoSpaces(), gtree.WithBranchFormatIntermedialNode("+->", ": "), gtree.WithBranchFormatLastNode("+->", " "), }, @@ -844,7 +841,7 @@ func TestOutput_encodeJSON(t *testing.T) { - e - o - g`)), - options: []gtree.Option{gtree.WithIndentTwoSpaces(), gtree.WithEncodeJSON()}, + options: []gtree.Option{gtree.WithEncodeJSON()}, }, out: out{ output: strings.TrimPrefix(` @@ -866,7 +863,7 @@ func TestOutput_encodeJSON(t *testing.T) { - e - o - g`)), - options: []gtree.Option{gtree.WithIndentFourSpaces(), gtree.WithEncodeJSON()}, + options: []gtree.Option{gtree.WithEncodeJSON()}, }, out: out{ output: strings.TrimPrefix(` @@ -1005,7 +1002,7 @@ children = [] - e - o - g`)), - options: []gtree.Option{gtree.WithIndentTwoSpaces(), gtree.WithEncodeTOML()}, + options: []gtree.Option{gtree.WithEncodeTOML()}, }, out: out{ output: strings.TrimPrefix(` @@ -1056,7 +1053,7 @@ children = [] - e - o - g`)), - options: []gtree.Option{gtree.WithIndentFourSpaces(), gtree.WithEncodeTOML()}, + options: []gtree.Option{gtree.WithEncodeTOML()}, }, out: out{ output: strings.TrimPrefix(` @@ -1201,7 +1198,7 @@ children: - e - o - g`)), - options: []gtree.Option{gtree.WithIndentTwoSpaces(), gtree.WithEncodeYAML()}, + options: []gtree.Option{gtree.WithEncodeYAML()}, }, out: out{ output: strings.TrimPrefix(` @@ -1240,7 +1237,7 @@ children: - e - o - g`)), - options: []gtree.Option{gtree.WithIndentFourSpaces(), gtree.WithEncodeYAML()}, + options: []gtree.Option{gtree.WithEncodeYAML()}, }, out: out{ output: strings.TrimPrefix(` diff --git a/wasm_root_generator.go b/wasm_root_generator.go index bd90516a..5282c126 100644 --- a/wasm_root_generator.go +++ b/wasm_root_generator.go @@ -13,11 +13,11 @@ type rootGenerator struct { nodeGenerator *nodeGenerator } -func newRootGenerator(r io.Reader, st spaceType) *rootGenerator { +func newRootGenerator(r io.Reader) *rootGenerator { return &rootGenerator{ counter: newCounter(), scanner: bufio.NewScanner(r), - nodeGenerator: newNodeGenerator(st), + nodeGenerator: newNodeGenerator(), } } diff --git a/wasm_tree_handler.go b/wasm_tree_handler.go index 627888e0..a186062b 100644 --- a/wasm_tree_handler.go +++ b/wasm_tree_handler.go @@ -10,7 +10,7 @@ import ( func Output(w io.Writer, r io.Reader, options ...Option) error { cfg := newConfig(options) - rg := newRootGenerator(r, cfg.space) + rg := newRootGenerator(r) roots, err := rg.generate() if err != nil { return err