Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ddddddO committed Jun 24, 2023
1 parent 79865ff commit 9f67775
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
6 changes: 6 additions & 0 deletions cmd/gtree/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ func actionOutput(c *cli.Context) error {
return exitErrOpts(err)
}
options := []gtree.Option{oi, oo}
if c.Bool("massive") {
options = append(options, gtree.WithMassive())
}

markdownPath := c.Path("file")
if isInputStdin(markdownPath) {
Expand Down Expand Up @@ -239,6 +242,9 @@ func actionMkdir(c *cli.Context) error {
}
oe := gtree.WithFileExtensions(c.StringSlice("extension"))
options := []gtree.Option{oi, oe}
if c.Bool("massive") {
options = append(options, gtree.WithMassive())
}

if c.Bool("dry-run") {
if err := outputWithValidation(in, options); err != nil {
Expand Down
6 changes: 0 additions & 6 deletions simple_tree_grower.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ func (*defaultGrowerSimple) assembleBranchFinally(current, root *Node) {
if root != nil {
current.setPath(root.path(), current.path())
}

if current.isRoot() {
current.setBranch(current.name, "\n")
} else {
current.setBranch(current.branch(), " ", current.name, "\n")
}
}

func (dg *defaultGrowerSimple) enableValidation() {
Expand Down
21 changes: 15 additions & 6 deletions simple_tree_spreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ func (ds *defaultSpreaderSimple) spread(w io.Writer, roots []*Node) error {
}

func (*defaultSpreaderSimple) spreadBranch(current *Node) string {
ret := current.branch()
ret := current.name + "\n"
if !current.isRoot() {
ret = current.branch() + " " + current.name + "\n"
}

for _, child := range current.children {
ret += (*defaultSpreaderSimple)(nil).spreadBranch(child)
}
Expand Down Expand Up @@ -96,21 +100,26 @@ func (cs *colorizeSpreaderSimple) spread(w io.Writer, roots []*Node) error {
}

func (cs *colorizeSpreaderSimple) spreadBranch(current *Node) string {
cs.colorize(current)
ret := current.branch()
ret := ""
if current.isRoot() {
ret = cs.colorize(current) + "\n"
} else {
ret = current.branch() + " " + cs.colorize(current) + "\n"
}

for _, child := range current.children {
ret += cs.spreadBranch(child)
}
return ret
}

func (cs *colorizeSpreaderSimple) colorize(current *Node) {
func (cs *colorizeSpreaderSimple) colorize(current *Node) string {
if cs.fileConsiderer.isFile(current) {
_ = cs.fileCounter.next()
current.name = cs.fileColor.Sprint(current.name)
return cs.fileColor.Sprint(current.name)
} else {
_ = cs.dirCounter.next()
current.name = cs.dirColor.Sprint(current.name)
return cs.dirColor.Sprint(current.name)
}
}

Expand Down

0 comments on commit 9f67775

Please sign in to comment.