Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ddddddO committed Jan 31, 2022
1 parent 5b2ca8a commit aa56619
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions programmable.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func OutputProgrammably(w io.Writer, root *Node, optFns ...OptFn) error {
if err := tree.grow(); err != nil {
return err
}
return tree.expand(w)
return tree.spread(w)
}

// MkdirProgrammably makes directories.
Expand Down Expand Up @@ -70,7 +70,7 @@ func MkdirProgrammably(root *Node, optFns ...OptFn) error {
if err := tree.grow(); err != nil {
return err
}
return tree.expand(os.Stdout)
return tree.spread(os.Stdout)
}

// 微妙?
Expand Down
12 changes: 6 additions & 6 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Output(w io.Writer, r io.Reader, optFns ...OptFn) error {
if err := tree.grow(); err != nil {
return err
}
return tree.expand(w)
return tree.spread(w)
}

// Mkdir makes directories.
Expand Down Expand Up @@ -96,7 +96,7 @@ type treeer interface {
addRoot(root *Node)
setDryRun(bool) // tree初期化のタイミングではなく、tree生成後に差し込む為に追加
grow() error
expand(w io.Writer) error
spread(w io.Writer) error
mkdir() error
}

Expand Down Expand Up @@ -214,18 +214,18 @@ func (*tree) assembleBranchFinally(current, root *Node) {
current.branch.path = filepath.Join(root.Name, current.branch.path)
}

func (t *tree) expand(w io.Writer) error {
func (t *tree) spread(w io.Writer) error {
branches := ""
for _, root := range t.roots {
branches += t.expandBranch(root, "")
branches += t.spreadBranch(root, "")
}
return t.write(w, branches)
}

func (*tree) expandBranch(current *Node, out string) string {
func (*tree) spreadBranch(current *Node, out string) string {
out += current.getBranch()
for _, child := range current.Children {
out = (*tree)(nil).expandBranch(child, out)
out = (*tree)(nil).spreadBranch(child, out)
}
return out
}
Expand Down
2 changes: 1 addition & 1 deletion tree_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type jsonTree struct {
*tree
}

func (jt *jsonTree) expand(w io.Writer) error {
func (jt *jsonTree) spread(w io.Writer) error {
enc := json.NewEncoder(w)

for _, root := range jt.roots {
Expand Down
2 changes: 1 addition & 1 deletion tree_toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type tomlTree struct {
*tree
}

func (tt *tomlTree) expand(w io.Writer) error {
func (tt *tomlTree) spread(w io.Writer) error {
enc := toml.NewEncoder(w)

for _, root := range tt.roots {
Expand Down
2 changes: 1 addition & 1 deletion tree_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type yamlTree struct {
*tree
}

func (yt *yamlTree) expand(w io.Writer) error {
func (yt *yamlTree) spread(w io.Writer) error {
enc := yaml.NewEncoder(w)

for _, root := range yt.roots {
Expand Down

0 comments on commit aa56619

Please sign in to comment.