cmd

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CompletionCmd = &cobra.Command{
	Use:   "completion",
	Short: TRCLI("cli.completion.summary"),
	Long:  TRCLI("cli.completion.description"),
	RunE: func(cmd *cobra.Command, args []string) error {

		err := RootCmd.GenBashCompletion(os.Stdout)
		if err != nil {
			return err
		}
		return nil
	},
}

CompletionCmd defines 'completion' subcommand

View Source
var ConfigureCmd = &cobra.Command{
	Use:   "configure",
	Short: TRCLI("cli.configure.summary"),
	Long:  TRCLI("cli.configure.description"),
	RunE: func(cmd *cobra.Command, args []string) error {
		pn := getSpecifiedProfileName()
		if pn == "" {
			pn = "default"
		}

		profile, err := collectProfileInfo(pn)
		if err != nil {
			cmd.SilenceUsage = true
			return err
		}

		err = saveProfile(pn, profile, configureOverwrite)
		if err != nil {
			cmd.SilenceUsage = true
			return err
		}

		return nil
	},
}

ConfigureCmd defines 'configure' subcommand

View Source
var ConfigureGetCmd = &cobra.Command{
	Use:   "get",
	Short: TRCLI("cli.configure.get.summary"),
	Long:  TRCLI("cli.configure.get.description"),
	RunE: func(cmd *cobra.Command, args []string) error {
		pn := getSpecifiedProfileName()
		if pn == "" {
			pn = "default"
		}

		p, err := loadProfile(pn)
		if err != nil {
			return err
		}

		return prettyPrintObjectAsJSON(p, os.Stdout)
	},
}

ConfigureGetCmd defineds 'get' subcommand

View Source
var ConfigureSandboxCmd = &cobra.Command{
	Use:   "configure-sandbox",
	Short: TRCLI("cli.configure_sandbox.summary"),
	Long:  TRCLI("cli.configure_sandbox.description"),
	RunE: func(cmd *cobra.Command, args []string) error {
		pn := getSpecifiedSandboxProfileName()

		var p *profile
		var err error
		if configureSandboxAuthKeyID == "" || configureSandboxAuthKey == "" || configureSandboxEmail == "" || configureSandboxPassword == "" {
			p, err = collectSandboxProfileInfo(pn, configureSandboxRegisterPaymentMethod)
			if err != nil {
				cmd.SilenceUsage = true
				return err
			}
			ep := getSpecifiedSandboxEndpoint(p.CoverageType)
			p.Endpoint = &ep
		} else {
			ct := getSpecifiedCoverageType()
			ep := getSpecifiedSandboxEndpoint(ct)
			p = &profile{
				Sandbox:               true,
				CoverageType:          ct,
				Endpoint:              &ep,
				AuthKeyID:             &configureSandboxAuthKeyID,
				AuthKey:               &configureSandboxAuthKey,
				Email:                 &configureSandboxEmail,
				Password:              &configureSandboxPassword,
				RegisterPaymentMethod: configureSandboxRegisterPaymentMethod,
			}
		}

		_, err = sandboxInit(p)
		if err != nil {
			cmd.SilenceUsage = true
			return err
		}

		p.AuthKeyID = nil
		p.AuthKey = nil

		err = saveProfile(pn, p, configureSandboxOverwrite)
		if err != nil {
			cmd.SilenceUsage = true
			return err
		}

		return nil
	},
}

ConfigureSandboxCmd defines 'configure-sandbox' subcommand

View Source
var SelfUpdateCmd = &cobra.Command{
	Use:   "self-update",
	Short: TRCLI("cli.self_update.summary"),
	Long:  TRCLI("cli.self_update.description"),
	RunE: func(cmd *cobra.Command, args []string) error {
		latestReleased, err := retrieveLatestReleasedFromGitHub()
		if err != nil {
			return err
		}

		if !isNewerThanCurrentVersion(latestReleased.TagName) {
			fmt.Printf(TRCLI("cli.self_update.already_latest"), version)
			return nil
		}

		fmt.Printf(TRCLI("cli.self_update.prompt_confirmation"), latestReleased.TagName, strings.TrimPrefix(latestReleased.TagName, "v"), runtime.GOARCH)
		yes, err := readDefaultNoConfirmationPrompt()
		if err != nil {
			return err
		}
		if !yes {
			return errors.New("abort")
		}

		downloaded, err := downloadExecutableBinary(latestReleased.TagName, latestReleased.Assets)
		if err != nil {
			return err
		}

		err = swapExecutableBinaryFile(downloaded)
		if err != nil {
			return err
		}

		fmt.Println(TRCLI("cli.self_update.update_finished"))
		return nil
	},
}
View Source
var Test500Cmd = &cobra.Command{
	Use:   "500",
	Short: TRCLI("cli.test._500.summary"),
	Long:  TRCLI("cli.test._500.description"),
	RunE: func(cmd *cobra.Command, args []string) error {
		opt := &apiClientOptions{
			BasePath: "/",
			Language: getSelectedLanguage(),
		}

		ac := newAPIClient(opt)
		if v := os.Getenv("SORACOM_VERBOSE"); v != "" {
			ac.SetVerbose(true)
		}

		param := &apiParams{
			method:      "POST",
			path:        "500",
			contentType: "application/json",
			body:        `{"expect":"500 Internal Server Error"}`,
		}

		_, err := ac.callAPI(param)

		return err
	},
}

Test500Cmd defines 'test 500' subcommand

View Source
var TestCmd = &cobra.Command{
	Use:    "test",
	Short:  TRCLI("cli.test.summary"),
	Long:   TRCLI("cli.test.description"),
	Hidden: true,
}

TestCmd defines 'test' subcommand

View Source
var UnconfigureCmd = &cobra.Command{
	Use:   "unconfigure",
	Short: TRCLI("cli.unconfigure.summary"),
	Long:  TRCLI("cli.unconfigure.description"),
	RunE: func(cmd *cobra.Command, args []string) error {
		pn := getSpecifiedProfileName()
		if pn == "" {
			pn = "default"
		}

		if confirmDeleteProfile(pn) {
			err := deleteProfile(pn)
			if err != nil {
				cmd.SilenceUsage = true
				return err
			}
		}

		return nil
	},
}

UnconfigureCmd defines 'unconfigure' subcommand

View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: TRCLI("cli.version.summary"),
	Long:  TRCLI("cli.version.description"),
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Printf("SORACOM API client v%s\n", version)
	},
}

VersionCmd defines 'version' subcommand

Functions

func TRAPI added in v0.2.4

func TRAPI(pathAndMethodAndField string) string

TRAPI ...

func TRCLI added in v0.2.4

func TRCLI(resourceID string) string

TRCLI ...

Types

type APICredentials added in v1.1.1

type APICredentials struct {
	APIKey   string
	APIToken string
}

type APICredentialsSource added in v1.1.1

type APICredentialsSource interface {
	GetAPICredentials(ac *apiClient) (*APICredentials, error)
}

Jump to

Keyboard shortcuts

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