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

updated cobra and switched some code to use Args concept #81

Merged
merged 1 commit into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets make an issue to replace the "arg count and type checking" to be their own flag types.

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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, we should use this in minikube to replace some boilerplate

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