command

package
v0.0.0-...-76a9f8d Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const DEFANG_PORTAL_HOST = "portal.defang.dev"
View Source
const SERVICE_PORTAL_URL = "https://" + DEFANG_PORTAL_HOST + "/service"
View Source
const TIER_ERROR_MESSAGE = "current subscription tier does not allow this action: "

Variables

View Source
var RootCmd = &cobra.Command{
	SilenceUsage:  true,
	SilenceErrors: true,
	Use:           "defang",
	Args:          cobra.NoArgs,
	Short:         "Defang CLI is used to develop, deploy, and debug your cloud services",
	PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) {
		term.SetDebug(doDebug)

		if IsCompletionCommand(cmd) {
			return nil
		}

		defer func() {
			track.Cmd(cmd, "Invoked", P("args", args), P("err", err), P("non-interactive", nonInteractive), P("provider", providerID))
		}()

		switch colorMode {
		case ColorNever:
			term.ForceColor(false)
		case ColorAlways:
			term.ForceColor(true)
		}

		if cwd, _ := cmd.Flags().GetString("cwd"); cwd != "" {

			if err = os.Chdir(cwd); err != nil {
				return err
			}
		}

		client = cli.NewGrpcClient(cmd.Context(), getCluster())

		if v, err := client.GetVersions(cmd.Context()); err == nil {
			version := cmd.Root().Version
			term.Debug("Fabric:", v.Fabric, "CLI:", version, "CLI-Min:", v.CliMin)
			if hasTty && isNewer(version, v.CliMin) {
				term.Warn("Your CLI version is outdated. Please upgrade to the latest version by running:\n\n  defang upgrade\n")
				os.Setenv("DEFANG_HIDE_UPDATE", "1")
			}
		}

		if _, ok := cmd.Annotations[authNeeded]; !ok {
			return nil
		}

		if err = client.CheckLoginAndToS(cmd.Context()); err != nil {
			if nonInteractive {
				return err
			}

			if connect.CodeOf(err) == connect.CodeUnauthenticated {
				term.Debug("Server error:", err)
				term.Warn("Please log in to continue.")

				defer func() { track.Cmd(nil, "Login", P("reason", err)) }()
				if err = cli.InteractiveLogin(cmd.Context(), client, gitHubClientId, getCluster()); err != nil {
					return err
				}

				client = cli.NewGrpcClient(cmd.Context(), getCluster())

				if err = client.CheckLoginAndToS(cmd.Context()); err == nil {
					return nil
				}
			}

			if connect.CodeOf(err) == connect.CodeFailedPrecondition {
				term.Warn(prettyError(err))

				defer func() { track.Cmd(nil, "Terms", P("reason", err)) }()
				if err = cli.InteractiveAgreeToS(cmd.Context(), client); err != nil {
					return err
				}
			}
		}

		return err
	},
}

Functions

func Execute

func Execute(ctx context.Context) error

func GetCurrentVersion

func GetCurrentVersion() string

func GetLatestVersion

func GetLatestVersion(ctx context.Context) (string, error)

func IsCompletionCommand

func IsCompletionCommand(cmd *cobra.Command) bool

func P

func P(name string, value interface{}) cliClient.Property

func SetupCommands

func SetupCommands(ctx context.Context, version string)

Types

type ColorMode

type ColorMode string
const (
	// ColorNever disables color output.
	ColorNever ColorMode = "never"
	// ColorAuto enables color output only if the output is connected to a terminal.
	ColorAuto ColorMode = "auto"
	// ColorAlways enables color output.
	ColorAlways ColorMode = "always"
)

func (*ColorMode) Set

func (c *ColorMode) Set(value string) error

func (ColorMode) String

func (c ColorMode) String() string

func (ColorMode) Type

func (c ColorMode) Type() string

type ErrNoPermission

type ErrNoPermission string

func (ErrNoPermission) Error

func (e ErrNoPermission) Error() string

type ExitCode

type ExitCode int

func (ExitCode) Error

func (e ExitCode) Error() string

type Mode

func (*Mode) Set

func (b *Mode) Set(s string) error

func (Mode) String

func (b Mode) String() string

func (Mode) Type

func (b Mode) Type() string

func (Mode) Value

func (b Mode) Value() defangv1.DeploymentMode

Jump to

Keyboard shortcuts

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