Skip to content

Commit aea90c3

Browse files
authored
Merge pull request #138 from vim-volt/devel
Release v0.2.2
2 parents 4203b29 + 354d5bc commit aea90c3

17 files changed

+322
-303
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ language: go
33
matrix:
44
include:
55
- os: linux
6-
go: 1.9.1
6+
go: 1.9
77
- os: linux
88
go: tip
99
- os: osx
1010
osx_image: xcode8.3
11-
go: 1.9.1
11+
go: 1.9
1212
- os: osx
1313
osx_image: xcode8.3
1414
go: tip

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ Or download binaries from [GitHub releases](https://github.com/vim-volt/volt/rel
125125

126126
## Build environment
127127

128-
* Go 1.9.1 or higher **with [the patch for os.RemoveAll()](https://go-review.googlesource.com/c/go/+/62970) ([#1](https://github.com/vim-volt/go-volt/issues/1))**
128+
* Go 1.9 or higher
129+
* If you are on WSL (Windows Subsystem Linux), note that you need **[the patch for os.RemoveAll()](https://go-review.googlesource.com/c/go/+/62970) ([#1](https://github.com/vim-volt/go-volt/issues/1))**
130+
* But it's a hassle, you can just download linux-386/amd64 binaries from [GitHub releases](https://github.com/vim-volt/volt/releases) :)
129131

130132
## Self upgrade
131133

cmd/build.go

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@ import (
2626
"gopkg.in/src-d/go-git.v4/plumbing/object"
2727
)
2828

29-
type buildFlagsType struct {
29+
var BuildModeInvalidType = os.ModeSymlink | os.ModeNamedPipe | os.ModeSocket | os.ModeDevice
30+
31+
func init() {
32+
cmdMap["build"] = &buildCmd{}
33+
}
34+
35+
type buildCmd struct {
3036
helped bool
3137
full bool
3238
}
3339

34-
var buildFlags buildFlagsType
35-
36-
var BuildModeInvalidType = os.ModeSymlink | os.ModeNamedPipe | os.ModeSocket | os.ModeDevice
37-
var ErrBuildModeType = "does not allow symlink, named pipe, socket, device"
38-
39-
func init() {
40+
func (cmd *buildCmd) FlagSet() *flag.FlagSet {
4041
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
4142
fs.SetOutput(os.Stdout)
4243
fs.Usage = func() {
@@ -62,22 +63,17 @@ Description
6263
fmt.Println("Options")
6364
fs.PrintDefaults()
6465
fmt.Println()
65-
buildFlags.helped = true
66+
cmd.helped = true
6667
}
67-
fs.BoolVar(&buildFlags.full, "full", false, "full build")
68-
69-
cmdFlagSet["build"] = fs
68+
fs.BoolVar(&cmd.full, "full", false, "full build")
69+
return fs
7070
}
7171

72-
type buildCmd struct{}
73-
74-
func Build(args []string) int {
75-
cmd := buildCmd{}
76-
72+
func (cmd *buildCmd) Run(args []string) int {
7773
// Parse args
78-
fs := cmdFlagSet["build"]
74+
fs := cmd.FlagSet()
7975
fs.Parse(args)
80-
if buildFlags.helped {
76+
if cmd.helped {
8177
return 0
8278
}
8379

@@ -89,7 +85,7 @@ func Build(args []string) int {
8985
}
9086
defer transaction.Remove()
9187

92-
err = cmd.doBuild(buildFlags.full)
88+
err = cmd.doBuild(cmd.full)
9389
if err != nil {
9490
logger.Error("Failed to build:", err.Error())
9591
return 12
@@ -799,12 +795,8 @@ func (cmd *buildCmd) updateNonBareGitRepos(r *git.Repository, src, dst string, r
799795
continue
800796
}
801797
if file.Mode()&BuildModeInvalidType != 0 {
802-
abspath := filepath.Join(src, file.Name())
803-
done <- actionReposResult{
804-
err: errors.New(ErrBuildModeType + ": " + abspath),
805-
repos: repos,
806-
}
807-
return
798+
// Currenly skip the invalid files...
799+
continue
808800
}
809801
if !created[dst] {
810802
os.MkdirAll(dst, 0755)

cmd/cmd.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cmd
2+
3+
import (
4+
"flag"
5+
6+
"github.com/vim-volt/volt/logger"
7+
)
8+
9+
var cmdMap = make(map[string]Cmd)
10+
11+
type Cmd interface {
12+
Run(args []string) int
13+
FlagSet() *flag.FlagSet
14+
}
15+
16+
func Run(subCmd string, args []string) int {
17+
if self, exists := cmdMap[subCmd]; exists {
18+
return self.Run(args)
19+
}
20+
logger.Error("Unknown command '" + subCmd + "'")
21+
return 3
22+
}

cmd/disable.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import (
1010
"github.com/vim-volt/volt/pathutil"
1111
)
1212

13-
type disableFlagsType struct {
14-
helped bool
13+
func init() {
14+
cmdMap["disable"] = &disableCmd{}
1515
}
1616

17-
var disableFlags disableFlagsType
17+
type disableCmd struct {
18+
helped bool
19+
}
1820

19-
func init() {
21+
func (cmd *disableCmd) FlagSet() *flag.FlagSet {
2022
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
2123
fs.SetOutput(os.Stdout)
2224
fs.Usage = func() {
@@ -33,17 +35,12 @@ Description
3335
//fmt.Println("Options")
3436
//fs.PrintDefaults()
3537
fmt.Println()
36-
disableFlags.helped = true
38+
cmd.helped = true
3739
}
38-
39-
cmdFlagSet["disable"] = fs
40+
return fs
4041
}
4142

42-
type disableCmd struct{}
43-
44-
func Disable(args []string) int {
45-
cmd := disableCmd{}
46-
43+
func (cmd *disableCmd) Run(args []string) int {
4744
reposPathList, err := cmd.parseArgs(args)
4845
if err == ErrShowedHelp {
4946
return 0
@@ -66,10 +63,10 @@ func Disable(args []string) int {
6663
return 0
6764
}
6865

69-
func (*disableCmd) parseArgs(args []string) ([]string, error) {
70-
fs := cmdFlagSet["disable"]
66+
func (cmd *disableCmd) parseArgs(args []string) ([]string, error) {
67+
fs := cmd.FlagSet()
7168
fs.Parse(args)
72-
if disableFlags.helped {
69+
if cmd.helped {
7370
return nil, ErrShowedHelp
7471
}
7572

cmd/enable.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import (
1010
"github.com/vim-volt/volt/pathutil"
1111
)
1212

13-
type enableFlagsType struct {
14-
helped bool
13+
func init() {
14+
cmdMap["enable"] = &enableCmd{}
1515
}
1616

17-
var enableFlags enableFlagsType
17+
type enableCmd struct {
18+
helped bool
19+
}
1820

19-
func init() {
21+
func (cmd *enableCmd) FlagSet() *flag.FlagSet {
2022
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
2123
fs.SetOutput(os.Stdout)
2224
fs.Usage = func() {
@@ -33,17 +35,12 @@ Description
3335
//fmt.Println("Options")
3436
//fs.PrintDefaults()
3537
fmt.Println()
36-
enableFlags.helped = true
38+
cmd.helped = true
3739
}
38-
39-
cmdFlagSet["enable"] = fs
40+
return fs
4041
}
4142

42-
type enableCmd struct{}
43-
44-
func Enable(args []string) int {
45-
cmd := enableCmd{}
46-
43+
func (cmd *enableCmd) Run(args []string) int {
4744
reposPathList, err := cmd.parseArgs(args)
4845
if err == ErrShowedHelp {
4946
return 0
@@ -66,10 +63,10 @@ func Enable(args []string) int {
6663
return 0
6764
}
6865

69-
func (*enableCmd) parseArgs(args []string) ([]string, error) {
70-
fs := cmdFlagSet["enable"]
66+
func (cmd *enableCmd) parseArgs(args []string) ([]string, error) {
67+
fs := cmd.FlagSet()
7168
fs.Parse(args)
72-
if enableFlags.helped {
69+
if cmd.helped {
7370
return nil, ErrShowedHelp
7471
}
7572

0 commit comments

Comments
 (0)