command

package
Version: v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2021 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "dice",
	Short: "Dice commandline client",
	Long: `
      _/_/_/   	_/_/_/ 	  _/_/_/  _/_/_/_/
     _/	   _/  	 _/    _/      	 _/
    _/ 	  _/   	_/    _/       	_/_/_/
   _/  	 _/    _/    _/	       _/
  _/_/_/    _/_/_/    _/_/_/  _/_/_/_/
`,
	SilenceUsage: true,
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		ctx.Debug = debugMode
		logrus.SetOutput(os.Stdout)
		defer func() {
			cmd.SilenceErrors = true
		}()

		httpOption := []httpclient.OpOption{httpclient.WithCompleteRedirect()}
		if debugMode {
			logrus.SetLevel(logrus.DebugLevel)
			httpOption = append(httpOption, httpclient.WithDebug(os.Stdout))
		} else {
			httpOption = append(httpOption, httpclient.WithLoadingPrint(""))
		}
		if strings.HasPrefix(host, "https") {
			httpOption = append(httpOption, httpclient.WithHTTPS())
		}
		ctx.HttpClient = httpclient.New(httpOption...)

		if strings.Contains(loginWhiteListCmds, strings.Split(cmd.Use, " ")[0]) {
			return nil
		}

		sessionInfos, err := ensureSessionInfos()
		if err != nil {
			err = fmt.Errorf(color_str.Red("✗ ") + err.Error())
			fmt.Println(err)
			return err
		}
		ctx.Sessions = sessionInfos

		return nil
	},
}

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

type Arg

type Arg interface {
	Validate(idx int, src string) error
	// return (converted_value, type_string)
	Convert(src string) interface{}
	// return converted_value_type_string
	ConvertType() string
	GetName() string
	// set name
	Name(name string) Arg
	// is an optional arg?
	Option() Arg

	IsOption() bool
}

type BoolFlag

type BoolFlag struct {
	Short        string
	Name         string
	Doc          string
	DefaultValue bool
}

func (BoolFlag) DefaultV

func (v BoolFlag) DefaultV() string

func (BoolFlag) Flag

func (BoolFlag) Flag()

type Command

type Command struct {
	// default: rootcmd
	ParentName string
	Name       string
	ShortHelp  string
	LongHelp   string
	Example    string
	// dont show up in list of cmds
	Hidden         bool
	DontHideCursor bool
	/* args:
	        []Arg {
		       IPArg{},
		       StringArg{},
		       BoolArg{},
		}
	*/
	Args []Arg
	/* flags:
	        []Flag{
	                StringFlag{"H", "host", "1.2.3.4", "doc"},
	                BoolFlag{"A", "another", true, "doc"},
	                IntFlag{"O", "ohyoyo", 1, "doc"},
		}
	*/
	Flags []Flag
	/* actually type:
		func(ctx Context, arg1 IPArg, arg2 string, arg3 bool, host string, anotherone bool, ohyoyo int) error

	`host`, `anotherone`, `ohyoyo` is generated by `Flags`
	*/
	Run interface{}
}

type CommonArg

type CommonArg struct {
	// contains filtered or unexported fields
}

func (CommonArg) GetName

func (a CommonArg) GetName() string

func (CommonArg) IsOption

func (a CommonArg) IsOption() bool

type Context

type Context struct {
	Sessions           map[string]status.StatusInfo
	CurrentOpenApiHost string
	Debug              bool
	Token              string // uc token
	HttpClient         *httpclient.HTTPClient
}

func GetContext

func GetContext() *Context

func (*Context) AvailableOrgs

func (c *Context) AvailableOrgs() ([]apistructs.OrgDTO, error)

func (*Context) CurrentOrg

func (c *Context) CurrentOrg() (apistructs.OrgDTO, error)

当前企业可能不存在,因为可能不在任何企业内,所以返回的OrgInfo可能为空

func (*Context) Delete

func (c *Context) Delete() *httpclient.Request

func (*Context) DevDiceYml

func (c *Context) DevDiceYml(checkExist bool) (string, error)

func (*Context) DiceYml

func (c *Context) DiceYml(checkExist bool) (string, error)

func (*Context) Fail

func (c *Context) Fail(format string, a ...interface{})

func (*Context) Get

func (c *Context) Get() *httpclient.Request

func (*Context) Patch

func (c *Context) Patch() *httpclient.Request

func (*Context) Post

func (c *Context) Post() *httpclient.Request

func (*Context) ProdDiceYml

func (c *Context) ProdDiceYml(checkExist bool) (string, error)

func (*Context) Put

func (c *Context) Put() *httpclient.Request

func (*Context) StagingDiceYml

func (c *Context) StagingDiceYml(checkExist bool) (string, error)

func (*Context) Succ

func (c *Context) Succ(format string, a ...interface{})

func (*Context) TestDiceYml

func (c *Context) TestDiceYml(checkExist bool) (string, error)

type Flag

type Flag interface {
	Flag()
	DefaultV() string
}

type FloatArg

type FloatArg struct {
	CommonArg
}

func (FloatArg) Convert

func (FloatArg) Convert(src string) interface{}

func (FloatArg) ConvertType

func (FloatArg) ConvertType() string

func (FloatArg) Name

func (a FloatArg) Name(name string) Arg

func (FloatArg) Option

func (a FloatArg) Option() Arg

func (FloatArg) Validate

func (FloatArg) Validate(idx int, src string) error

type FloatFlag

type FloatFlag struct {
	Short        string
	Name         string
	Doc          string
	DefaultValue float64
}

func (FloatFlag) DefaultV

func (v FloatFlag) DefaultV() string

func (FloatFlag) Flag

func (FloatFlag) Flag()

type IPArg

type IPArg struct {
	CommonArg
}

func (IPArg) Convert

func (IPArg) Convert(src string) interface{}

func (IPArg) ConvertType

func (IPArg) ConvertType() string

func (IPArg) Name

func (a IPArg) Name(name string) Arg

func (IPArg) Option

func (a IPArg) Option() Arg

func (IPArg) Validate

func (IPArg) Validate(idx int, src string) error

type IPFlag

type IPFlag struct {
	Short        string
	Name         string
	Doc          string
	DefaultValue string
}

func (IPFlag) DefaultV

func (v IPFlag) DefaultV() string

func (IPFlag) Flag

func (IPFlag) Flag()

type IntArg

type IntArg struct {
	CommonArg
}

func (IntArg) Convert

func (IntArg) Convert(src string) interface{}

func (IntArg) ConvertType

func (IntArg) ConvertType() string

func (IntArg) Name

func (a IntArg) Name(name string) Arg

func (IntArg) Option

func (a IntArg) Option() Arg

func (IntArg) Validate

func (IntArg) Validate(idx int, src string) error

type IntFlag

type IntFlag struct {
	Short        string
	Name         string
	Doc          string
	DefaultValue int
}

func (IntFlag) DefaultV

func (v IntFlag) DefaultV() string

func (IntFlag) Flag

func (IntFlag) Flag()

type Level2

type Level2 struct {
	V [2]string
}

func (Level2) DicePathAble

func (Level2) DicePathAble()

type Level2Arg

type Level2Arg struct {
	CommonArg
}

func (Level2Arg) Convert

func (Level2Arg) Convert(src string) interface{}

func (Level2Arg) ConvertType

func (Level2Arg) ConvertType() string

func (Level2Arg) Name

func (a Level2Arg) Name(name string) Arg

func (Level2Arg) Option

func (a Level2Arg) Option() Arg

func (Level2Arg) Validate

func (Level2Arg) Validate(idx int, src string) error

type Level3

type Level3 struct {
	V [3]string
}

func (Level3) DicePathAble

func (Level3) DicePathAble()

type Level3Arg

type Level3Arg struct {
	CommonArg
}

func (Level3Arg) Convert

func (Level3Arg) Convert(src string) interface{}

func (Level3Arg) ConvertType

func (Level3Arg) ConvertType() string

func (Level3Arg) Name

func (a Level3Arg) Name(name string) Arg

func (Level3Arg) Option

func (a Level3Arg) Option() Arg

func (Level3Arg) Validate

func (Level3Arg) Validate(idx int, src string) error

type Level4

type Level4 struct {
	V [4]string
}

func (Level4) DicePathAble

func (Level4) DicePathAble()

type Level4Arg

type Level4Arg struct {
	CommonArg
}

func (Level4Arg) Convert

func (Level4Arg) Convert(src string) interface{}

func (Level4Arg) ConvertType

func (Level4Arg) ConvertType() string

func (Level4Arg) Name

func (a Level4Arg) Name(name string) Arg

func (Level4Arg) Option

func (a Level4Arg) Option() Arg

func (Level4Arg) Validate

func (Level4Arg) Validate(idx int, src string) error

type Level5

type Level5 struct {
	V [5]string
}

func (Level5) DicePathAble

func (Level5) DicePathAble()

type Level5Arg

type Level5Arg struct {
	CommonArg
}

func (Level5Arg) Convert

func (Level5Arg) Convert(src string) interface{}

func (Level5Arg) ConvertType

func (Level5Arg) ConvertType() string

func (Level5Arg) Name

func (a Level5Arg) Name(name string) Arg

func (Level5Arg) Option

func (a Level5Arg) Option() Arg

func (Level5Arg) Validate

func (Level5Arg) Validate(idx int, src string) error

type Level6

type Level6 struct {
	V [6]string
}

type Level6Arg

type Level6Arg struct {
	CommonArg
}

func (Level6Arg) Convert

func (Level6Arg) Convert(src string) interface{}

func (Level6Arg) ConvertType

func (Level6Arg) ConvertType() string

func (Level6Arg) Name

func (a Level6Arg) Name(name string) Arg

func (Level6Arg) Option

func (a Level6Arg) Option() Arg

func (Level6Arg) Validate

func (Level6Arg) Validate(idx int, src string) error

type OrgInfo

type OrgInfo struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
	Desc string `json:"desc"`
}

type Release

type Release struct {
	ReleaseID   string    `json:"releaseId"`
	ReleaseName string    `json:"releaseName"`
	Labels      string    `json:"labels"`
	OrgId       int64     `json:"orgId"`       // 所属企业
	ClusterName string    `json:"clusterName"` // 所属集群
	CreatedAt   time.Time `json:"createdAt"`
	UpdatedAt   time.Time `json:"updatedAt"`
}

type ReleaseResponse

type ReleaseResponse struct {
	Success bool      `json:"success"`
	Data    []Release `json:"data"`
}

type StringArg

type StringArg struct {
	CommonArg
}

func (StringArg) Convert

func (StringArg) Convert(src string) interface{}

func (StringArg) ConvertType

func (StringArg) ConvertType() string

func (StringArg) Name

func (a StringArg) Name(name string) Arg

func (StringArg) Option

func (a StringArg) Option() Arg

func (StringArg) Validate

func (StringArg) Validate(idx int, src string) error

type StringFlag

type StringFlag struct {
	Short        string
	Name         string
	Doc          string
	DefaultValue string
}

func (StringFlag) DefaultV

func (v StringFlag) DefaultV() string

func (StringFlag) Flag

func (StringFlag) Flag()

type StringListFlag

type StringListFlag struct {
	Short        string
	Name         string
	Doc          string
	DefaultValue []string
}

func (StringListFlag) DefaultV

func (v StringListFlag) DefaultV() string

[]string{`a`, `b`}

func (StringListFlag) Flag

func (StringListFlag) Flag()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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