cli: add minimal doc generator (#129)

* cli: add minimal doc generator

* fixup! cli: add
This commit is contained in:
Thomas Tendyck 2022-05-11 09:20:37 +02:00 committed by GitHub
parent 2fc9129b9f
commit d76703061b
5 changed files with 64 additions and 21 deletions

View file

@ -9,20 +9,39 @@ import (
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "constellation",
Short: "Manage your Constellation cluster",
Long: "Manage your Constellation cluster.",
PersistentPreRun: preRunRoot,
}
// Execute starts the CLI.
func Execute() error {
rootCmd := NewRootCmd()
ctx, cancel := signalContext(context.Background(), os.Interrupt)
defer cancel()
return rootCmd.ExecuteContext(ctx)
}
// NewRootCmd creates the root command.
func NewRootCmd() *cobra.Command {
rootCmd := &cobra.Command{
Use: "constellation",
Short: "Manage your Constellation cluster",
Long: "Manage your Constellation cluster.",
PersistentPreRun: preRunRoot,
}
// Set output of cmd.Print to stdout. (By default, it's stderr.)
rootCmd.SetOut(os.Stdout)
rootCmd.PersistentFlags().String("dev-config", "", "use settings from a development config")
must(rootCmd.MarkPersistentFlagFilename("dev-config", "json"))
rootCmd.AddCommand(newCreateCmd())
rootCmd.AddCommand(newInitCmd())
rootCmd.AddCommand(newVerifyCmd())
rootCmd.AddCommand(newRecoverCmd())
rootCmd.AddCommand(newTerminateCmd())
rootCmd.AddCommand(newVersionCmd())
return rootCmd
}
// signalContext returns a context that is canceled on the handed signal.
// The signal isn't watched after its first occurrence. Call the cancel
// function to ensure the internal goroutine is stopped and the signal isn't
@ -50,20 +69,6 @@ func signalContext(ctx context.Context, sig os.Signal) (context.Context, context
return sigCtx, cancelFunc
}
func init() {
cobra.EnableCommandSorting = false
// Set output of cmd.Print to stdout. (By default, it's stderr.)
rootCmd.SetOut(os.Stdout)
rootCmd.PersistentFlags().String("dev-config", "", "use settings from a development config")
must(rootCmd.MarkPersistentFlagFilename("dev-config", "json"))
rootCmd.AddCommand(newCreateCmd())
rootCmd.AddCommand(newInitCmd())
rootCmd.AddCommand(newVerifyCmd())
rootCmd.AddCommand(newRecoverCmd())
rootCmd.AddCommand(newTerminateCmd())
rootCmd.AddCommand(newVersionCmd())
}
func preRunRoot(cmd *cobra.Command, args []string) {
cmd.SilenceUsage = true
}