From 37aefe320d873eb95c052038e3801872a1a1e2f4 Mon Sep 17 00:00:00 2001 From: Charles Lowell <10964656+chlowell@users.noreply.github.com> Date: Fri, 24 May 2024 00:34:11 +0000 Subject: [PATCH] apiviewgo: print help instead of panicking when given no args --- src/go/cmd/root.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/go/cmd/root.go b/src/go/cmd/root.go index 896dc9e995a..b0211f752cf 100644 --- a/src/go/cmd/root.go +++ b/src/go/cmd/root.go @@ -12,17 +12,18 @@ import ( // rootCmd represents the base command when called without any subcommands var rootCmd = &cobra.Command{ - Use: "apiview ", - Short: "apiview will generate the JSON token output for APIView", - Long: `The apiview command can be used to generate the tokenized -output needed by the APIView tool to show a view of publicly -exposed portions of an SDK. The generated file will use the -following naming format: .json -NOTE: This command will overwrite any file with the same name -in the output directory.`, - // Uncomment the following line if your bare application - // has an action associated with it: + Use: "apiviewgo ", + Long: `apiviewgo outputs a file representing the public API of an Azure SDK for Go +module in APIView format. It writes this file to /.json, +overwriting any file of the same name.`, Run: func(cmd *cobra.Command, args []string) { + if len(args) != 2 { + err := cmd.Help() + if err != nil { + fmt.Println(err) + } + return + } err := CreateAPIView(args[0], args[1]) if err != nil { fmt.Println(err)