cmd

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "morty",
	Short: "Morty CLI is used to interact with the Morty serverless platform.",
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		// By default, if there is no value for the environment variable
		// MORTY_LOG, all logs are disabled.
		//
		// The program will produce only
		// outputs that comes from fmt.Print instructions.
		// But in some cases, it would be great to have the opportunity
		// to see what is going on in the execution of the program.
		//
		// If a value is provided, a logger will be configured. If the value
		// can't be parsed, the default log level will be applied, INFO.
		var level log.Level

		envFlag := os.Getenv(logEnvVarKey)
		cliFlag, _ := cmd.Flags().GetCount("verbose")

		switch cliFlag {
		case 1:
			level = log.InfoLevel
		case 2:
			level = log.DebugLevel
		case 3:
			level = log.TraceLevel
		default:
			level, _ = log.ParseLevel(envFlag)
		}

		if level == 0 {
			log.SetOutput(io.Discard)
		} else {
			log.SetLevel(level)
		}

		cfg, err := cliconfig.Load()
		if err != nil {
			log.Fatal(err)
		}

		currentCtx, err := cfg.GetCurrentContext()
		if err != nil {
			log.Fatal(err)
		}

		log.Infof("Active context : %s", cfg.Current)

		ctx := context.WithValue(cmd.Context(), cliconfig.CtxKey{}, cfg)
		ctx = context.WithValue(ctx, cliconfig.CurrentCtxKey{}, currentCtx)
		ctx = context.WithValue(ctx, cliconfig.ControllerClientContextKey{}, makeMortyClient(currentCtx.Controller))
		ctx = context.WithValue(ctx, cliconfig.RegistryClientContextKey{}, makeRegistryClient(currentCtx.Registry))

		cmd.SetContext(ctx)
	},
}

rootCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL