Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 32b0eaa

Browse files
authored
Merge pull request #81 from aaron-prindle/cobra-args
updated cobra and switched some code to use Args concept
2 parents f249e2a + 3af74ee commit 32b0eaa

File tree

12 files changed

+444
-320
lines changed

12 files changed

+444
-320
lines changed

Godeps/Godeps.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/analyze.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ var analyzeCmd = &cobra.Command{
3232
Use: "analyze",
3333
Short: "Analyzes an image: [image]",
3434
Long: `Analyzes an image using the specifed analyzers as indicated via flags (see documentation for available ones).`,
35-
Run: func(cmd *cobra.Command, args []string) {
35+
Args: func(cmd *cobra.Command, args []string) error {
3636
if err := validateArgs(args, checkAnalyzeArgNum, checkArgType); err != nil {
37-
glog.Error(err.Error())
38-
os.Exit(1)
37+
return errors.New(err.Error())
3938
}
4039
if err := checkIfValidAnalyzer(types); err != nil {
41-
glog.Error(err)
42-
os.Exit(1)
40+
return errors.New(err.Error())
4341
}
42+
return nil
43+
},
44+
Run: func(cmd *cobra.Command, args []string) {
4445
if err := analyzeImage(args[0], strings.Split(types, ",")); err != nil {
4546
glog.Error(err)
4647
os.Exit(1)
@@ -49,11 +50,8 @@ var analyzeCmd = &cobra.Command{
4950
}
5051

5152
func checkAnalyzeArgNum(args []string) error {
52-
var errMessage string
5353
if len(args) != 1 {
54-
errMessage = "'analyze' requires one image as an argument: container analyze [image]"
55-
glog.Errorf(errMessage)
56-
return errors.New(errMessage)
54+
return errors.New("'analyze' requires one image as an argument: container analyze [image]")
5755
}
5856
return nil
5957
}

cmd/diff.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ var diffCmd = &cobra.Command{
3333
Use: "diff",
3434
Short: "Compare two images: [image1] [image2]",
3535
Long: `Compares two images using the specifed analyzers as indicated via flags (see documentation for available ones).`,
36-
Run: func(cmd *cobra.Command, args []string) {
36+
Args: func(cmd *cobra.Command, args []string) error {
3737
if err := validateArgs(args, checkDiffArgNum, checkArgType); err != nil {
38-
glog.Error(err.Error())
39-
os.Exit(1)
38+
return errors.New(err.Error())
4039
}
4140
if err := checkIfValidAnalyzer(types); err != nil {
42-
glog.Error(err)
43-
os.Exit(1)
41+
return errors.New(err.Error())
4442
}
43+
return nil
44+
},
45+
Run: func(cmd *cobra.Command, args []string) {
4546
if err := diffImages(args[0], args[1], strings.Split(types, ",")); err != nil {
4647
glog.Error(err)
4748
os.Exit(1)
@@ -50,10 +51,8 @@ var diffCmd = &cobra.Command{
5051
}
5152

5253
func checkDiffArgNum(args []string) error {
53-
var errMessage string
5454
if len(args) != 2 {
55-
errMessage = "'diff' requires two images as arguments: container diff [image1] [image2]"
56-
return errors.New(errMessage)
55+
return errors.New("'diff' requires two images as arguments: container diff [image1] [image2]")
5756
}
5857
return nil
5958
}

cmd/version.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var versionCmd = &cobra.Command{
2727
Use: "version",
2828
Short: "Print the version of container-diff",
2929
Long: `Print the version of container-diff.`,
30+
Args: cobra.ExactArgs(0),
3031
Run: func(command *cobra.Command, args []string) {
3132
fmt.Println(version.GetVersion())
3233
},

vendor/github.com/spf13/cobra/.travis.yml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)