Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be7bd69

Browse files
committed
converted tabs to spaces, updated blog post
1 parent d4e1f07 commit be7bd69

File tree

4 files changed

+245
-256
lines changed

4 files changed

+245
-256
lines changed

golang/gomr.go

+52-52
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
package main
22

33
import (
4-
"github.com/codegangsta/cli"
5-
"os"
4+
"github.com/codegangsta/cli"
5+
"os"
66
)
77

88
func main() {
9-
app := cli.NewApp()
10-
app.Name = "gomr"
11-
app.Author = "Kyle W. Purdon"
12-
app.Version = "0.0.1"
13-
app.Usage = "multi-repository manager in go"
14-
app.Commands = []cli.Command{
15-
{
16-
Name: "register",
17-
Usage: "register a directory",
18-
Action: register,
19-
Flags: []cli.Flag{
20-
cli.StringFlag{
21-
Name: "directory, d",
22-
Value: "./",
23-
Usage: "directory to tag",
24-
},
25-
cli.StringFlag{
26-
Name: "tag, t",
27-
Value: "default",
28-
Usage: "tag to add for directory",
29-
},
30-
cli.BoolFlag{
31-
Name: "append",
32-
Usage: "append the tag to an existing registered directory",
33-
},
34-
},
35-
},
36-
{
37-
Name: "run",
38-
Usage: "run a command",
39-
Action: run,
40-
Flags: []cli.Flag{
41-
cli.StringFlag{
42-
Name: "basepath, b",
43-
Value: "./",
44-
Usage: "path to begin the recursive search",
45-
},
46-
cli.StringFlag{
47-
Name: "tag, t",
48-
Value: "default",
49-
Usage: "tag to add for directory",
50-
},
51-
cli.BoolFlag{
52-
Name: "dryrun, d",
53-
Usage: "print (dont execute) the commands that will be run",
54-
},
55-
},
56-
},
57-
}
9+
app := cli.NewApp()
10+
app.Name = "gomr"
11+
app.Author = "Kyle W. Purdon"
12+
app.Version = "0.0.1"
13+
app.Usage = "multi-repository manager in go"
14+
app.Commands = []cli.Command{
15+
{
16+
Name: "register",
17+
Usage: "register a directory",
18+
Action: register,
19+
Flags: []cli.Flag{
20+
cli.StringFlag{
21+
Name: "directory, d",
22+
Value: "./",
23+
Usage: "directory to tag",
24+
},
25+
cli.StringFlag{
26+
Name: "tag, t",
27+
Value: "default",
28+
Usage: "tag to add for directory",
29+
},
30+
cli.BoolFlag{
31+
Name: "append",
32+
Usage: "append the tag to an existing registered directory",
33+
},
34+
},
35+
},
36+
{
37+
Name: "run",
38+
Usage: "run a command",
39+
Action: run,
40+
Flags: []cli.Flag{
41+
cli.StringFlag{
42+
Name: "basepath, b",
43+
Value: "./",
44+
Usage: "path to begin the recursive search",
45+
},
46+
cli.StringFlag{
47+
Name: "tag, t",
48+
Value: "default",
49+
Usage: "tag to add for directory",
50+
},
51+
cli.BoolFlag{
52+
Name: "dryrun, d",
53+
Usage: "print (dont execute) the commands that will be run",
54+
},
55+
},
56+
},
57+
}
5858

59-
app.Run(os.Args)
59+
app.Run(os.Args)
6060
}

golang/register.go

+33-33
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
package main
22

33
import (
4-
"fmt"
5-
"github.com/codegangsta/cli"
6-
"github.com/robfig/config"
7-
"os"
8-
"path"
9-
"strings"
4+
"fmt"
5+
"github.com/codegangsta/cli"
6+
"github.com/robfig/config"
7+
"os"
8+
"path"
9+
"strings"
1010
)
1111

1212
func AppendIfMissing(slice []string, i string) []string {
13-
for _, ele := range slice {
14-
if ele == i {
15-
return slice
16-
}
17-
}
18-
return append(slice, i)
13+
for _, ele := range slice {
14+
if ele == i {
15+
return slice
16+
}
17+
}
18+
return append(slice, i)
1919
}
2020

2121
func register(ctx *cli.Context) {
2222

23-
fn := path.Join(ctx.String("directory"), ".gomr")
23+
fn := path.Join(ctx.String("directory"), ".gomr")
2424

25-
newTags := strings.Split(ctx.String("tag"), ",")
25+
newTags := strings.Split(ctx.String("tag"), ",")
2626

27-
if ctx.Bool("append") {
28-
if _, err := os.Stat(fn); err == nil {
29-
cfg, _ := config.ReadDefault(".gomr")
30-
curTags, _ := cfg.String("gomr", "tags")
27+
if ctx.Bool("append") {
28+
if _, err := os.Stat(fn); err == nil {
29+
cfg, _ := config.ReadDefault(".gomr")
30+
curTags, _ := cfg.String("gomr", "tags")
3131

32-
for _, tag := range strings.Split(curTags, ",") {
33-
newTags = AppendIfMissing(newTags, tag)
34-
}
35-
} else {
36-
err := "append used, existing file not found."
37-
fmt.Fprintf(os.Stderr, "error: %v\n", err)
38-
os.Exit(1)
39-
}
40-
}
32+
for _, tag := range strings.Split(curTags, ",") {
33+
newTags = AppendIfMissing(newTags, tag)
34+
}
35+
} else {
36+
err := "append used, existing file not found."
37+
fmt.Fprintf(os.Stderr, "error: %v\n", err)
38+
os.Exit(1)
39+
}
40+
}
4141

42-
outTags := strings.Join(newTags, ",")
42+
outTags := strings.Join(newTags, ",")
4343

44-
outCfg := config.NewDefault()
45-
outCfg.AddSection("gomr")
46-
outCfg.AddOption("gomr", "tags", outTags)
47-
outCfg.WriteFile(fn, 0644, "gomr configuration file")
44+
outCfg := config.NewDefault()
45+
outCfg.AddSection("gomr")
46+
outCfg.AddOption("gomr", "tags", outTags)
47+
outCfg.WriteFile(fn, 0644, "gomr configuration file")
4848

49-
return
49+
return
5050
}

golang/run.go

+36-36
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
11
package main
22

33
import (
4-
"fmt"
5-
"github.com/codegangsta/cli"
6-
"github.com/robfig/config"
7-
"os"
8-
"os/exec"
9-
"path/filepath"
10-
"strings"
4+
"fmt"
5+
"github.com/codegangsta/cli"
6+
"github.com/robfig/config"
7+
"os"
8+
"os/exec"
9+
"path/filepath"
10+
"strings"
1111
)
1212

1313
func RunGomr(ctx *cli.Context) filepath.WalkFunc {
14-
return func(path string, f os.FileInfo, err error) error {
14+
return func(path string, f os.FileInfo, err error) error {
1515

16-
tag := ctx.String("tag")
17-
dryrun := ctx.Bool("dryrun")
16+
tag := ctx.String("tag")
17+
dryrun := ctx.Bool("dryrun")
1818

19-
if len(ctx.Args()) == 0 {
20-
panic("no command given")
21-
}
19+
if len(ctx.Args()) == 0 {
20+
panic("no command given")
21+
}
2222

23-
command := ctx.Args()[0]
23+
command := ctx.Args()[0]
2424

25-
if strings.Contains(path, ".gomr") {
25+
if strings.Contains(path, ".gomr") {
2626

27-
cfg, _ := config.ReadDefault(path)
28-
gomrTags, _ := cfg.String("gomr", "tags")
27+
cfg, _ := config.ReadDefault(path)
28+
gomrTags, _ := cfg.String("gomr", "tags")
2929

30-
if strings.Contains(gomrTags, tag) {
31-
if dryrun {
32-
fmt.Printf("Would run %s in %s\n", command, filepath.Dir(path))
33-
} else {
34-
os.Chdir(filepath.Dir(path))
35-
cmd := exec.Command("sh", "-c", command)
36-
stdout, err := cmd.Output()
30+
if strings.Contains(gomrTags, tag) {
31+
if dryrun {
32+
fmt.Printf("Would run %s in %s\n", command, filepath.Dir(path))
33+
} else {
34+
os.Chdir(filepath.Dir(path))
35+
cmd := exec.Command("sh", "-c", command)
36+
stdout, err := cmd.Output()
3737

38-
if err != nil {
39-
panic(err.Error())
40-
}
38+
if err != nil {
39+
panic(err.Error())
40+
}
4141

42-
println(string(stdout))
43-
}
44-
}
42+
println(string(stdout))
43+
}
44+
}
4545

46-
}
47-
return nil
48-
}
46+
}
47+
return nil
48+
}
4949
}
5050

5151
func run(ctx *cli.Context) {
5252

53-
root := ctx.String("basepath")
54-
filepath.Walk(root, RunGomr(ctx))
53+
root := ctx.String("basepath")
54+
filepath.Walk(root, RunGomr(ctx))
5555

56-
return
56+
return
5757
}

0 commit comments

Comments
 (0)