cli

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

Package cli contains all definitions pertaining to the user-visible commands of the epinio client. It provides the viper/cobra setup.

Index

Constants

This section is empty.

Variables

View Source
var CmdApp = &cobra.Command{
	Use:           "app",
	Aliases:       []string{"apps"},
	Short:         "Epinio application features",
	Long:          `Manage epinio application`,
	SilenceErrors: false,
	Args:          cobra.MinimumNArgs(1),
}

CmdApp implements the command: epinio app

View Source
var CmdAppChart = &cobra.Command{
	Use:   "chart",
	Short: "Epinio application chart management",
	Long:  `Manage epinio application charts`,
}

CmdAppChart implements the command: epinio app chart

View Source
var CmdAppChartDefault = &cobra.Command{
	Use:               "default [CHARTNAME]",
	Short:             "Set or show app chart default",
	Long:              "Set or show app chart default",
	Args:              cobra.MaximumNArgs(1),
	ValidArgsFunction: matchingChartFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		if len(args) == 1 {
			err = client.ChartDefaultSet(cmd.Context(), args[0])
			if err != nil {
				return errors.Wrap(err, "error setting app chart default")
			}
		} else {
			err = client.ChartDefaultShow(cmd.Context())
			if err != nil {
				return errors.Wrap(err, "error showing app chart default")
			}
		}

		return nil
	},
}

CmdAppChartDefault implements the command: epinio app chart default

View Source
var CmdAppChartList = &cobra.Command{
	Use:   "list",
	Short: "List application charts",
	Long:  "List applications charts",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.ChartList(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error listing app charts")
		}

		return nil
	},
}

CmdAppChartList implements the command: epinio app chart list

View Source
var CmdAppChartShow = &cobra.Command{
	Use:               "show CHARTNAME",
	Short:             "Describe application chart",
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: matchingChartFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.ChartShow(cmd.Context(), args[0])
		if err != nil {
			return errors.Wrap(err, "error showing app chart")
		}

		return nil
	},
}

CmdAppChartShow implements the command: epinio app env show

View Source
var CmdAppCreate = &cobra.Command{
	Use:   "create NAME",
	Short: "Create just the app, without creating a workload",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		m, err := manifest.UpdateICE(models.ApplicationManifest{}, cmd)
		if err != nil {
			return errors.Wrap(err, "unable to get app configuration")
		}

		m, err = manifest.UpdateAppChart(m, cmd)
		if err != nil {
			return errors.Wrap(err, "unable to get app chart")
		}

		m, err = manifest.UpdateRoutes(m, cmd)
		if err != nil {
			return err
		}

		err = client.AppCreate(args[0], m.Configuration)

		return errors.Wrap(err, "error creating app")
	},
}

CmdAppCreate implements the command: epinio apps create

View Source
var CmdAppDelete = &cobra.Command{
	Use:   "delete NAME1 [NAME2 ...]",
	Short: "Deletes one or more applications",
	Args:  cobra.MinimumNArgs(1),
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		epinioClient, err := usercmd.New(cmd.Context())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		matches := epinioClient.AppsMatching(toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.Delete(cmd.Context(), args)
		if err != nil {
			return errors.Wrap(err, "error deleting app")
		}

		return nil
	},
}

CmdAppDelete implements the command: epinio app delete

View Source
var CmdAppEnv = &cobra.Command{
	Use:   "env",
	Short: "Epinio application configuration",
	Long:  `Manage epinio application environment variables`,
}

CmdAppEnv implements the command: epinio app env

View Source
var CmdAppExec = &cobra.Command{
	Use:               "exec NAME",
	Short:             "creates a shell to the application",
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: matchingAppsFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		instance, err := cmd.Flags().GetString("instance")
		if err != nil {
			cmd.SilenceUsage = false
			return errors.Wrap(err, "could not read instance parameter")
		}

		err = client.AppExec(cmd.Context(), args[0], instance)

		return errors.Wrap(err, "error getting a shell to application")
	},
}

CmdAppExec implements the command: epinio apps exec

View Source
var CmdAppExport = &cobra.Command{
	Use:               "export NAME DIRECTORY",
	Short:             "Export the named application into the directory",
	Args:              cobra.ExactArgs(2),
	ValidArgsFunction: matchingAppsFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.AppExport(args[0], args[1])

		return errors.Wrap(err, "error exporting app")
	},
}

CmdAppExport implements the command: epinio apps export

View Source
var CmdAppList = &cobra.Command{
	Use:   "list [--all]",
	Short: "Lists applications",
	Long:  "Lists applications in the targeted namespace, or all",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		all, err := cmd.Flags().GetBool("all")
		if err != nil {
			return errors.Wrap(err, "error reading option --all")
		}

		err = client.Apps(all)

		return errors.Wrap(err, "error listing apps")
	},
}

CmdAppList implements the command: epinio app list

View Source
var CmdAppLogs = &cobra.Command{
	Use:               "logs NAME",
	Short:             "Streams the logs of the application",
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: matchingAppsFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		follow, err := cmd.Flags().GetBool("follow")
		if err != nil {
			return errors.Wrap(err, "error reading option --follow")
		}

		staging, err := cmd.Flags().GetBool("staging")
		if err != nil {
			return errors.Wrap(err, "error reading option --staging")
		}

		stageID := ""
		if staging {
			stageID, err = client.AppStageID(args[0])
			if err != nil {
				return errors.Wrap(err, "error checking app")
			}
		}

		err = client.AppLogs(args[0], stageID, follow)

		return errors.Wrap(err, "error streaming application logs")
	},
}

CmdAppLogs implements the command: epinio apps logs

View Source
var CmdAppManifest = &cobra.Command{
	Use:               "manifest NAME MANIFESTPATH",
	Short:             "Save state of the named application as a manifest",
	Args:              cobra.ExactArgs(2),
	ValidArgsFunction: matchingAppsFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.AppManifest(args[0], args[1])

		return errors.Wrap(err, "error getting app manifest")
	},
}

CmdAppManifest implements the command: epinio apps manifest

View Source
var CmdAppPortForward = &cobra.Command{
	Use:               "port-forward NAME [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N]",
	Short:             "forward one or more local ports to a pod",
	Args:              cobra.MinimumNArgs(2),
	ValidArgsFunction: matchingAppsFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		appName := args[0]
		ports := args[1:]

		err = client.AppPortForward(cmd.Context(), appName, portForwardInstance, portForwardAddress, ports)

		return errors.Wrap(err, "error port forwarding to application")
	},
}

CmdAppPortForward implements the command: epinio apps port-forward

View Source
var CmdAppPush = &cobra.Command{
	Use:   "push [flags] [PATH_TO_APPLICATION_MANIFEST]",
	Short: "Push an application declared in the specified manifest",
	Args:  cobra.RangeArgs(0, 1),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		wd, err := os.Getwd()
		if err != nil {
			return errors.Wrap(err, "working directory not accessible")
		}

		var manifestPath string

		if len(args) == 1 {
			manifestPath = args[0]
		} else {
			manifestPath = filepath.Join(wd, "epinio.yml")
		}

		m, err := manifest.Get(manifestPath)
		if err != nil {
			cmd.SilenceUsage = false
			return errors.Wrap(err, "Manifest error")
		}

		m, err = manifest.UpdateICE(m, cmd)
		if err != nil {
			return err
		}

		m, err = manifest.UpdateBASN(m, cmd)
		if err != nil {
			return err
		}

		m, err = manifest.UpdateRoutes(m, cmd)
		if err != nil {
			return err
		}

		if m.Name == "" {
			cmd.SilenceUsage = false
			return errors.New("Name required, not found in manifest nor options")
		}

		if m.Origin.Kind == models.OriginNone {
			m.Origin.Kind = models.OriginPath
			m.Origin.Path = wd
		}

		if m.Origin.Kind == models.OriginPath {
			if _, err := os.Stat(m.Origin.Path); err != nil {

				cmd.SilenceUsage = false
				return errors.Wrap(err, "path not accessible")
			}
		}

		params := usercmd.PushParams{
			ApplicationManifest: m,
		}

		err = client.Push(cmd.Context(), params)
		if err != nil {
			return errors.Wrap(err, "error pushing app to server")
		}

		return nil
	},
}

CmdAppPush implements the command: epinio app push

View Source
var CmdAppRestage = &cobra.Command{
	Use:               "restage NAME",
	Short:             "Restage the application",
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: matchingAppsFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.AppRestage(args[0])

		return errors.Wrap(err, "error restaging app")
	},
}

CmdAppRestage implements the command: epinio app restage

View Source
var CmdAppRestart = &cobra.Command{
	Use:               "restart NAME",
	Short:             "Restart the application",
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: matchingAppsFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.AppRestart(args[0])

		return errors.Wrap(err, "error restarting app")
	},
}

CmdAppRestart implements the command: epinio app restart

View Source
var CmdAppShow = &cobra.Command{
	Use:               "show NAME",
	Short:             "Describe the named application",
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: matchingAppsFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.AppShow(args[0])

		return errors.Wrap(err, "error showing app")
	},
}

CmdAppShow implements the command: epinio apps show

View Source
var CmdAppUpdate = &cobra.Command{
	Use:               "update NAME",
	Short:             "Update the named application",
	Long:              "Update the running application's attributes (e.g. instances)",
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: matchingAppsFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		m, err := manifest.UpdateICE(models.ApplicationManifest{}, cmd)
		if err != nil {
			return errors.Wrap(err, "unable to get app configuration")
		}

		m, err = manifest.UpdateAppChart(m, cmd)
		if err != nil {
			return errors.Wrap(err, "unable to get app chart")
		}

		m, err = manifest.UpdateRoutes(m, cmd)
		if err != nil {
			return errors.Wrap(err, "unable to update domains")
		}

		err = client.AppUpdate(args[0], m.Configuration)

		return errors.Wrap(err, "error updating the app")
	},
}

CmdAppUpdate implements the command: epinio apps update It scales the named app

View Source
var CmdClientSync = &cobra.Command{
	Use:   "client-sync",
	Short: "Downloads a client binary matching the currently logged server",
	Long:  `Synchronizes the epinio client with the server by downloading the matching binary and replacing the current one.`,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.ClientSync()
		if err != nil {
			return errors.Wrap(err, "error syncing the Epinio client")
		}

		return nil
	},
}

CmdClientSync implements the command: epinio client-sync

View Source
var CmdCompletion = &cobra.Command{
	Use:   "completion [bash|zsh|fish|powershell]",
	Short: "Generate completion script for a shell",
	Long: `To load completions:

Bash:

$ source <(epinio completion bash)

# To load completions for each session, execute once:
Linux:
  $ epinio completion bash > /etc/bash_completion.d/epinio
MacOS:
  $ epinio completion bash > /usr/local/etc/bash_completion.d/epinio

ATTENTION:
    The generated script requires the bash-completion package.
    See https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion
    for information on how to install and activate it.

Zsh:

# If shell completion is not already enabled in your environment you will need
# to enable it.  You can execute the following once:

$ echo "autoload -U compinit; compinit" >> ~/.zshrc

# To load completions for each session, execute once:
$ epinio completion zsh > "${fpath[1]}/_epinio"

# You will need to start a new shell for this setup to take effect.

Fish:

$ epinio completion fish | source

# To load completions for each session, execute once:
$ epinio completion fish > ~/.config/fish/completions/epinio.fish

Powershell:

PS> epinio completion powershell | Out-String | Invoke-Expression

# To load completions for every new session, run:
PS> epinio completion powershell > epinio.ps1
# and source this file from your powershell profile.
`,
	DisableFlagsInUseLine: true,
	ValidArgs:             []string{"bash", "zsh", "fish", "powershell"},
	Args:                  cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
	RunE: func(cmd *cobra.Command, args []string) error {
		switch args[0] {
		case "bash":
			return cmd.Root().GenBashCompletion(os.Stdout)
		case "zsh":
			return cmd.Root().GenZshCompletion(os.Stdout)
		case "fish":
			return cmd.Root().GenFishCompletion(os.Stdout, true)
		case "powershell":
			return cmd.Root().GenPowerShellCompletion(os.Stdout)
		}
		return errors.New("Internal error: Invalid shell")
	},
}

CmdCompletion represents the completion command

View Source
var CmdConfiguration = &cobra.Command{
	Use:           "configuration",
	Aliases:       []string{"configurations"},
	Short:         "Epinio configuration features",
	Long:          `Handle configuration features with Epinio`,
	SilenceErrors: true,
	SilenceUsage:  true,
	Args:          cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := cmd.Usage(); err != nil {
			return err
		}
		return fmt.Errorf(`Unknown method "%s"`, args[0])
	},
}

CmdConfiguration implements the command: epinio configuration

View Source
var CmdConfigurationBind = &cobra.Command{
	Use:               "bind NAME APP",
	Short:             "Bind a configuration to an application",
	Long:              `Bind configuration by name, to named application.`,
	Args:              cobra.ExactArgs(2),
	RunE:              ConfigurationBind,
	ValidArgsFunction: findConfigurationApp,
}

CmdConfigurationBind implements the command: epinio configuration bind

View Source
var CmdConfigurationCreate = &cobra.Command{
	Use:   "create NAME (KEY VALUE)...",
	Short: "Create a configuration",
	Long:  `Create configuration by name and key/value dictionary.`,
	Args: func(cmd *cobra.Command, args []string) error {
		if len(args) < 3 {
			return errors.New("Not enough arguments, expected name, key, and value")
		}
		if len(args)%2 == 0 {
			return errors.New("Last Key has no value")
		}
		return nil
	},
	RunE: ConfigurationCreate,
}

CmdConfigurationCreate implements the command: epinio configuration create

View Source
var CmdConfigurationDelete = &cobra.Command{
	Use:   "delete NAME1 [NAME2 ...]",
	Short: "Delete one or more configurations",
	Long:  `Delete configurations by name.`,
	Args:  cobra.MinimumNArgs(1),
	RunE:  ConfigurationDelete,
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		epinioClient, err := usercmd.New(cmd.Context())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}
		epinioClient.API.DisableVersionWarning()

		matches := epinioClient.ConfigurationMatching(context.Background(), toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdConfigurationDelete implements the command: epinio configuration delete

View Source
var CmdConfigurationList = &cobra.Command{
	Use:   "list [--all]",
	Short: "Lists configurations",
	Long:  "Lists configurations in the targeted namespace, or all",
	RunE:  ConfigurationList,
}

CmdConfigurationList implements the command: epinio configuration list

View Source
var CmdConfigurationShow = &cobra.Command{
	Use:               "show NAME",
	Short:             "Configuration information",
	Long:              `Show detailed information of the named configuration.`,
	Args:              cobra.ExactArgs(1),
	RunE:              ConfigurationShow,
	ValidArgsFunction: matchingConfigurationFinder,
}

CmdConfigurationShow implements the command: epinio configuration show

View Source
var CmdConfigurationUnbind = &cobra.Command{
	Use:               "unbind NAME APP",
	Short:             "Unbind configuration from an application",
	Long:              `Unbind configuration by name, from named application.`,
	Args:              cobra.ExactArgs(2),
	RunE:              ConfigurationUnbind,
	ValidArgsFunction: findConfigurationApp,
}

CmdConfigurationUnbind implements the command: epinio configuration unbind

View Source
var CmdConfigurationUpdate = &cobra.Command{
	Use:   "update NAME [flags]",
	Short: "Update a configuration",
	Long:  `Update configuration by name and change instructions through flags.`,
	Args:  cobra.ExactArgs(1),
	RunE:  ConfigurationUpdate,
}

CmdConfigurationUpdate implements the command: epinio configuration create

View Source
var CmdDebug = &cobra.Command{
	Hidden:        true,
	Use:           "debug",
	Short:         "Dev Tools",
	Long:          `Developer Tools. Hidden From Regular User.`,
	SilenceErrors: true,
	SilenceUsage:  true,
	Args:          cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := cmd.Usage(); err != nil {
			return err
		}
		return fmt.Errorf(`Unknown method "%s"`, args[0])
	},
}

CmdDebug implements the command: epinio debug

View Source
var CmdDebugTTY = &cobra.Command{
	Use:   "tty",
	Short: "Running In a Terminal?",
	Long:  `Running In a Terminal?`,
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true
		if isatty.IsTerminal(os.Stdout.Fd()) {
			fmt.Println("Is Terminal")
		} else if isatty.IsCygwinTerminal(os.Stdout.Fd()) {
			fmt.Println("Is Cygwin/MSYS2 Terminal")
		} else {
			fmt.Println("Is Not Terminal")
		}
		return nil
	},
}

CmdDebug implements the command: epinio debug tty

View Source
var CmdEnvList = &cobra.Command{
	Use:               "list APPNAME",
	Short:             "Lists application environment",
	Long:              "Lists environment variables of named application",
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: matchingAppsFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.EnvList(cmd.Context(), args[0])
		if err != nil {
			return errors.Wrap(err, "error listing app environment")
		}

		return nil
	},
}

CmdEnvList implements the command: epinio app env list

View Source
var CmdEnvSet = &cobra.Command{
	Use:   "set APPNAME NAME VALUE",
	Short: "Extend application environment",
	Long:  "Add or change environment variable of named application",
	Args:  cobra.ExactArgs(3),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())

		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.EnvSet(cmd.Context(), args[0], args[1], args[2])
		if err != nil {
			return errors.Wrap(err, "error setting into app environment")
		}

		return nil
	},
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {

		if len(args) > 1 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := usercmd.New(cmd.Context())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}
		app.API.DisableVersionWarning()

		matches := app.AppsMatching(toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdEnvSet implements the command: epinio app env set

View Source
var CmdEnvShow = &cobra.Command{
	Use:   "show APPNAME NAME",
	Short: "Describe application's environment variable",
	Args:  cobra.ExactArgs(2),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())

		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.EnvShow(cmd.Context(), args[0], args[1])
		if err != nil {
			return errors.Wrap(err, "error accessing app environment")
		}

		return nil
	},
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		if len(args) > 2 {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app, err := usercmd.New(cmd.Context())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}
		app.API.DisableVersionWarning()

		if len(args) == 1 {

			matches := app.EnvMatching(context.Background(), args[0], toComplete)
			return matches, cobra.ShellCompDirectiveNoFileComp
		}

		matches := app.AppsMatching(toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
}

CmdEnvShow implements the command: epinio app env show

View Source
var CmdEnvUnset = &cobra.Command{
	Use:               "unset APPNAME NAME",
	Short:             "Shrink application environment",
	Long:              "Remove environment variable from named application",
	Args:              cobra.ExactArgs(2),
	ValidArgsFunction: matchingAppsFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.EnvUnset(cmd.Context(), args[0], args[1])
		if err != nil {
			return errors.Wrap(err, "error removing from app environment")
		}

		return nil
	},
}

CmdEnvUnset implements the command: epinio app env unset

View Source
var CmdInfo = &cobra.Command{
	Use:   "info",
	Short: "Shows information about the Epinio environment",
	Long:  `Shows status and versions for epinio's server-side components.`,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.Info()
		if err != nil {
			return errors.Wrap(err, "error retrieving Epinio environment information")
		}

		return nil
	},
}

CmdInfo implements the command: epinio info

View Source
var CmdLogin = &cobra.Command{
	Use:   "login [URL]",
	Short: "Epinio login to the server",
	Long:  `The login command allows you to authenticate against an Epinio instance and updates the settings file with the generated authentication token`,
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return err
		}

		address := args[0]
		username, err := cmd.Flags().GetString("user")
		if err != nil {
			return err
		}

		password, err := cmd.Flags().GetString("password")
		if err != nil {
			return err
		}

		trustCA, err := cmd.Flags().GetBool("trust-ca")
		if err != nil {
			return err
		}

		oidc, err := cmd.Flags().GetBool("oidc")
		if err != nil {
			return err
		}

		prompt, err := cmd.Flags().GetBool("prompt")
		if err != nil {
			return err
		}

		if oidc {
			return client.LoginOIDC(cmd.Context(), address, trustCA, prompt)
		}
		return client.Login(cmd.Context(), username, password, address, trustCA)
	},
}

CmdLogin implements the command: epinio login

View Source
var CmdNamespace = &cobra.Command{
	Use:           "namespace",
	Aliases:       []string{"namespaces"},
	Short:         "Epinio-controlled namespaces",
	Long:          `Manage epinio-controlled namespaces`,
	SilenceErrors: true,
	SilenceUsage:  true,
	Args:          cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := cmd.Usage(); err != nil {
			return err
		}
		return fmt.Errorf(`Unknown method "%s"`, args[0])
	},
}

CmdNamespace implements the command: epinio namespace

View Source
var CmdNamespaceCreate = &cobra.Command{
	Use:   "create NAME",
	Short: "Creates an epinio-controlled namespace",
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.CreateNamespace(args[0])
		if err != nil {
			return errors.Wrap(err, "error creating epinio-controlled namespace")
		}

		return nil
	},
}

CmdNamespaceCreate implements the command: epinio namespace create

View Source
var CmdNamespaceDelete = &cobra.Command{
	Use:               "delete NAME",
	Short:             "Deletes an epinio-controlled namespace",
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: matchingNamespaceFinder,
	PreRunE: func(cmd *cobra.Command, args []string) error {
		force, err := cmd.Flags().GetBool("force")
		if err != nil {
			return err
		}
		if !force {
			cmd.Printf("You are about to delete namespace %s and everything it includes, i.e. applications, configurations, etc. Are you sure? (y/n): ", args[0])
			if !askConfirmation(cmd) {
				return errors.New("Cancelled by user")
			}
		}

		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.DeleteNamespace(args[0])
		if err != nil {
			return errors.Wrap(err, "error deleting epinio-controlled namespace")
		}

		return nil
	},
}

CmdNamespaceDelete implements the command: epinio namespace delete

View Source
var CmdNamespaceList = &cobra.Command{
	Use:   "list",
	Short: "Lists all epinio-controlled namespaces",
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.Namespaces()
		if err != nil {
			return errors.Wrap(err, "error listing epinio-controlled namespaces")
		}

		return nil
	},
}

CmdNamespaces implements the command: epinio namespace list

View Source
var CmdNamespaceShow = &cobra.Command{
	Use:               "show NAME",
	Short:             "Shows the details of an epinio-controlled namespace",
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: matchingNamespaceFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.ShowNamespace(args[0])
		if err != nil {
			return errors.Wrap(err, "error showing epinio-controlled namespace")
		}

		return nil
	},
}

CmdNamespaceShow implements the command: epinio namespace show

View Source
var CmdServer = &cobra.Command{
	Use:   "server",
	Short: "Starts the Epinio server.",
	Long:  "This command starts the Epinio server. `epinio install` ensures the server is running inside your cluster. Normally you don't need to run this command manually.",
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true
		logger := tracelog.NewLogger().WithName("EpinioServer")

		handler, err := server.NewHandler(logger)
		if err != nil {
			return errors.Wrap(err, "error creating handler")
		}

		port := viper.GetInt("port")
		listener, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
		if err != nil {
			return errors.Wrap(err, "error creating listener")
		}

		ui := termui.NewUI()
		ui.Normal().Msg("Epinio version: " + version.Version)
		listeningPort := strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)
		ui.Normal().Msg("listening on localhost on port " + listeningPort)

		trackingDisabled := viper.GetBool("disable-tracking")
		upgradeResponderAddress := viper.GetString("upgrade-responder-address")
		logger.Info("Checking upgrade-responder tracking", "disabled", trackingDisabled, "upgradeResponderAddress", upgradeResponderAddress)

		if !trackingDisabled {
			checker, err := upgraderesponder.NewChecker(context.Background(), logger, upgradeResponderAddress)
			if err != nil {
				return errors.Wrap(err, "error creating listener")
			}

			checker.Start()
			defer checker.Stop()
		}

		return startServerGracefully(listener, handler)
	},
}

CmdServer implements the command: epinio server

View Source
var CmdServiceBind = &cobra.Command{
	Use:               "bind SERVICENAME APPNAME",
	Short:             "Bind a service SERVICENAME to an Epinio app APPNAME",
	Args:              cobra.ExactArgs(2),
	ValidArgsFunction: findServiceApp,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		serviceName := args[0]
		appName := args[1]

		err = client.ServiceBind(serviceName, appName)
		return errors.Wrap(err, "error binding service")
	},
}
View Source
var CmdServiceCatalog = &cobra.Command{
	Use:               "catalog [NAME]",
	Short:             "Lists all available Epinio catalog services, or show the details of the specified one",
	ValidArgsFunction: matchingCatalogFinder,
	Args:              cobra.MaximumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		if len(args) == 0 {
			err = client.ServiceCatalog()
			return errors.Wrap(err, "error listing Epinio catalog services")
		}

		if len(args) == 1 {
			serviceName := args[0]
			err = client.ServiceCatalogShow(serviceName)
			return errors.Wrap(err, fmt.Sprintf("error showing %s Epinio catalog service", serviceName))
		}

		return nil
	},
}
View Source
var CmdServiceCreate = &cobra.Command{
	Use:               "create CATALOGSERVICENAME SERVICENAME",
	Short:             "Create a service SERVICENAME of an Epinio catalog service CATALOGSERVICENAME",
	Args:              cobra.ExactArgs(2),
	ValidArgsFunction: matchingCatalogFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		catalogServiceName := args[0]
		serviceName := args[1]

		err = client.ServiceCreate(catalogServiceName, serviceName)
		return errors.Wrap(err, "error creating service")
	},
}
View Source
var CmdServiceDelete = &cobra.Command{
	Use:   "delete SERVICENAME1 [SERVICENAME2 ...]",
	Short: "Delete one or more services",
	Args:  cobra.MinimumNArgs(1),
	ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
		app, err := usercmd.New(cmd.Context())
		if err != nil {
			return nil, cobra.ShellCompDirectiveNoFileComp
		}

		app.API.DisableVersionWarning()
		matches := app.ServiceMatching(toComplete)

		return matches, cobra.ShellCompDirectiveNoFileComp
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		unbind, err := cmd.Flags().GetBool("unbind")
		if err != nil {
			return errors.Wrap(err, "error reading option --unbind")
		}

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.ServiceDelete(args, unbind)
		return errors.Wrap(err, "error deleting service")
	},
}
View Source
var CmdServiceList = &cobra.Command{
	Use:   "list",
	Short: "List all the services in the targeted namespace",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		all, err := cmd.Flags().GetBool("all")
		if err != nil {
			return errors.Wrap(err, "error reading option --all")
		}

		if all {
			err = client.ServiceListAll()
		} else {
			err = client.ServiceList()
		}

		return errors.Wrap(err, "error listing services")
	},
}
View Source
var CmdServiceShow = &cobra.Command{
	Use:               "show SERVICENAME",
	Short:             "Show details of a service SERVICENAME",
	Args:              cobra.ExactArgs(1),
	ValidArgsFunction: matchingServiceFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		serviceName := args[0]

		err = client.ServiceShow(serviceName)
		return errors.Wrap(err, "error showing service")
	},
}
View Source
var CmdServiceUnbind = &cobra.Command{
	Use:               "unbind SERVICENAME APPNAME",
	Short:             "Unbinds a service SERVICENAME from an Epinio app APPNAME",
	Args:              cobra.ExactArgs(2),
	ValidArgsFunction: findServiceApp,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		serviceName := args[0]
		appName := args[1]

		err = client.ServiceUnbind(serviceName, appName)
		return errors.Wrap(err, "error unbinding service")
	},
}
View Source
var CmdServices = &cobra.Command{
	Use:           "service",
	Aliases:       []string{"services"},
	Short:         "Epinio service management",
	Long:          `Manage the epinio services`,
	SilenceErrors: false,
	Args:          cobra.ExactArgs(1),
}

CmdServices implements the command: epinio services

View Source
var CmdSettings = &cobra.Command{
	Use:           "settings",
	Short:         "Epinio settings management",
	Long:          `Manage the epinio cli settings`,
	SilenceErrors: true,
	SilenceUsage:  true,
	Args:          cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		if err := cmd.Usage(); err != nil {
			return err
		}
		return fmt.Errorf(`Unknown method "%s"`, args[0])
	},
}

CmdSettings implements the command: epinio settings

View Source
var CmdSettingsColors = &cobra.Command{
	Use:   "colors BOOL",
	Short: "Manage colored output",
	Long:  "Enable/Disable colored output",
	Args: func(cmd *cobra.Command, args []string) error {
		if len(args) != 1 {
			return errors.New("requires a boolean argument")
		}
		_, err := strconv.ParseBool(args[0])
		if err != nil {
			return errors.New("requires a boolean argument")
		}
		return nil
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		ui := termui.NewUI()

		theSettings, err := settings.Load()
		if err != nil {
			return errors.Wrap(err, "failed to load settings")
		}

		ui.Note().
			WithStringValue("Settings", helpers.AbsPath(theSettings.Location)).
			Msg("Edit Colorization Flag")

		colors, err := strconv.ParseBool(args[0])

		if err != nil {
			return errors.Wrap(err, "unexpected bool parsing error")
		}

		theSettings.Colors = colors
		if err := theSettings.Save(); err != nil {
			return err
		}

		ui.Success().WithBoolValue("Colors", theSettings.Colors).Msg("Ok")
		return nil
	},
}

CmdSettingsColors implements the command: epinio settings colors

View Source
var CmdSettingsShow = &cobra.Command{
	Use:   "show",
	Short: "Show the current settings",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		ui := termui.NewUI()

		theSettings, err := settings.Load()
		if err != nil {
			return errors.Wrap(err, "failed to load settings")
		}

		ui.Note().
			WithStringValue("Settings", helpers.AbsPath(theSettings.Location)).
			Msg("Show Settings")

		certInfo := color.CyanString("None defined")
		if theSettings.Certs != "" {
			certInfo = color.BlueString("Present")
		}

		var password string
		if theSettings.Password != "" {
			password = "***********"
			if viper.GetBool("show-password") {
				password = theSettings.Password
			}
		}

		var token string
		if theSettings.Token.AccessToken != "" {
			token = "***********"
			if viper.GetBool("show-token") {
				token = theSettings.Token.AccessToken
			}
		}

		ui.Success().
			WithTable("Key", "Value").
			WithTableRow("Colorized Output", color.MagentaString("%t", theSettings.Colors)).
			WithTableRow("Current Namespace", color.CyanString(theSettings.Namespace)).
			WithTableRow("Default App Chart", color.CyanString(theSettings.AppChart)).
			WithTableRow("API User Name", color.BlueString(theSettings.User)).
			WithTableRow("API Password", color.BlueString(password)).
			WithTableRow("API Token", color.BlueString(token)).
			WithTableRow("API Url", color.BlueString(theSettings.API)).
			WithTableRow("WSS Url", color.BlueString(theSettings.WSS)).
			WithTableRow("Certificates", certInfo).
			Msg("Ok")

		return nil
	},
}

CmdSettingsShow implements the command: epinio settings show

View Source
var CmdSettingsUpdateCA = &cobra.Command{
	Use:   "update-ca",
	Short: "Update the api location and CA certificate",
	Long:  "Update the api location and CA certificate from the current cluster",
	Args:  cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := admincmd.New()

		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		err = client.SettingsUpdateCA(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "failed to update the settings")
		}

		return nil
	},
}

CmdSettingsUpdateCA implements the command: epinio settings update-ca

View Source
var CmdTarget = &cobra.Command{
	Use:               "target [namespace]",
	Short:             "Targets an epinio-controlled namespace.",
	Args:              cobra.MaximumNArgs(1),
	ValidArgsFunction: matchingNamespaceFinder,
	RunE: func(cmd *cobra.Command, args []string) error {
		cmd.SilenceUsage = true

		client, err := usercmd.New(cmd.Context())
		if err != nil {
			return errors.Wrap(err, "error initializing cli")
		}

		namespace := ""
		if len(args) > 0 {
			namespace = args[0]
		}

		err = client.Target(namespace)
		if err != nil {
			return errors.Wrap(err, "failed to set target")
		}

		return nil
	},
}

CmdTarget implements the command: epinio target

Functions

func ConfigurationBind added in v0.6.0

func ConfigurationBind(cmd *cobra.Command, args []string) error

ConfigurationBind is the backend of command: epinio configuration bind

func ConfigurationCreate added in v0.6.0

func ConfigurationCreate(cmd *cobra.Command, args []string) error

ConfigurationCreate is the backend of command: epinio configuration create

func ConfigurationDelete added in v0.6.0

func ConfigurationDelete(cmd *cobra.Command, args []string) error

ConfigurationDelete is the backend of command: epinio configuration delete

func ConfigurationList added in v0.6.0

func ConfigurationList(cmd *cobra.Command, args []string) error

ConfigurationList is the backend of command: epinio configuration list

func ConfigurationShow added in v0.6.0

func ConfigurationShow(cmd *cobra.Command, args []string) error

ConfigurationShow is the backend of command: epinio configuration show

func ConfigurationUnbind added in v0.6.0

func ConfigurationUnbind(cmd *cobra.Command, args []string) error

ConfigurationUnbind is the backend of command: epinio configuration unbind

func ConfigurationUpdate added in v0.6.0

func ConfigurationUpdate(cmd *cobra.Command, args []string) error

ConfigurationUpdate is the backend of command: epinio configuration update

func CreateKubeClient

func CreateKubeClient(configPath string) kubernetes.Interface

CreateKubeClient returns a client for access to kubernetes It is currently not used

func Execute

func Execute()

Execute executes the root command. This is called by main.main(). It only needs to happen once to the rootCmd.

func ExitIfError

func ExitIfError(err error)

ExitIfError is a short form of ExitfIfError, with a standard message It is currently not used

func ExitfIfError

func ExitfIfError(err error, message string)

ExitfIfError stops the application with an error exit code, after printing error and message, if there is an error.

func ExitfWithMessage

func ExitfWithMessage(message string, args ...interface{})

ExitfWithMessage stops the application with an error exit code, after formatting and printing the message. It is currently not used

func NewEpinioCLI added in v0.0.19

func NewEpinioCLI() *cobra.Command

NewEpinioCLI returns the main `epinio` cli.

Types

This section is empty.

Directories

Path Synopsis
Package admincmd provides the commands of the admin CLI, which deals with installing and configurations
Package admincmd provides the commands of the admin CLI, which deals with installing and configurations
Package logprinter is used to print container log lines in color
Package logprinter is used to print container log lines in color
Package server provides the Epinio http server
Package server provides the Epinio http server
requestctx
Package requestctx provides access to special fields in the http request's context
Package requestctx provides access to special fields in the http request's context
Package usercmd provides Epinio CLI commands for users
Package usercmd provides Epinio CLI commands for users
usercmdfakes
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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