Skip to content

Commit

Permalink
Merge pull request #29 from DiSiqueira/gotree-hotfix
Browse files Browse the repository at this point in the history
Update to use the new version of gotree
  • Loading branch information
disiqueira authored Apr 9, 2018
2 parents 42633d9 + 53cebaa commit 6896f20
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 43 deletions.
25 changes: 9 additions & 16 deletions gorganizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,17 @@ var cfg *ini.File
var cfgFile string
var language string

func addToTree(folder, file string, tree *gotree.GTStructure) {

newFile := gotree.GTStructure{Name: file}

func addToTree(folder, file string, tree gotree.Tree) {
// append to parent, if exists
for i, item := range tree.Items {
if item.Name == folder {
item.Items = append(item.Items, &newFile)
tree.Items[i] = item
for _, item := range tree.Items() {
if item.Text() == folder {
item.Add(file)
return
}
}

// create parent if missing
newFolder := gotree.GTStructure{Name: folder}
newFolder.Items = append(newFolder.Items, &newFile)
tree.Items = append(tree.Items, &newFolder)
tree.Add(folder).Add(file)
}

type excludeListType []string
Expand Down Expand Up @@ -106,17 +100,16 @@ func main() {

fmt.Println("GOrganizing your Files")

var tree gotree.GTStructure
tree.Name = "Files"
tree := gotree.New("Files")

scanDirectory(*inputFolder, *outputFolder, &tree, *preview, *recursive, *ignoreHiddenFiles)
scanDirectory(*inputFolder, *outputFolder, tree, *preview, *recursive, *ignoreHiddenFiles)

gotree.PrintTree(&tree)
fmt.Println(tree.Print())

fmt.Println("All files have been GOrganized!")
}

func scanDirectory(inputFolder, outputFolder string, tree *gotree.GTStructure, preview, recursive, ignoreHiddenFiles bool) {
func scanDirectory(inputFolder, outputFolder string, tree gotree.Tree, preview, recursive, ignoreHiddenFiles bool) {
files, _ := ioutil.ReadDir(inputFolder)
for _, f := range files {
if strings.Index(f.Name(), ".") == 0 && !ignoreHiddenFiles {
Expand Down
32 changes: 5 additions & 27 deletions ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ import (
"strings"

"github.com/disiqueira/gotree"
"fmt"
)

func iniGet(key string) string {

key = strings.ToLower(key)

names := cfg.SectionStrings()

for _, section := range names[1:] {

if cfg.Section(section).HasKey(key) {
return section
}
Expand All @@ -23,7 +21,6 @@ func iniGet(key string) string {
}

func iniSet(key, value string) error {

title := strings.Title(value)
key = strings.ToLower(key)

Expand All @@ -33,11 +30,9 @@ func iniSet(key, value string) error {
}

func iniDelete(key string) bool {

names := cfg.SectionStrings()

for _, section := range names {

if cfg.Section(section).HasKey(key) {
cfg.Section(section).DeleteKey(key)
return true
Expand All @@ -48,33 +43,16 @@ func iniDelete(key string) bool {
}

func iniScanExt() {

names := cfg.SectionStrings()

var tree gotree.GTStructure

tree.Name = "Rules"
tree := gotree.New("Rules")

for _, section := range names[1:] {

var treeFolder gotree.GTStructure

treeFolder.Name = section

folder := tree.Add(section)
keys := cfg.Section(section).KeyStrings()

for _, key := range keys {

var treeItem gotree.GTStructure
treeItem.Name = key

treeFolder.Items = append(treeFolder.Items, &treeItem)
folder.Add(key)
}

tree.Items = append(tree.Items, &treeFolder)

}

gotree.PrintTree(&tree)

fmt.Println(tree.Print())
}

0 comments on commit 6896f20

Please sign in to comment.