From 60b50edbfdf7be945e72b31ca641e715ca2a6c6d Mon Sep 17 00:00:00 2001 From: Beni Cherniavsky-Paskin Date: Tue, 5 Mar 2019 14:16:39 +0200 Subject: [PATCH] --help: List available analyzers, improve Usage line --- cmd/analyze.go | 8 +++++--- cmd/diff.go | 8 +++++--- cmd/root.go | 13 ++++++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/cmd/analyze.go b/cmd/analyze.go index 0f673f97..2faaba6b 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -29,9 +29,11 @@ import ( ) 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).`, + Use: "analyze image", + Short: "Analyzes an image: container-diff image", + Long: `Analyzes an image using the specifed analyzers as indicated via --type flag(s). + +For details on how to specify images, run: container-diff help`, Args: func(cmd *cobra.Command, args []string) error { if err := validateArgs(args, checkAnalyzeArgNum, checkIfValidAnalyzer); err != nil { return err diff --git a/cmd/diff.go b/cmd/diff.go index 69ca393b..52c29bef 100644 --- a/cmd/diff.go +++ b/cmd/diff.go @@ -34,9 +34,11 @@ import ( var filename string 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).`, + Use: "diff image1 image2", + Short: "Compare two images: container-diff image1 image2", + Long: `Compares two images using the specifed analyzers as indicated via --type flag(s). + +For details on how to specify images, run: container-diff help`, Args: func(cmd *cobra.Command, args []string) error { if err := validateArgs(args, checkDiffArgNum, checkIfValidAnalyzer, checkFilenameFlag); err != nil { return err diff --git a/cmd/root.go b/cmd/root.go index 7a627ac1..b320f2d0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -223,8 +223,19 @@ func (d *diffTypes) Type() string { } func addSharedFlags(cmd *cobra.Command) { + sortedTypes := []string{} + for analyzerType := range differs.Analyzers { + sortedTypes = append(sortedTypes, analyzerType) + } + sort.Strings(sortedTypes) + supportedTypes := strings.Join(sortedTypes, ", ") + cmd.Flags().BoolVarP(&json, "json", "j", false, "JSON Output defines if the diff should be returned in a human readable format (false) or a JSON (true).") - cmd.Flags().VarP(&types, "type", "t", "This flag sets the list of analyzer types to use. Set it repeatedly to use multiple analyzers.") + cmd.Flags().VarP(&types, "type", "t", + fmt.Sprintf("This flag sets the list of analyzer types to use.\n"+ + "Set it repeatedly to use multiple analyzers.\n"+ + "Supported types: %s.", + supportedTypes)) cmd.Flags().BoolVarP(&save, "save", "s", false, "Set this flag to save rather than remove the final image filesystems on exit.") cmd.Flags().BoolVarP(&util.SortSize, "order", "o", false, "Set this flag to sort any file/package results by descending size. Otherwise, they will be sorted by name.") cmd.Flags().BoolVarP(&noCache, "no-cache", "n", false, "Set this to force retrieval of image filesystem on each run.")