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

Commit

Permalink
Merge pull request #81 from aaron-prindle/cobra-args
Browse files Browse the repository at this point in the history
updated cobra and switched some code to use Args concept
  • Loading branch information
nkubala authored Sep 12, 2017
2 parents f249e2a + 3af74ee commit 32b0eaa
Show file tree
Hide file tree
Showing 12 changed files with 444 additions and 320 deletions.
5 changes: 3 additions & 2 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ var analyzeCmd = &cobra.Command{
Use: "analyze",
Short: "Analyzes an image: [image]",
Long: `Analyzes an image using the specifed analyzers as indicated via flags (see documentation for available ones).`,
Run: func(cmd *cobra.Command, args []string) {
Args: func(cmd *cobra.Command, args []string) error {
if err := validateArgs(args, checkAnalyzeArgNum, checkArgType); err != nil {
glog.Error(err.Error())
os.Exit(1)
return errors.New(err.Error())
}
if err := checkIfValidAnalyzer(types); err != nil {
glog.Error(err)
os.Exit(1)
return errors.New(err.Error())
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
if err := analyzeImage(args[0], strings.Split(types, ",")); err != nil {
glog.Error(err)
os.Exit(1)
Expand All @@ -49,11 +50,8 @@ var analyzeCmd = &cobra.Command{
}

func checkAnalyzeArgNum(args []string) error {
var errMessage string
if len(args) != 1 {
errMessage = "'analyze' requires one image as an argument: container analyze [image]"
glog.Errorf(errMessage)
return errors.New(errMessage)
return errors.New("'analyze' requires one image as an argument: container analyze [image]")
}
return nil
}
Expand Down
15 changes: 7 additions & 8 deletions cmd/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ var diffCmd = &cobra.Command{
Use: "diff",
Short: "Compare two images: [image1] [image2]",
Long: `Compares two images using the specifed analyzers as indicated via flags (see documentation for available ones).`,
Run: func(cmd *cobra.Command, args []string) {
Args: func(cmd *cobra.Command, args []string) error {
if err := validateArgs(args, checkDiffArgNum, checkArgType); err != nil {
glog.Error(err.Error())
os.Exit(1)
return errors.New(err.Error())
}
if err := checkIfValidAnalyzer(types); err != nil {
glog.Error(err)
os.Exit(1)
return errors.New(err.Error())
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
if err := diffImages(args[0], args[1], strings.Split(types, ",")); err != nil {
glog.Error(err)
os.Exit(1)
Expand All @@ -50,10 +51,8 @@ var diffCmd = &cobra.Command{
}

func checkDiffArgNum(args []string) error {
var errMessage string
if len(args) != 2 {
errMessage = "'diff' requires two images as arguments: container diff [image1] [image2]"
return errors.New(errMessage)
return errors.New("'diff' requires two images as arguments: container diff [image1] [image2]")
}
return nil
}
Expand Down
1 change: 1 addition & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version of container-diff",
Long: `Print the version of container-diff.`,
Args: cobra.ExactArgs(0),
Run: func(command *cobra.Command, args []string) {
fmt.Println(version.GetVersion())
},
Expand Down
4 changes: 2 additions & 2 deletions vendor/github.com/spf13/cobra/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 32b0eaa

Please sign in to comment.