Skip to content

Commit 95634a2

Browse files
author
Karan Goel
committed
Fix formatting for sections karan#82
1 parent da86eb8 commit 95634a2

File tree

1 file changed

+112
-109
lines changed

1 file changed

+112
-109
lines changed

joe.go

Lines changed: 112 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package main
22

33
import (
4-
"fmt"
5-
"github.com/codegangsta/cli"
6-
"io/ioutil"
7-
"log"
8-
"os"
9-
"path"
10-
"path/filepath"
11-
"sort"
12-
"strings"
4+
"fmt"
5+
"github.com/codegangsta/cli"
6+
"io/ioutil"
7+
"log"
8+
"os"
9+
"path"
10+
"path/filepath"
11+
"sort"
12+
"strings"
1313
)
1414

1515
const joe string = `
@@ -32,119 +32,122 @@ const dataDir string = ".joe-data"
3232
var dataPath = path.Join(os.Getenv("HOME"), dataDir)
3333

3434
func findGitignores() (a map[string]string, err error) {
35-
_, err = ioutil.ReadDir(dataPath)
36-
if err != nil {
37-
return nil, err
38-
}
35+
_, err = ioutil.ReadDir(dataPath)
36+
if err != nil {
37+
return nil, err
38+
}
3939

40-
filelist := make(map[string]string)
41-
filepath.Walk(dataPath, func(filepath string, info os.FileInfo, err error) error {
42-
if strings.HasSuffix(info.Name(), ".gitignore") {
43-
name := strings.ToLower(strings.Replace(info.Name(), ".gitignore", "", 1))
44-
filelist[name] = filepath
45-
}
46-
return nil
47-
})
48-
return filelist, nil
40+
filelist := make(map[string]string)
41+
filepath.Walk(dataPath, func(filepath string, info os.FileInfo, err error) error {
42+
if strings.HasSuffix(info.Name(), ".gitignore") {
43+
name := strings.ToLower(strings.Replace(info.Name(), ".gitignore", "", 1))
44+
filelist[name] = filepath
45+
}
46+
return nil
47+
})
48+
return filelist, nil
4949
}
5050

5151
func availableFiles() (a []string, err error) {
52-
gitignores, err := findGitignores()
53-
if err != nil {
54-
return nil, err
55-
}
52+
gitignores, err := findGitignores()
53+
if err != nil {
54+
return nil, err
55+
}
5656

57-
availableGitignores := []string{}
58-
for key, _ := range gitignores {
59-
availableGitignores = append(availableGitignores, key)
60-
}
57+
availableGitignores := []string{}
58+
for key, _ := range gitignores {
59+
availableGitignores = append(availableGitignores, key)
60+
}
6161

62-
return availableGitignores, nil
62+
return availableGitignores, nil
6363
}
6464

6565
func generate(args string) {
66-
names := strings.Split(args, ",")
66+
names := strings.Split(args, ",")
6767

68-
gitignores, err := findGitignores()
69-
if err != nil {
70-
log.Fatal(err)
71-
}
68+
gitignores, err := findGitignores()
69+
if err != nil {
70+
log.Fatal(err)
71+
}
7272

73-
notFound := []string{}
74-
output := ""
75-
for _, name := range names {
76-
if filepath, ok := gitignores[strings.ToLower(name)]; ok {
77-
bytes, err := ioutil.ReadFile(filepath)
78-
if err == nil {
79-
output += "#### " + name + " ####\n"
80-
output += string(bytes)
81-
continue
82-
}
83-
} else {
84-
notFound = append(notFound, name)
85-
}
86-
}
73+
notFound := []string{}
74+
output := ""
75+
for index, name := range names {
76+
if filepath, ok := gitignores[strings.ToLower(name)]; ok {
77+
bytes, err := ioutil.ReadFile(filepath)
78+
if err == nil {
79+
output += "\n#### " + name + " ####\n"
80+
output += string(bytes)
81+
if index < len(names) - 1 {
82+
output += "\n"
83+
}
84+
continue
85+
}
86+
} else {
87+
notFound = append(notFound, name)
88+
}
89+
}
8790

88-
if len(notFound) > 0 {
89-
fmt.Printf("Unsupported files: %s\n", strings.Join(notFound, ", "))
90-
fmt.Println("Run `joe ls` to see list of available gitignores.")
91-
output = ""
92-
}
93-
if len(output) > 0 {
94-
output = "#### joe made this: http://goel.io/joe\n" + output
95-
}
96-
fmt.Println(output)
91+
if len(notFound) > 0 {
92+
fmt.Printf("Unsupported files: %s\n", strings.Join(notFound, ", "))
93+
fmt.Println("Run `joe ls` to see list of available gitignores.")
94+
output = ""
95+
}
96+
if len(output) > 0 {
97+
output = "#### joe made this: http://goel.io/joe\n" + output
98+
}
99+
fmt.Print(output)
97100
}
98101

99102
func main() {
100-
app := cli.NewApp()
101-
app.Name = joe
102-
app.Usage = "generate .gitignore files from the command line"
103-
app.UsageText = "joe command [arguments...]"
104-
app.Version = version
105-
app.Commands = []cli.Command{
106-
{
107-
Name: "ls",
108-
Aliases: []string{"list"},
109-
Usage: "list all available files",
110-
Action: func(c *cli.Context) {
111-
availableGitignores, err := availableFiles()
112-
if err != nil {
113-
log.Fatal(err)
114-
}
115-
fmt.Printf("%d supported .gitignore files:\n", len(availableGitignores))
116-
sort.Strings(availableGitignores)
117-
fmt.Printf("%s\n", strings.Join(availableGitignores, ", "))
118-
},
119-
},
120-
{
121-
Name: "u",
122-
Aliases: []string{"update"},
123-
Usage: "update all available gitignore files",
124-
Action: func(c *cli.Context) {
125-
fmt.Println("Updating gitignore files..")
126-
err := RemoveContents(dataPath)
127-
if err != nil {
128-
log.Fatal(err)
129-
}
130-
err = DownloadFiles(gitignoreUrl, dataPath)
131-
if err != nil {
132-
log.Fatal(err)
133-
}
134-
},
135-
},
136-
{
137-
Name: "g",
138-
Aliases: []string{"generate"},
139-
Usage: "generate gitignore files",
140-
Action: func(c *cli.Context) {
141-
if c.NArg() != 1 {
142-
cli.ShowAppHelp(c)
143-
} else {
144-
generate(c.Args()[0])
145-
}
146-
},
147-
},
148-
}
149-
app.Run(os.Args)
103+
app := cli.NewApp()
104+
app.Name = joe
105+
app.Usage = "generate .gitignore files from the command line"
106+
app.UsageText = "joe command [arguments...]"
107+
app.Version = version
108+
app.Commands = []cli.Command{
109+
{
110+
Name: "ls",
111+
Aliases: []string{"list"},
112+
Usage: "list all available files",
113+
Action: func(c *cli.Context) {
114+
availableGitignores, err := availableFiles()
115+
if err != nil {
116+
log.Fatal(err)
117+
}
118+
fmt.Printf("%d supported .gitignore files:\n", len(availableGitignores))
119+
sort.Strings(availableGitignores)
120+
fmt.Printf("%s\n", strings.Join(availableGitignores, ", "))
121+
},
122+
},
123+
{
124+
Name: "u",
125+
Aliases: []string{"update"},
126+
Usage: "update all available gitignore files",
127+
Action: func(c *cli.Context) {
128+
fmt.Println("Updating gitignore files..")
129+
err := RemoveContents(dataPath)
130+
if err != nil {
131+
log.Fatal(err)
132+
}
133+
err = DownloadFiles(gitignoreUrl, dataPath)
134+
if err != nil {
135+
log.Fatal(err)
136+
}
137+
},
138+
},
139+
{
140+
Name: "g",
141+
Aliases: []string{"generate"},
142+
Usage: "generate gitignore files",
143+
Action: func(c *cli.Context) {
144+
if c.NArg() != 1 {
145+
cli.ShowAppHelp(c)
146+
} else {
147+
generate(c.Args()[0])
148+
}
149+
},
150+
},
151+
}
152+
app.Run(os.Args)
150153
}

0 commit comments

Comments
 (0)