From 6d911213acc0da777ef29dad124a954134016655 Mon Sep 17 00:00:00 2001 From: ia Date: Sun, 17 Jun 2018 00:59:34 +0200 Subject: [PATCH] all: gofmt Run standard gofmt command on project root. - go version go1.10.3 darwin/amd64 Signed-off-by: ia --- joe.go | 234 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 117 insertions(+), 117 deletions(-) diff --git a/joe.go b/joe.go index 340a563..3baa581 100644 --- a/joe.go +++ b/joe.go @@ -1,15 +1,15 @@ package main import ( - "fmt" - "github.com/codegangsta/cli" - "io/ioutil" - "log" - "os" - "path" - "path/filepath" - "sort" - "strings" + "fmt" + "github.com/codegangsta/cli" + "io/ioutil" + "log" + "os" + "path" + "path/filepath" + "sort" + "strings" ) const joe string = ` @@ -32,127 +32,127 @@ const dataDir string = ".joe-data" var dataPath = path.Join(os.Getenv("HOME"), dataDir) func findGitignores() (a map[string]string, err error) { - _, err = ioutil.ReadDir(dataPath) - if err != nil { - return nil, err - } + _, err = ioutil.ReadDir(dataPath) + if err != nil { + return nil, err + } - filelist := make(map[string]string) - filepath.Walk(dataPath, func(filepath string, info os.FileInfo, err error) error { - if strings.HasSuffix(info.Name(), ".gitignore") { - name := strings.ToLower(strings.Replace(info.Name(), ".gitignore", "", 1)) - filelist[name] = filepath - } - return nil - }) - return filelist, nil + filelist := make(map[string]string) + filepath.Walk(dataPath, func(filepath string, info os.FileInfo, err error) error { + if strings.HasSuffix(info.Name(), ".gitignore") { + name := strings.ToLower(strings.Replace(info.Name(), ".gitignore", "", 1)) + filelist[name] = filepath + } + return nil + }) + return filelist, nil } func availableFiles() (a []string, err error) { - gitignores, err := findGitignores() - if err != nil { - return nil, err - } + gitignores, err := findGitignores() + if err != nil { + return nil, err + } - availableGitignores := []string{} - for key, _ := range gitignores { - availableGitignores = append(availableGitignores, key) - } + availableGitignores := []string{} + for key, _ := range gitignores { + availableGitignores = append(availableGitignores, key) + } - return availableGitignores, nil + return availableGitignores, nil } func generate(args string) { - names := strings.Split(args, ",") + names := strings.Split(args, ",") - gitignores, err := findGitignores() - if err != nil { - log.Fatal(err) - } + gitignores, err := findGitignores() + if err != nil { + log.Fatal(err) + } - notFound := []string{} - output := "" - for index, name := range names { - if filepath, ok := gitignores[strings.ToLower(name)]; ok { - bytes, err := ioutil.ReadFile(filepath) - if err == nil { - output += "\n#### " + name + " ####\n" - output += string(bytes) - if index < len(names) - 1 { - output += "\n" - } - continue - } - } else { - notFound = append(notFound, name) - } - } + notFound := []string{} + output := "" + for index, name := range names { + if filepath, ok := gitignores[strings.ToLower(name)]; ok { + bytes, err := ioutil.ReadFile(filepath) + if err == nil { + output += "\n#### " + name + " ####\n" + output += string(bytes) + if index < len(names)-1 { + output += "\n" + } + continue + } + } else { + notFound = append(notFound, name) + } + } - if len(notFound) > 0 { - fmt.Printf("Unsupported files: %s\n", strings.Join(notFound, ", ")) - fmt.Println("Run `joe ls` to see list of available gitignores.") - output = "" - } - if len(output) > 0 { - output = "#### joe made this: http://goel.io/joe\n" + output - } - fmt.Print(output) + if len(notFound) > 0 { + fmt.Printf("Unsupported files: %s\n", strings.Join(notFound, ", ")) + fmt.Println("Run `joe ls` to see list of available gitignores.") + output = "" + } + if len(output) > 0 { + output = "#### joe made this: http://goel.io/joe\n" + output + } + fmt.Print(output) } func main() { - app := cli.NewApp() - app.Name = joe - app.Usage = "generate .gitignore files from the command line" - app.UsageText = "joe command [arguments...]" - app.Version = version - app.Commands = []cli.Command{ - { - Name: "ls", - Aliases: []string{"list"}, - Usage: "list all available files", - Action: func(c *cli.Context) error { - availableGitignores, err := availableFiles() - if err != nil { - log.Fatal(err) - return err - } - fmt.Printf("%d supported .gitignore files:\n", len(availableGitignores)) - sort.Strings(availableGitignores) - fmt.Printf("%s\n", strings.Join(availableGitignores, ", ")) - return nil - }, - }, - { - Name: "u", - Aliases: []string{"update"}, - Usage: "update all available gitignore files", - Action: func(c *cli.Context) error { - fmt.Println("Updating gitignore files..") - err := RemoveContents(dataPath) - if err != nil { - log.Fatal(err) - } - err = DownloadFiles(gitignoreUrl, dataPath) - if err != nil { - log.Fatal(err) - return err - } - return nil - }, - }, - { - Name: "g", - Aliases: []string{"generate"}, - Usage: "generate gitignore files", - Action: func(c *cli.Context) error { - if c.NArg() != 1 { - cli.ShowAppHelp(c) - } else { - generate(c.Args()[0]) - } - return nil - }, - }, - } - app.Run(os.Args) + app := cli.NewApp() + app.Name = joe + app.Usage = "generate .gitignore files from the command line" + app.UsageText = "joe command [arguments...]" + app.Version = version + app.Commands = []cli.Command{ + { + Name: "ls", + Aliases: []string{"list"}, + Usage: "list all available files", + Action: func(c *cli.Context) error { + availableGitignores, err := availableFiles() + if err != nil { + log.Fatal(err) + return err + } + fmt.Printf("%d supported .gitignore files:\n", len(availableGitignores)) + sort.Strings(availableGitignores) + fmt.Printf("%s\n", strings.Join(availableGitignores, ", ")) + return nil + }, + }, + { + Name: "u", + Aliases: []string{"update"}, + Usage: "update all available gitignore files", + Action: func(c *cli.Context) error { + fmt.Println("Updating gitignore files..") + err := RemoveContents(dataPath) + if err != nil { + log.Fatal(err) + } + err = DownloadFiles(gitignoreUrl, dataPath) + if err != nil { + log.Fatal(err) + return err + } + return nil + }, + }, + { + Name: "g", + Aliases: []string{"generate"}, + Usage: "generate gitignore files", + Action: func(c *cli.Context) error { + if c.NArg() != 1 { + cli.ShowAppHelp(c) + } else { + generate(c.Args()[0]) + } + return nil + }, + }, + } + app.Run(os.Args) }