Skip to content

Commit c5dac53

Browse files
committed
refactor(examples): allow recursive go build and go test
The examples/ code was poorly organized, with `main()` being redeclared several times. This could prevent other projects from using the standard `go build ./...` syntax.
1 parent 7fb3e64 commit c5dac53

File tree

18 files changed

+35
-39
lines changed

18 files changed

+35
-39
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ language: go
66

77
go:
88
- 1.2.2
9+
- 1.3
910
- tip
1011

1112
matrix:
@@ -18,12 +19,13 @@ before_install:
1819
- go get -v github.com/mattn/goveralls
1920

2021
install:
21-
- go get -d -v ./... && go build -v .
22+
- go get -d -v ./... && go build -v ./...
2223

2324
script:
2425
- go vet -x ./...
2526
- $HOME/gopath/bin/golint .
26-
- go test -covermode=count -coverprofile=profile.cov -v .
27+
- go test -v ./...
28+
- go test -covermode=count -coverprofile=profile.cov .
2729

2830
after_script:
2931
- $HOME/gopath/bin/goveralls -coverprofile=profile.cov -service=travis-ci
File renamed without changes.

examples/git/git_branch.go renamed to examples/git/branch/git_branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package git
22

33
import (
44
"fmt"

examples/git/git_checkout.go renamed to examples/git/checkout/git_checkout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package git
22

33
import (
44
"fmt"

examples/git/git_clone.go renamed to examples/git/clone/git_clone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package git
22

33
import (
44
"fmt"

examples/git/git.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,38 @@ func runCommand(cmd string, args []string) (err error) {
7171
return cmdAdd(argv)
7272
case "branch":
7373
// subcommand is a script
74-
return goRun("git_branch.go", argv)
74+
return goRun("branch/git_branch.go", argv)
7575
case "checkout", "clone", "commit", "push", "remote":
7676
// subcommand is a script
77-
scriptName := fmt.Sprintf("git_%s.go", cmd)
77+
scriptName := fmt.Sprintf("%s/git_%s.go", cmd, cmd)
7878
return goRun(scriptName, argv)
7979
case "help", "":
8080
return goRun("git.go", []string{"git_add.go", "--help"})
8181
}
8282

8383
return fmt.Errorf("%s is not a git command. See 'git help'", cmd)
8484
}
85+
86+
func cmdAdd(argv []string) (err error) {
87+
usage := `usage: git add [options] [--] [<filepattern>...]
88+
89+
options:
90+
-h, --help
91+
-n, --dry-run dry run
92+
-v, --verbose be verbose
93+
-i, --interactive interactive picking
94+
-p, --patch select hunks interactively
95+
-e, --edit edit current diff and apply
96+
-f, --force allow adding otherwise ignored files
97+
-u, --update update tracked files
98+
-N, --intent-to-add record only the fact that the path will be added later
99+
-A, --all add all, noticing removal of tracked files
100+
--refresh don't add, only refresh the index
101+
--ignore-errors just skip files which cannot be added because of errors
102+
--ignore-missing check if - even missing - files are ignored in dry run
103+
`
104+
105+
args, _ := docopt.Parse(usage, nil, true, "", false)
106+
fmt.Println(args)
107+
return
108+
}

examples/git/git_add.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)