mycli

package module
v0.0.40 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 16 Imported by: 1

README

MyCLI

Abilities

  • toml configuration file

    • allows you to configure all flags for all commands but you still need to pass the command/subcommand to run

    • see example/config.toml for example

        Example
        globalflagName="XX"
      
        [command]
            [command.subcommand]
            flagname="XX"
      
  • prefix to environment values

        Example
        c := mycli.NewCli(nil, nil)
        c.EnvPrefix = "T"
    
  • Commands

        Example
        const (
          title = "Example Title"
          description = "Example Description"
          author = "John Doe (j.doe@example.com)"
          copyRight = "(c) YYYY Example Inc.,"
        )
    
        func setupFlags(ctx context.Context) {
          var overrideLogDir string
          var port int64 = 8081
          cli := mycli.NewCli(nil, nil)
    
          cli.Title = title
          cli.Description = description
          cli.Version = version.VERSION
          cli.BuildDate = version.BUILDDATE
          cli.GitCommit = version.GITCOMMIT
          cli.GoVersion = version.GOVERSION
          cli.Author = author
          cli.Copyright = copyRight
          cli.PostGlblAction = func() error { return setLogger(overrideLogDir) }
          cli.Flgs = []mycli.CLIFlag{
             &mycli.StringFlg{Variable: &overrideLogDir, Name: "log_dir", ShortName: "ld", Usage: "override logging directory"},
          }
    
          cli.Cmds = []*mycli.CLICommand{
              {
                  Name:   "update",
                  Usage:  "check for updates",
                  Action: func() error { return update() },
                  Flags: []mycli.CLIFlag{},
              },
              {
    	       Name:   "serve",
    	       Usage:  "start server",
                   Action: func() error { return startServer(ctx, port) },
    	       Flags: []mycli.CLIFlag{
    		   &mycli.Int64Flg{Variable: &port, Name: "port", ShortName: "p", Value: 8081},
                   },
              },
          }
          err := cli.Parse()
          if err != nil {
              log.Logf(log.FATAL, "%v", err)
          }
       }
    
  • Sub Commands

        EXAMPLE
        cli := mycli.NewCli(nil, nil)
        ...
        cli.Cmds = []*mycli.CLICommand{
    	Name:  "client",
    	Usage: "use as a client",
    	SubCommands: []*mycli.CLICommand{
    		{
    			Name:      "config",
    			ShortName: "c",
    			Usage:     "use config file",
    			Action: func() { log.Println("ran clients config") },
    			Flags: []mycli.CLIFlag{
    				&mycli.Int64Flg{Variable: &t4, Name: "port", ShortName: "p", Usage: "Set Port", Value: 9111, Required: false},
    			},
    		},
    		{
    			Name:      "cmdln",
    			ShortName: "cl",
    			Usage:     "use command line",
    			Action: func() { log.Println("ran clients cmdline") },
    			Flags: []mycli.CLIFlag{
    				&mycli.Int64Flg{Variable: &t5, Name: "port", ShortName: "p", Usage: "Set Port", Value: 9111, Required: false},
    			},
    		},
    	},
        }
    
  • Global and Command Flags

       EXAMPLE
       cli := mycli.NewCli(nil, nil)
       ...
       cli.Flgs = []mycli.CLIFlag{
          &mycli.StringFlg{Variable: &overrideLogDir, Name: "log_dir", ShortName: "ld", Usage: "override logging directory"},
       }
    
  • Custom Flag types

    • toml
  • Default Flag types

    • bool
    • float64
    • int64
    • string
    • uint64
    • toml
  • Help

     Example
     $ main -h
     NAME:
       main
    
     USAGE:
       main [global options] command [command options] [arguments...]
    
     GLOBAL OPTIONS:
       -debug, -d
             flag set to debug (default false)
    
       -debugLevel, -dbglvl  int
             set debug level (default 0)
    
       -config, -c  string
             config file path
    
       -proxyhttp  string
           HTTP_PROXY  (as environment var)
             Sets http_proxy for network connections
    
       -proxyhttps  string
           HTTPS_PROXY (as environment var)
             Sets https_proxy for network connections
    
       -noproxy  string
           NO_PROXY    (as environment var)
             Sets no_proxy for network connections
    
       -log_dir, -ld  string
             override logging directory
    
     COMMANDS:
       update:    (check for updates)
    
       serve:     (start server)
           -port, -p  int
               Set port (default 8081)
    
       client:    (use as a client)
    
         Sub Commands:
           config :  use config file
             -port, -p  int
                Set Port (default 9111)
    
           cmdln :   use command line
            -port, -p  int
                Set Port (default 9111)
    
  • Flag Attributes

    • required flag

      EXAMPLE
      &mycli.Int64Flg{Variable: &t4, Name: "port", ShortName: "p", Usage: "Set Port", Value: 9111, Required: true},
      
    • option values, limit to set of valid options

      EXAMPLE
      &mycli.StringFlg{Variable: &capture, Name: "capture", ShortName: "cap", Usage: "Used to test string", Options: []string{"hello", "bye"}},
      
  • Bash Autocompletion

    use the included bash_autocomplete script along with bash-completion v2+
    Typically you will perform the following to set this up
    - Name of executable i.e. mytest
    - Copy bash_autocomplete to /etc/bash_completion.d/ using the name of the executable 
       i.e. /etc/bash_completion.d/mytest
    - chmod 777 for all to use i.e. chmod 777 /etc/bash_completion.d/mytest
    

Order of precedence on FLAG values

    1. commandline (highest priority)
    1. environment
    1. config file
    1. defaults (lowest priority)

Testing using example

    1. go run main.go -c config.toml server
    1. go run main.go -c config.toml client
    1. go run main.go -c config.toml weserve cmdln
    1. go run main.go -c config.toml weserve config

Warning on Reuse of Variables across Commands

  • When a variable is reused on different commands a warning is displayed
    • this will help inform you that the value could be overridden unexpectedly DISABLE by setting in your declaration
    • cli.DisableFlagValidation = true

Documentation

Index

Constants

View Source
const (
	UseHTTPProxy  = "Sets http_proxy for network connections"
	UseHTTPSProxy = "Sets https_proxy for network connections"
	UseNoProxy    = "Sets no_proxy for network connections"
)

Variables

View Source
var (
	ProxyHTTP              string
	ProxyHTTPS             string
	ProxyNO                string
	ProxySOCKS             string
	Debug                  bool
	DebugLevel             int64
	GenerateBashCompletion bool
	FlgValues              map[string]interface{}
)

Functions

func BashCompletionMain

func BashCompletionMain(c *CLI)

func BashCompletionSub

func BashCompletionSub(c *CLI, cm *CLICommand)

func Err

func Err(err error) bool

func FixPath

func FixPath(path string) string

func PanicErr

func PanicErr(err error)

func ResetForTesting

func ResetForTesting(usage func())

ResetForTesting clears all flag state and sets the usage function as directed. After calling ResetForTesting, parse errors in flag handling will not exit the program.

Types

type AppInfo

type AppInfo struct {
	// Version typically v0.0.1 format of version
	Version string
	// BuildDate typically set to a unix timestamp format
	BuildDate string
	// GitCommit the short git commit hash
	GitCommit string
	// GitBranch the short git commit hash
	GitBranch string
	// GoVersion go version application was built upon
	GoVersion string
	// Title plain text name for the application
	Title string
	// Description detailed purpose of the application
	Description string
	Usage       string
	Author      string
	// Copyright typically company or developer copyright i.e. [ (c) 4-digit-year company/user ]
	Copyright string
}

AppInfo supplies all pertinent information for the application

type BoolFlg

type BoolFlg struct {
	Variable      interface{}
	Name          string
	ShortName     string
	Usage         string
	EnvVar        string
	EnvVarExclude bool
	Value         bool
	CommaSepVal   bool
	Required      bool
	Action        interface{}
	Options       []bool
	Hidden        bool
	// contains filtered or unexported fields
}

func (*BoolFlg) AdjustValue added in v0.0.34

func (c *BoolFlg) AdjustValue(cmd string, flgValues map[string]interface{})

func (*BoolFlg) BuildFlag

func (c *BoolFlg) BuildFlag(flgSet *flag.FlagSet, varMap map[string][]FieldPtr, flgValues map[string]interface{})

func (*BoolFlg) GAction

func (c *BoolFlg) GAction() interface{}

func (*BoolFlg) GCommaSepVal

func (c *BoolFlg) GCommaSepVal() bool

func (*BoolFlg) GCommand

func (c *BoolFlg) GCommand(cmd string)

func (*BoolFlg) GEnvVar

func (c *BoolFlg) GEnvVar() string

func (*BoolFlg) GEnvVarExclude

func (c *BoolFlg) GEnvVarExclude() bool

func (*BoolFlg) GHidden

func (c *BoolFlg) GHidden() bool

func (*BoolFlg) GName

func (c *BoolFlg) GName() string

func (*BoolFlg) GOptions

func (c *BoolFlg) GOptions() interface{}

func (*BoolFlg) GRequired

func (c *BoolFlg) GRequired() bool

func (*BoolFlg) GShortName

func (c *BoolFlg) GShortName() string

func (*BoolFlg) GUsage

func (c *BoolFlg) GUsage() string

func (*BoolFlg) GValue

func (c *BoolFlg) GValue() interface{}

func (*BoolFlg) GVariable

func (c *BoolFlg) GVariable() interface{}

func (*BoolFlg) GVariableToString

func (c *BoolFlg) GVariableToString() string

func (*BoolFlg) Kind

func (c *BoolFlg) Kind() error

Kind check if this is NOT of type pointer or Nil and return error

func (*BoolFlg) RequiredAndNotSet

func (c *BoolFlg) RequiredAndNotSet() bool

func (*BoolFlg) RetrieveConfigValue

func (c *BoolFlg) RetrieveConfigValue(val *TomlWrapper, name string) error

func (*BoolFlg) RetrieveEnvValue

func (c *BoolFlg) RetrieveEnvValue() error

func (*BoolFlg) SetDebug

func (c *BoolFlg) SetDebug(dbg bool)

func (*BoolFlg) SetDebugLevel added in v0.0.15

func (c *BoolFlg) SetDebugLevel(lvl int64)

func (*BoolFlg) SetEnvVar

func (c *BoolFlg) SetEnvVar(envVar string)

func (*BoolFlg) UnquotedUsage

func (c *BoolFlg) UnquotedUsage() string

func (*BoolFlg) ValidValue

func (c *BoolFlg) ValidValue() bool

func (*BoolFlg) ValueAsString

func (c *BoolFlg) ValueAsString() string

type CLI

type CLI struct {
	*AppInfo
	// Default Flags for Reference Only these are in Flgs for actual use
	DefFlags []CLIFlag
	// Flgs location to set all global flags
	Flgs []CLIFlag
	// Cmds global commands your application supports
	Cmds []*CLICommand
	// PostGlblAction runs an action after processing Global flags
	PostGlblAction interface{}
	// MainAction this is a default if no Command is specified when the application is run
	MainAction interface{}

	// BashCompletion typically set to the built in default of mycli.BashCompletionMain
	BashCompletion interface{}
	// VersionPrint an overridable function that prints by default the set Version, BuildDate, GitCommit, GoVersion
	VersionPrint interface{}

	Writer io.Writer
	// DisableEnvVars disable all environment variables
	DisableEnvVars bool
	// EnvPrefix a prefix you can define to use on Environment Variables for values used in the application default "T"
	EnvPrefix string
	// TestMode reserved for internal testing
	TestMode bool

	DisableFlagValidation bool
	ShowDuration          bool
	// contains filtered or unexported fields
}

CLI command line struct

func NewCli

func NewCli(f FatalAdapter, u UsageAdapter) *CLI

NewCli creates an instance of the CLI application

func (*CLI) Command

func (c *CLI) Command(name string) *CLICommand

func (*CLI) DebugLevel added in v0.0.25

func (c *CLI) DebugLevel() int64

func (*CLI) Flag

func (c *CLI) Flag(flgName string, flgs []CLIFlag) CLIFlag

func (*CLI) GetHttpProxy added in v0.0.25

func (c *CLI) GetHttpProxy() string

func (*CLI) GetHttpsProxy added in v0.0.25

func (c *CLI) GetHttpsProxy() string

func (*CLI) GetNoProxy added in v0.0.25

func (c *CLI) GetNoProxy() string

func (*CLI) Help

func (c *CLI) Help() bool

func (*CLI) IsDebug added in v0.0.25

func (c *CLI) IsDebug() bool

func (*CLI) IsProxySet added in v0.0.25

func (c *CLI) IsProxySet() bool

func (*CLI) Parse

func (c *CLI) Parse() error

func (*CLI) SetupEnvVars

func (c *CLI) SetupEnvVars()

SetupEnvVars Loop through all Flags and Command Flags then set EnvVars based on Prefix and NAME or Override

func (*CLI) ValidateFlgKind

func (c *CLI) ValidateFlgKind() error

ValidateFlgKind ensure these are of type pointer or nil otherwise error

func (*CLI) ValidateValues

func (c *CLI) ValidateValues(commands bool) error

type CLICommand

type CLICommand struct {
	// Name of the command and passed for use
	Name string
	// ShortName used for execution but provides a shorter name
	ShortName string
	// Usage definition of what this command accomplishes
	Usage string
	// Variable used to process a file full of configurations see custom/flgtoml.go as an example used with Hidden:true
	Variable interface{}
	// Value unused
	Value interface{}
	// PreAction perform some action prior to the Action defined
	PreAction interface{}
	// Action main action to perform for this Command
	Action interface{}
	// PostAction perform some action after the main Action
	PostAction interface{}
	// Flags are command flags local to this command
	Flags []CLIFlag
	// FS reserved for internal use
	FS *flag.FlagSet
	// BashCompletion should be set to mycli.BashCompletionSub for sub command completion
	BashCompletion interface{}

	// Hidden stops from showing in help
	Hidden bool

	// SubCommands ability to create sub commands of a top command
	SubCommands Commands
	// contains filtered or unexported fields
}

func (*CLICommand) RetrieveConfigValue

func (c *CLICommand) RetrieveConfigValue(val *TomlWrapper, name string) error

RetrieveConfigValue TODO Convert this section to a JSON string

type CLIFlag

type CLIFlag interface {
	GAction() interface{}
	GEnvVar() string
	GEnvVarExclude() bool
	GHidden() bool
	GName() string
	GOptions() interface{}
	GRequired() bool
	GShortName() string
	GUsage() string
	GValue() interface{}
	GVariable() interface{}
	GVariableToString() string
	Kind() error
	RetrieveEnvValue() error
	RetrieveConfigValue(val *TomlWrapper, name string) error
	RequiredAndNotSet() bool
	SetDebug(bool)
	SetDebugLevel(int64)
	SetEnvVar(string)
	ValidValue() bool
	GCommaSepVal() bool
	ValueAsString() string
	GCommand(string)
	BuildFlag(*flag.FlagSet, map[string][]FieldPtr, map[string]interface{})
	UnquotedUsage() string
	AdjustValue(cmd string, flgValues map[string]interface{})
}

type Commands

type Commands []*CLICommand

type Fatal

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

func (*Fatal) PrintNotice

func (f *Fatal) PrintNotice(name string)

func (*Fatal) PrintNoticeSubCmd

func (f *Fatal) PrintNoticeSubCmd(name, cmd string)

type FatalAdapter

type FatalAdapter interface {
	PrintNotice(string)
	PrintNoticeSubCmd(string, string)
}

type FieldPtr added in v0.0.28

type FieldPtr struct {
	FieldName string
	Address   string
	Command   string
	Value     interface{}
	ValType   string
}

type Float64Flg

type Float64Flg struct {
	Variable      interface{}
	Name          string
	ShortName     string
	Usage         string
	EnvVar        string
	EnvVarExclude bool
	Value         float64
	CommaSepVal   bool
	Required      bool
	Action        interface{}
	Options       []float64
	Hidden        bool
	// contains filtered or unexported fields
}

func (*Float64Flg) AdjustValue added in v0.0.34

func (c *Float64Flg) AdjustValue(cmd string, flgValues map[string]interface{})

func (*Float64Flg) BuildFlag

func (c *Float64Flg) BuildFlag(flgSet *flag.FlagSet, varMap map[string][]FieldPtr, flgValues map[string]interface{})

func (*Float64Flg) GAction

func (c *Float64Flg) GAction() interface{}

func (*Float64Flg) GCommaSepVal

func (c *Float64Flg) GCommaSepVal() bool

func (*Float64Flg) GCommand

func (c *Float64Flg) GCommand(cmd string)

func (*Float64Flg) GEnvVar

func (c *Float64Flg) GEnvVar() string

func (*Float64Flg) GEnvVarExclude

func (c *Float64Flg) GEnvVarExclude() bool

func (*Float64Flg) GHidden

func (c *Float64Flg) GHidden() bool

func (*Float64Flg) GName

func (c *Float64Flg) GName() string

func (*Float64Flg) GOptions

func (c *Float64Flg) GOptions() interface{}

func (*Float64Flg) GRequired

func (c *Float64Flg) GRequired() bool

func (*Float64Flg) GShortName

func (c *Float64Flg) GShortName() string

func (*Float64Flg) GUsage

func (c *Float64Flg) GUsage() string

func (*Float64Flg) GValue

func (c *Float64Flg) GValue() interface{}

func (*Float64Flg) GVariable

func (c *Float64Flg) GVariable() interface{}

func (*Float64Flg) GVariableToString

func (c *Float64Flg) GVariableToString() string

func (*Float64Flg) Kind

func (c *Float64Flg) Kind() error

Kind check if this is NOT of type pointer or Nil and return error

func (*Float64Flg) RequiredAndNotSet

func (c *Float64Flg) RequiredAndNotSet() bool

func (*Float64Flg) RetrieveConfigValue

func (c *Float64Flg) RetrieveConfigValue(val *TomlWrapper, name string) error

func (*Float64Flg) RetrieveEnvValue

func (c *Float64Flg) RetrieveEnvValue() error

func (*Float64Flg) SetDebug

func (c *Float64Flg) SetDebug(dbg bool)

func (*Float64Flg) SetDebugLevel added in v0.0.15

func (c *Float64Flg) SetDebugLevel(lvl int64)

func (*Float64Flg) SetEnvVar

func (c *Float64Flg) SetEnvVar(envVar string)

func (*Float64Flg) UnquotedUsage

func (c *Float64Flg) UnquotedUsage() string

func (*Float64Flg) ValidValue

func (c *Float64Flg) ValidValue() bool

func (*Float64Flg) ValueAsString

func (c *Float64Flg) ValueAsString() string

type Int64Flg

type Int64Flg struct {
	Variable      interface{}
	Name          string
	ShortName     string
	Usage         string
	EnvVar        string
	EnvVarExclude bool
	Value         int64
	CommaSepVal   bool
	Required      bool
	Action        interface{}
	Options       []int64
	Hidden        bool
	// contains filtered or unexported fields
}

func (*Int64Flg) AdjustValue added in v0.0.34

func (c *Int64Flg) AdjustValue(cmd string, flgValues map[string]interface{})

func (*Int64Flg) BuildFlag

func (c *Int64Flg) BuildFlag(flgSet *flag.FlagSet, varMap map[string][]FieldPtr, flgValues map[string]interface{})

func (*Int64Flg) GAction

func (c *Int64Flg) GAction() interface{}

func (*Int64Flg) GCommaSepVal

func (c *Int64Flg) GCommaSepVal() bool

func (*Int64Flg) GCommand

func (c *Int64Flg) GCommand(cmd string)

func (*Int64Flg) GEnvVar

func (c *Int64Flg) GEnvVar() string

func (*Int64Flg) GEnvVarExclude

func (c *Int64Flg) GEnvVarExclude() bool

func (*Int64Flg) GHidden

func (c *Int64Flg) GHidden() bool

func (*Int64Flg) GName

func (c *Int64Flg) GName() string

func (*Int64Flg) GOptions

func (c *Int64Flg) GOptions() interface{}

func (*Int64Flg) GRequired

func (c *Int64Flg) GRequired() bool

func (*Int64Flg) GShortName

func (c *Int64Flg) GShortName() string

func (*Int64Flg) GUsage

func (c *Int64Flg) GUsage() string

func (*Int64Flg) GValue

func (c *Int64Flg) GValue() interface{}

func (*Int64Flg) GVariable

func (c *Int64Flg) GVariable() interface{}

func (*Int64Flg) GVariableToString

func (c *Int64Flg) GVariableToString() string

func (*Int64Flg) Kind

func (c *Int64Flg) Kind() error

Kind check if this is NOT of type pointer or Nil and return error

func (*Int64Flg) RequiredAndNotSet

func (c *Int64Flg) RequiredAndNotSet() bool

func (*Int64Flg) RetrieveConfigValue

func (c *Int64Flg) RetrieveConfigValue(val *TomlWrapper, name string) error

func (*Int64Flg) RetrieveEnvValue

func (c *Int64Flg) RetrieveEnvValue() error

func (*Int64Flg) SetDebug

func (c *Int64Flg) SetDebug(dbg bool)

func (*Int64Flg) SetDebugLevel added in v0.0.15

func (c *Int64Flg) SetDebugLevel(lvl int64)

func (*Int64Flg) SetEnvVar

func (c *Int64Flg) SetEnvVar(envVar string)

func (*Int64Flg) UnquotedUsage

func (c *Int64Flg) UnquotedUsage() string

func (*Int64Flg) ValidValue

func (c *Int64Flg) ValidValue() bool

func (*Int64Flg) ValueAsString

func (c *Int64Flg) ValueAsString() string

type InvalidObjectError

type InvalidObjectError struct {
	Type reflect.Type
	Name string
}

func (*InvalidObjectError) Error

func (e *InvalidObjectError) Error() string

type InvalidValueError

type InvalidValueError struct {
	Field   string
	Value   string
	Options interface{}
}

func (*InvalidValueError) Error

func (e *InvalidValueError) Error() string

type StringFlg

type StringFlg struct {
	Variable      interface{}
	Name          string
	ShortName     string
	Usage         string
	EnvVar        string
	EnvVarExclude bool
	Value         string
	CommaSepVal   bool
	Required      bool
	Action        interface{}
	Options       []string
	Hidden        bool
	// contains filtered or unexported fields
}

func (*StringFlg) AdjustValue added in v0.0.34

func (c *StringFlg) AdjustValue(cmd string, flgValues map[string]interface{})

func (*StringFlg) BuildFlag

func (c *StringFlg) BuildFlag(flgSet *flag.FlagSet, varMap map[string][]FieldPtr, flgValues map[string]interface{})

func (*StringFlg) GAction

func (c *StringFlg) GAction() interface{}

func (*StringFlg) GCommaSepVal

func (c *StringFlg) GCommaSepVal() bool

func (*StringFlg) GCommand

func (c *StringFlg) GCommand(cmd string)

func (*StringFlg) GEnvVar

func (c *StringFlg) GEnvVar() string

func (*StringFlg) GEnvVarExclude

func (c *StringFlg) GEnvVarExclude() bool

func (*StringFlg) GHidden

func (c *StringFlg) GHidden() bool

func (*StringFlg) GName

func (c *StringFlg) GName() string

func (*StringFlg) GOptions

func (c *StringFlg) GOptions() interface{}

func (*StringFlg) GRequired

func (c *StringFlg) GRequired() bool

func (*StringFlg) GShortName

func (c *StringFlg) GShortName() string

func (*StringFlg) GUsage

func (c *StringFlg) GUsage() string

func (*StringFlg) GValue

func (c *StringFlg) GValue() interface{}

func (*StringFlg) GVariable

func (c *StringFlg) GVariable() interface{}

func (*StringFlg) GVariableToString

func (c *StringFlg) GVariableToString() string

func (*StringFlg) Kind

func (c *StringFlg) Kind() error

Kind check if this is NOT of type pointer or Nil and return error

func (*StringFlg) RequiredAndNotSet

func (c *StringFlg) RequiredAndNotSet() bool

func (*StringFlg) RetrieveConfigValue

func (c *StringFlg) RetrieveConfigValue(val *TomlWrapper, name string) error

func (*StringFlg) RetrieveEnvValue

func (c *StringFlg) RetrieveEnvValue() error

func (*StringFlg) SetDebug

func (c *StringFlg) SetDebug(dbg bool)

func (*StringFlg) SetDebugLevel added in v0.0.15

func (c *StringFlg) SetDebugLevel(lvl int64)

func (*StringFlg) SetEnvVar

func (c *StringFlg) SetEnvVar(envVar string)

func (*StringFlg) UnquotedUsage

func (c *StringFlg) UnquotedUsage() string

func (*StringFlg) ValidValue

func (c *StringFlg) ValidValue() bool

func (*StringFlg) ValueAsString

func (c *StringFlg) ValueAsString() string

type StringList

type StringList []string

func (*StringList) Set

func (s *StringList) Set(value string) error

func (*StringList) String

func (s *StringList) String() string

Implement the flag.Value interface

func (*StringList) UnquotedUsage

func (c *StringList) UnquotedUsage() string

type TomlWrapper added in v0.0.27

type TomlWrapper struct {
	Map map[string]interface{}
}

func Toml added in v0.0.27

func Toml() *TomlWrapper

func (*TomlWrapper) Get added in v0.0.27

func (t *TomlWrapper) Get(key string) interface{}

func (*TomlWrapper) GetPath added in v0.0.27

func (t *TomlWrapper) GetPath(keys []string) interface{}

func (*TomlWrapper) Has added in v0.0.27

func (t *TomlWrapper) Has(key string) bool

func (*TomlWrapper) HasPath added in v0.0.27

func (t *TomlWrapper) HasPath(keys []string) bool

func (*TomlWrapper) LoadToml added in v0.0.27

func (t *TomlWrapper) LoadToml(path string) error

type Uint64Flg

type Uint64Flg struct {
	Variable      interface{}
	Name          string
	ShortName     string
	Usage         string
	EnvVar        string
	EnvVarExclude bool
	Value         uint64
	CommaSepVal   bool
	Required      bool
	Action        interface{}
	Options       []uint64
	Hidden        bool
	// contains filtered or unexported fields
}

func (*Uint64Flg) AdjustValue added in v0.0.34

func (c *Uint64Flg) AdjustValue(cmd string, flgValues map[string]interface{})

func (*Uint64Flg) BuildFlag

func (c *Uint64Flg) BuildFlag(flgSet *flag.FlagSet, varMap map[string][]FieldPtr, flgValues map[string]interface{})

func (*Uint64Flg) GAction

func (c *Uint64Flg) GAction() interface{}

func (*Uint64Flg) GCommaSepVal

func (c *Uint64Flg) GCommaSepVal() bool

func (*Uint64Flg) GCommand

func (c *Uint64Flg) GCommand(cmd string)

func (*Uint64Flg) GEnvVar

func (c *Uint64Flg) GEnvVar() string

func (*Uint64Flg) GEnvVarExclude

func (c *Uint64Flg) GEnvVarExclude() bool

func (*Uint64Flg) GHidden

func (c *Uint64Flg) GHidden() bool

func (*Uint64Flg) GName

func (c *Uint64Flg) GName() string

func (*Uint64Flg) GOptions

func (c *Uint64Flg) GOptions() interface{}

func (*Uint64Flg) GRequired

func (c *Uint64Flg) GRequired() bool

func (*Uint64Flg) GShortName

func (c *Uint64Flg) GShortName() string

func (*Uint64Flg) GUsage

func (c *Uint64Flg) GUsage() string

func (*Uint64Flg) GValue

func (c *Uint64Flg) GValue() interface{}

func (*Uint64Flg) GVariable

func (c *Uint64Flg) GVariable() interface{}

func (*Uint64Flg) GVariableToString

func (c *Uint64Flg) GVariableToString() string

func (*Uint64Flg) Kind

func (c *Uint64Flg) Kind() error

Kind check if this is NOT of type pointer or Nil and return error

func (*Uint64Flg) RequiredAndNotSet

func (c *Uint64Flg) RequiredAndNotSet() bool

func (*Uint64Flg) RetrieveConfigValue

func (c *Uint64Flg) RetrieveConfigValue(val *TomlWrapper, name string) error

func (*Uint64Flg) RetrieveEnvValue

func (c *Uint64Flg) RetrieveEnvValue() error

func (*Uint64Flg) SetDebug

func (c *Uint64Flg) SetDebug(dbg bool)

func (*Uint64Flg) SetDebugLevel added in v0.0.15

func (c *Uint64Flg) SetDebugLevel(lvl int64)

func (*Uint64Flg) SetEnvVar

func (c *Uint64Flg) SetEnvVar(envVar string)

func (*Uint64Flg) UnquotedUsage

func (c *Uint64Flg) UnquotedUsage() string

func (*Uint64Flg) ValidValue

func (c *Uint64Flg) ValidValue() bool

func (*Uint64Flg) ValueAsString

func (c *Uint64Flg) ValueAsString() string

type UsageAdapter

type UsageAdapter interface {
	UsageText(*CLICommand)
}

type UsageDisplay

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

func (*UsageDisplay) UsageText

func (u *UsageDisplay) UsageText(cmd *CLICommand)

type VarFlg

type VarFlg struct {
	Variable      interface{}
	Name          string
	ShortName     string
	Usage         string
	EnvVar        string
	EnvVarExclude bool
	Value         StringList
	CommaSepVal   bool
	Required      bool
	Action        interface{}
	Options       []StringList
	Hidden        bool
	// contains filtered or unexported fields
}

func (*VarFlg) AdjustValue added in v0.0.34

func (c *VarFlg) AdjustValue(cmd string, flgValues map[string]interface{})

func (*VarFlg) BuildFlag

func (c *VarFlg) BuildFlag(flgSet *flag.FlagSet, varMap map[string][]FieldPtr, flgValues map[string]interface{})

func (*VarFlg) GAction

func (c *VarFlg) GAction() interface{}

func (*VarFlg) GCommaSepVal

func (c *VarFlg) GCommaSepVal() bool

func (*VarFlg) GCommand

func (c *VarFlg) GCommand(cmd string)

func (*VarFlg) GEnvVar

func (c *VarFlg) GEnvVar() string

func (*VarFlg) GEnvVarExclude

func (c *VarFlg) GEnvVarExclude() bool

func (*VarFlg) GHidden

func (c *VarFlg) GHidden() bool

func (*VarFlg) GName

func (c *VarFlg) GName() string

func (*VarFlg) GOptions

func (c *VarFlg) GOptions() interface{}

func (*VarFlg) GRequired

func (c *VarFlg) GRequired() bool

func (*VarFlg) GShortName

func (c *VarFlg) GShortName() string

func (*VarFlg) GUsage

func (c *VarFlg) GUsage() string

func (*VarFlg) GValue

func (c *VarFlg) GValue() interface{}

func (*VarFlg) GVariable

func (c *VarFlg) GVariable() interface{}

func (*VarFlg) GVariableToString

func (c *VarFlg) GVariableToString() string

func (*VarFlg) Kind

func (c *VarFlg) Kind() error

Kind check if this is NOT of type pointer or Nil and return error

func (*VarFlg) RequiredAndNotSet

func (c *VarFlg) RequiredAndNotSet() bool

func (*VarFlg) RetrieveConfigValue

func (c *VarFlg) RetrieveConfigValue(val *TomlWrapper, name string) error

func (*VarFlg) RetrieveConfigValueOrig added in v0.0.40

func (c *VarFlg) RetrieveConfigValueOrig(val map[string]interface{}, name string) error

func (*VarFlg) RetrieveEnvValue

func (c *VarFlg) RetrieveEnvValue() error

func (*VarFlg) SetDebug

func (c *VarFlg) SetDebug(dbg bool)

func (*VarFlg) SetDebugLevel added in v0.0.15

func (c *VarFlg) SetDebugLevel(lvl int64)

func (*VarFlg) SetEnvVar

func (c *VarFlg) SetEnvVar(envVar string)

func (*VarFlg) UnquotedUsage

func (c *VarFlg) UnquotedUsage() string

func (*VarFlg) ValidValue

func (c *VarFlg) ValidValue() bool

func (*VarFlg) ValueAsString

func (c *VarFlg) ValueAsString() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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