cli

package
v1.4.4-alpha1202-diff-... Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: AGPL-3.0 Imports: 15 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	OsArgs          []string
	DefaultCliApp   = NewCliApp()
	DefaultExitFunc = func() {
		os.Exit(1)
	}
	CliExportFuncNames []string
)
View Source
var CliExports = map[string]interface{}{
	"Args":        DefaultCliApp.Args,
	"Bool":        DefaultCliApp.Bool,
	"Have":        DefaultCliApp.Have,
	"String":      DefaultCliApp.String,
	"HTTPPacket":  DefaultCliApp.HTTPPacket,
	"YakCode":     DefaultCliApp.YakCode,
	"Text":        DefaultCliApp.Text,
	"Int":         DefaultCliApp.Int,
	"Integer":     DefaultCliApp.Integer,
	"Float":       DefaultCliApp.Float,
	"Double":      DefaultCliApp.Double,
	"YakitPlugin": DefaultCliApp.YakitPlugin,
	"StringSlice": DefaultCliApp.StringSlice,
	"IntSlice":    DefaultCliApp.IntSlice,

	"Urls": DefaultCliApp.Urls,
	"Url":  DefaultCliApp.Url,

	"Ports": DefaultCliApp.Ports,
	"Port":  DefaultCliApp.Port,

	"Hosts":   DefaultCliApp.Hosts,
	"Host":    DefaultCliApp.Host,
	"Network": DefaultCliApp.Network,
	"Net":     DefaultCliApp.Net,

	"File":          DefaultCliApp.File,
	"FileNames":     DefaultCliApp.FileNames,
	"FolderName":    DefaultCliApp.FolderName,
	"FileOrContent": DefaultCliApp.FileOrContent,
	"LineDict":      DefaultCliApp.LineDict,
	"Json":          DefaultCliApp.Json,

	"setHelp":      DefaultCliApp.SetHelp,
	"setShortName": DefaultCliApp.SetShortName,
	"setDefault":   DefaultCliApp.SetDefault,
	"setRequired":  DefaultCliApp.SetRequired,
	"setPluginEnv": DefaultCliApp.SetPluginEnv,

	"setVerboseName": DefaultCliApp.SetVerboseName,

	"setCliGroup": DefaultCliApp.SetCliGroup,

	"setYakitPayload": DefaultCliApp.SetYakitPayload,

	"setMultipleSelect": DefaultCliApp.SetMultipleSelect,

	"setSelectOption": DefaultCliApp.SetSelectOption,
	"setJsonSchema":   DefaultCliApp.SetJsonSchema,

	"UI":           DefaultCliApp.UI,
	"showGroup":    DefaultCliApp.showGroup,
	"showParams":   DefaultCliApp.showParams,
	"hideGroup":    DefaultCliApp.hideGroup,
	"hideParams":   DefaultCliApp.hideParams,
	"whenTrue":     DefaultCliApp.whenTrue,
	"whenFalse":    DefaultCliApp.whenFalse,
	"whenEqual":    DefaultCliApp.whenEqual,
	"whenNotEqual": DefaultCliApp.whenEqual,
	"whenDefault":  DefaultCliApp.whenDefault,
	"when":         DefaultCliApp.when,

	"setUISchema":           DefaultCliApp.SetUISchema,
	"uiGlobalFieldPosition": DefaultCliApp.SetUISchemaGlobalFieldPosition,
	"uiGroups":              DefaultCliApp.SetUISchemaGroups,
	"uiGroup":               DefaultCliApp.NewUISchemaGroup,
	"uiTableField":          DefaultCliApp.NewUISchemaTableField,
	"uiField":               DefaultCliApp.NewUISchemaField,
	"uiFieldPosition":       DefaultCliApp.SetUISchemaFieldPosition,
	"uiFieldComponentStyle": DefaultCliApp.SetUISchemaFieldComponentStyle,
	"uiFieldWidget":         DefaultCliApp.SetUISchemaFieldWidget,
	"uiFieldGroups":         DefaultCliApp.SetUISchemaInnerGroups,
	"uiPosDefault":          UISchemaFieldPosDefault,
	"uiPosHorizontal":       UISchemaFieldPosHorizontal,
	"uiWidgetTable":         UISchemaWidgetTable,
	"uiWidgetRadio":         UISchemaWidgetRadio,
	"uiWidgetSelect":        UISchemaWidgetSelect,
	"uiWidgetCheckbox":      UISchemaWidgetCheckbox,
	"uiWidgetTextarea":      UISchemaWidgetTextArea,
	"uiWidgetPassword":      UISchemaWidgetPassword,

	"uiWidgetUpdown": UISchemaWidgetUpdown,

	"uiWidgetFile":   UISchemaWidgetFile,
	"uiWidgetFiles":  UISchemaWidgetFiles,
	"uiWidgetFolder": UISchemaWidgetFolder,

	"SetCliName": DefaultCliApp.SetCliName,
	"SetDoc":     DefaultCliApp.SetDoc,

	"help":  DefaultCliApp.Help,
	"check": DefaultCliApp.Check,
}

Functions

func GetCliExportMapByCliApp added in v1.3.1

func GetCliExportMapByCliApp(app *CliApp) map[string]any

func InjectCliArgs

func InjectCliArgs(args []string)

Types

type CliApp added in v1.3.1

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

func NewCliApp added in v1.3.1

func NewCliApp() *CliApp

func (*CliApp) Args added in v1.3.1

func (c *CliApp) Args() []string

func (*CliApp) Bool added in v1.3.1

func (c *CliApp) Bool(name string, opts ...SetCliExtraParam) bool

Bool 获取对应名称的命令行参数,并将其转换为 bool 类型返回 Example: ``` verbose = cli.Bool("verbose") // --verbose 则为true ```

func (*CliApp) Check added in v1.3.1

func (c *CliApp) Check()

check 用于检查命令行参数是否合法,这主要检查必要参数是否传入与传入值是否合法 Example: ``` target = cli.String("target", cli.SetRequired(true)) cli.check() ```

func (*CliApp) CliCheckFactory added in v1.3.1

func (c *CliApp) CliCheckFactory(callback func()) func()

func (*CliApp) Double added in v1.3.1

func (c *CliApp) Double(name string, opts ...SetCliExtraParam) float64

Double 获取对应名称的命令行参数,并将其转换为 float 类型返回 Example: ``` percent = cli.Double("percent") // --percent 0.5 则 percent 为 0.5 ```

func (*CliApp) File added in v1.3.1

func (c *CliApp) File(name string, opts ...SetCliExtraParam) []byte

File 获取对应名称的命令行参数,根据其传入的值读取其对应文件内容并返回 []byte 类型 Example: ``` file = cli.File("file") // --file /etc/passwd 则 file 为 /etc/passwd 文件中的内容 ```

func (*CliApp) FileNames added in v1.3.1

func (c *CliApp) FileNames(name string, opts ...SetCliExtraParam) []string

FileNames 获取对应名称的命令行参数,获得选中的所有文件路径,并返回 []string 类型 Example: ``` file = cli.FileNames("file") // --file /etc/passwd,/etc/hosts 则 file 为 ["/etc/passwd", "/etc/hosts"] ```

func (*CliApp) FileOrContent added in v1.3.1

func (c *CliApp) FileOrContent(name string, opts ...SetCliExtraParam) []byte

FileOrContent 获取对应名称的命令行参数 根据其传入的值尝试读取其对应文件内容,如果无法读取则直接返回,最后返回 []byte 类型 Example: ``` foc = cli.FileOrContent("foc") // --foc /etc/passwd 则 foc 为 /etc/passwd 文件中的内容 // --file "asd" 则 file 为 "asd" ```

func (*CliApp) Float added in v1.3.1

func (c *CliApp) Float(name string, opts ...SetCliExtraParam) float64

Float 获取对应名称的命令行参数,并将其转换为 float 类型返回 Example: ``` percent = cli.Float("percent") // --percent 0.5 则 percent 为 0.5 ```

func (*CliApp) FolderName

func (c *CliApp) FolderName(name string, opts ...SetCliExtraParam) string

FolderName 获取对应名称的命令行参数,获得选中的文件夹路径,并返回 string 类型 Example: ``` folder = cli.FolderName("folder") // --folder /etc 则 folder 为 "/etc" ```

func (*CliApp) GetArgs added in v1.3.1

func (c *CliApp) GetArgs() []string

Args 获取命令行参数 Example: ``` Args = cli.Args() ```

func (*CliApp) HTTPPacket added in v1.3.1

func (c *CliApp) HTTPPacket(name string, opts ...SetCliExtraParam) string

HTTPPacket 获取对应名称的命令行参数,并将其转换为 string 类型返回 其作为一个独立脚本运行时与 cli.String 没有区别,仅在 Yakit 图形化中展示为 HTTP 报文形式 Example: ``` target = cli.HTTPPacket("target") // --target yaklang.com 则 target 为 yaklang.com ```

func (*CliApp) Have added in v1.3.1

func (c *CliApp) Have(name string, opts ...SetCliExtraParam) bool

Have 获取对应名称的命令行参数,并将其转换为 bool 类型返回 Example: ``` verbose = cli.Have("verbose") // --verbose 则为true ```

func (*CliApp) Help added in v1.3.1

func (c *CliApp) Help(w ...io.Writer)

help 用于输出命令行程序的帮助信息 Example: ``` cli.help() ```

func (*CliApp) Host added in v1.3.1

func (c *CliApp) Host(name string, opts ...SetCliExtraParam) []string

Host 获取对应名称的命令行参数,根据","切割并尝试解析CIDR网段并返回 []string 类型 Example: ``` hosts = cli.Host("hosts") // --hosts 192.168.0.0/24,172.17.0.1 则 hosts 为 192.168.0.0/24对应的所有IP和172.17.0.1 ```

func (*CliApp) Hosts added in v1.3.1

func (c *CliApp) Hosts(name string, opts ...SetCliExtraParam) []string

Hosts 获取对应名称的命令行参数,根据","切割并尝试解析CIDR网段并返回 []string 类型 Example: ``` hosts = cli.Hosts("hosts") // --hosts 192.168.0.0/24,172.17.0.1 则 hosts 为 192.168.0.0/24对应的所有IP和172.17.0.1 ```

func (*CliApp) Int added in v1.3.1

func (c *CliApp) Int(name string, opts ...SetCliExtraParam) int

Int 获取对应名称的命令行参数,并将其转换为 int 类型返回 Example: ``` port = cli.Int("port") // --port 80 则 port 为 80 ```

func (*CliApp) IntSlice

func (c *CliApp) IntSlice(name string, options ...SetCliExtraParam) []int

IntSlice 获取对应名称的命令行参数,将其字符串根据","切割并尝试转换为 int 类型返回 []int 类型 Example: ``` ports = cli.IntSlice("ports") // --ports 80,443,8080 则 ports 为 [80, 443, 8080] ```

func (*CliApp) Integer added in v1.3.1

func (c *CliApp) Integer(name string, opts ...SetCliExtraParam) int

Integer 获取对应名称的命令行参数,并将其转换为 int 类型返回 Example: ``` port = cli.Integer("port") // --port 80 则 port 为 80 ```

func (*CliApp) Json

func (c *CliApp) Json(name string, opts ...SetCliExtraParam) map[string]any

Json 获取对应名称的命令行参数, 与cli.JsonSchema一起使用以构建复杂参数 详情参考: 1. https://json-schema.org/docs 2. https://rjsf-team.github.io/react-jsonschema-form/ Example: ``` info = cli.Json("info", cli.setVerboseName("项目信息"), cli.setJsonSchema(<<<JSON {"title":"A registration form","description":"A simple form example.","type":"object","required":["firstName","lastName"],"properties":{"name":{"type":"string","title":"Name","default":"Chuck"},"password":{"type":"string","title":"Password","minLength":3},"telephone":{"type":"string","title":"Telephone","minLength":10}}} JSON,cli.setUISchema()), ) cli.check() ```

func (*CliApp) LineDict added in v1.3.1

func (c *CliApp) LineDict(name string, opts ...SetCliExtraParam) []string

LineDict 获取对应名称的命令行参数 根据其传入的值尝试读取其对应文件内容,如果无法读取则作为字符串,最后根据换行符切割,返回 []string 类型 Example: ``` dict = cli.LineDict("dict") // --dict /etc/passwd 则 dict 为 /etc/passwd 文件中的逐行的内容 // --dict "asd" 则 dict 为 ["asd"] ```

func (*CliApp) Net added in v1.3.1

func (c *CliApp) Net(name string, opts ...SetCliExtraParam) []string

Net 获取对应名称的命令行参数,根据","切割并尝试解析CIDR网段并返回 []string 类型 Example: ``` hosts = cli.Net("hosts") // --hosts 192.168.0.0/24,172.17.0.1 则 hosts 为 192.168.0.0/24对应的所有IP和172.17.0.1 ```

func (*CliApp) Network added in v1.3.1

func (c *CliApp) Network(name string, opts ...SetCliExtraParam) []string

NetWork 获取对应名称的命令行参数,根据","切割并尝试解析CIDR网段并返回 []string 类型 Example: ``` hosts = cli.NetWork("hosts") // --hosts 192.168.0.0/24,172.17.0.1 则 hosts 为 192.168.0.0/24对应的所有IP和172.17.0.1 ```

func (*CliApp) NewUISchemaField

func (c *CliApp) NewUISchemaField(name string, widthPercent float64, opts ...UISchemaFieldParams) *uiSchemaField

uiField 是一个选项参数,用于指定UISchema中的一个字段 第一个参数指定字段名 第二个参数指定这个字段所占的宽度比(0.0-1.0) 接下来可以接收零个到多个选项,用于对此字段进行其他的设置,例如内嵌分组(cli.uiFieldGroups)或者指定其部件(cli.uiFieldWidget) Example: ``` info = cli.Json(

"info",
cli.setVerboseName("项目信息"),
cli.setJsonSchema(
    <<<JSON

{"title":"A registration form","description":"A simple form example.","type":"object","required":["firstName","lastName"],"properties":{"name":{"type":"string","title":"Name","default":"Chuck"},"password":{"type":"string","title":"Password","minLength":3},"telephone":{"type":"string","title":"Telephone","minLength":10}}} JSON,

    cli.setUISchema(cli.uiGroups(
        cli.uiGroup(
            cli.uiField("name", 0.5),
            cli.uiField("password", 0.5, cli.uiFieldWidget(cli.uiWidgetPassword)),
        ),
        cli.uiGroup(cli.uiField("telephone", 1)),
    )),
),

cli.setRequired(true), ) cli.check() ```

func (*CliApp) NewUISchemaGroup

func (c *CliApp) NewUISchemaGroup(fields ...uiSchemaField) *uiSchemaGroup

uiGroup 是一个选项参数,用于指定UISchema中的一个分组,接收多个字段(cli.Field),同一分组的字段会放在一行 Example: ``` info = cli.Json(

"info",
cli.setVerboseName("项目信息"),
cli.setJsonSchema(
    <<<JSON

{"title":"A registration form","description":"A simple form example.","type":"object","required":["firstName","lastName"],"properties":{"name":{"type":"string","title":"Name","default":"Chuck"},"password":{"type":"string","title":"Password","minLength":3},"telephone":{"type":"string","title":"Telephone","minLength":10}}} JSON,

    cli.setUISchema(cli.uiGroups(
        cli.uiGroup(
            cli.uiField("name", 0.5),
            cli.uiField("password", 0.5, cli.uiFieldWidget(cli.uiWidgetPassword)),
        ),
        cli.uiGroup(cli.uiField("telephone", 1)),
    )),
),

cli.setRequired(true), ) cli.check() ```

func (*CliApp) NewUISchemaTableField

func (c *CliApp) NewUISchemaTableField(name string, width float64, opts ...UISchemaFieldParams) *uiSchemaField

uiTableField 是一个选项参数,用于指定UISchema中的一个表格字段 第一个参数指定字段名 第二个参数指定这个字段所占宽度 接下来可以接收零个到多个选项,用于对此字段进行其他的设置,例如内嵌分组(cli.uiFieldGroups)或者指定其部件(cli.uiFieldWidget) Example: ``` args = cli.Json(

"kv",
cli.setVerboseName("键值对abc"),
cli.setJsonSchema(
    <<<JSON

{"type":"object","properties":{"kvs":{"type":"array","title":"键值对","minItems":1,"items":{"properties":{"key":{"type":"string","title":"键"},"value":{"type":"string","title":"值"}},"require":["key","value"]}}}} JSON, cli.setUISchema(

cli.uiGroups(
    cli.uiGroup(
        cli.uiField("kvs", 1, cli.uiFieldWidget(cli.uiWidgetTable), cli.uiFieldGroups(
            cli.uiGroup(
                cli.uiField("items", 1, cli.uiFieldGroups(
                    cli.uiGroup(
                        cli.uiTableField("key", 100),
                        cli.uiTableField("value", 100),
                    )
                ))
            )
        ))
    )
)

),

),

cli.setRequired(true),

) cli.check() ```

func (*CliApp) Port added in v1.3.1

func (c *CliApp) Port(name string, opts ...SetCliExtraParam) []int

Port 获取对应名称的命令行参数,根据","与"-"切割并尝试解析端口并返回 []int 类型 Example: ``` ports = cli.Port("ports") // --ports 10086-10088,23333 则 ports 为 [10086, 10087, 10088, 23333] ```

func (*CliApp) Ports added in v1.3.1

func (c *CliApp) Ports(name string, opts ...SetCliExtraParam) []int

Ports 获取对应名称的命令行参数,根据","与"-"切割并尝试解析端口并返回 []int 类型 Example: ``` ports = cli.Ports("ports") // --ports 10086-10088,23333 则 ports 为 [10086, 10087, 10088, 23333] ```

func (*CliApp) SetArgs added in v1.3.1

func (c *CliApp) SetArgs(args []string)

func (*CliApp) SetCliCheckCallback

func (c *CliApp) SetCliCheckCallback(f func())

func (*CliApp) SetCliGroup added in v1.3.1

func (c *CliApp) SetCliGroup(group string) SetCliExtraParam

setCliGroup 是一个选项函数,设置参数的分组 Example: ``` cli.String("target", cli.setCliGroup("common")) cli.Int("port", cli.setCliGroup("common")) cli.Int("threads", cli.setCliGroup("request")) cli.Int("retryTimes", cli.setCliGroup("request")) ```

func (*CliApp) SetCliName added in v1.3.1

func (c *CliApp) SetCliName(name string)

SetCliName 设置此命令行程序的名称 这会在命令行输入 --help 或执行`cli.check()`后参数非法时显示 Example: ``` cli.SetCliName("example-tools") ```

func (*CliApp) SetDefault added in v1.3.1

func (c *CliApp) SetDefault(i interface{}) SetCliExtraParam

setDefault 是一个选项函数,设置参数的默认值 Example: ``` cli.String("target", cli.SetDefault("yaklang.com")) ```

func (*CliApp) SetDoc added in v1.3.1

func (c *CliApp) SetDoc(document string)

SetDoc 设置此命令行程序的文档 这会在命令行输入 --help 或执行`cli.check()`后参数非法时显示 Example: ``` cli.SetDoc("example-tools is a tool for example") ```

func (*CliApp) SetHelp added in v1.3.1

func (c *CliApp) SetHelp(i string) SetCliExtraParam

setHelp 是一个选项函数,设置参数的帮助信息 这会在命令行输入 --help 或执行`cli.check()`后参数非法时显示 Example: ``` cli.String("target", cli.SetHelp("target host or ip")) ```

func (*CliApp) SetJsonSchema

func (c *CliApp) SetJsonSchema(schema string, uis ...*UISchema) SetCliExtraParam

setJsonSchema 是一个选项参数,用于在cli.Json中使用JsonSchema构建复杂参数 详情参考: 1. https://json-schema.org/docs 2. https://rjsf-team.github.io/react-jsonschema-form/ Example: ``` info = cli.Json("info", cli.setVerboseName("项目信息"), cli.setJsonSchema(<<<JSON {"title":"A registration form","description":"A simple form example.","type":"object","required":["firstName","lastName"],"properties":{"name":{"type":"string","title":"Name","default":"Chuck"},"password":{"type":"string","title":"Password","minLength":3},"telephone":{"type":"string","title":"Telephone","minLength":10}}} JSON,cli.setUISchema()), ) cli.check() ```

func (*CliApp) SetMultipleSelect added in v1.3.1

func (c *CliApp) SetMultipleSelect(multiSelect bool) SetCliExtraParam

SetMultipleSelect 是一个选项函数,设置参数是否可以多选 此选项仅在`cli.StringSlice`中生效 Example: ``` cli.StringSlice("targets", cli.SetMultipleSelect(true)) ```

func (*CliApp) SetPluginEnv

func (c *CliApp) SetPluginEnv(key string) SetCliExtraParam

setPluginEnv 是一个选项函数,设置参数从插件环境中取值 Example: ``` cli.String("key", cli.setPluginEnv("api-key")) ```

func (*CliApp) SetRequired added in v1.3.1

func (c *CliApp) SetRequired(t bool) SetCliExtraParam

setRequired 是一个选项函数,设置参数是否必须 Example: ``` cli.String("target", cli.SetRequired(true)) ```

func (*CliApp) SetSelectOption added in v1.3.1

func (c *CliApp) SetSelectOption(name, value string) SetCliExtraParam

setSelectOption 是一个选项函数,设置参数的下拉框选项 此选项仅在`cli.StringSlice`中生效 Example: ``` cli.StringSlice("targets", cli.setSelectOption("下拉框选项", "下拉框值")) ```

func (*CliApp) SetShortName added in v1.3.1

func (c *CliApp) SetShortName(shortName string) SetCliExtraParam

setShortName 是一个选项函数,设置参数的短名称 Example: ``` cli.String("target", cli.setShortName("t")) ``` 在命令行可以使用`-t`代替`--target`

func (*CliApp) SetUISchema

func (c *CliApp) SetUISchema(params ...UISchemaParams) *UISchema

setUISchema 是一个选项参数,用于对JsonSchema设置的参数进行图形化的调整 详情参考: 1. https://json-schema.org/docs 2. https://rjsf-team.github.io/react-jsonschema-form/ 3. https://rjsf-team.github.io/react-jsonschema-form/docs/api-reference/uiSchema/ Example: ``` info = cli.Json(

"info",
cli.setVerboseName("项目信息"),
cli.setJsonSchema(
    <<<JSON

{"title":"A registration form","description":"A simple form example.","type":"object","required":["firstName","lastName"],"properties":{"name":{"type":"string","title":"Name","default":"Chuck"},"password":{"type":"string","title":"Password","minLength":3},"telephone":{"type":"string","title":"Telephone","minLength":10}}} JSON,

    cli.setUISchema(cli.uiGroups(
        cli.uiGroup(
            cli.uiField("name", 0.5),
            cli.uiField("password", 0.5, cli.uiFieldWidget(cli.uiWidgetPassword)),
        ),
        cli.uiGroup(cli.uiField("telephone", 1)),
    )),
),

cli.setRequired(true), ) cli.check() ```

func (*CliApp) SetUISchemaFieldComponentStyle

func (c *CliApp) SetUISchemaFieldComponentStyle(css map[string]any) UISchemaFieldParams

uiFieldComponentStyle 是一个选项参数,用于指定UISchema中的CSS样式 Example: ``` info = cli.Json(

"info",
cli.setVerboseName("项目信息"),
cli.setJsonSchema(
    <<<JSON

{"title":"A registration form","description":"A simple form example.","type":"object","required":["firstName","lastName"],"properties":{"name":{"type":"string","title":"Name","default":"Chuck"},"password":{"type":"string","title":"Password","minLength":3},"telephone":{"type":"string","title":"Telephone","minLength":10}}} JSON,

    cli.setUISchema(cli.uiGroups(
        cli.uiGroup(
            cli.uiField("name", 0.5),
            cli.uiField("password", 0.5, cli.uiFieldWidget(cli.uiWidgetPassword)),
        ),
        cli.uiGroup(cli.uiField(
            "telephone",
            1,
            cli.uiFieldComponentStyle({"width": "50%"}),
        )),
    )),
),

cli.setRequired(true), ) cli.check() ```

func (*CliApp) SetUISchemaFieldPosition

func (c *CliApp) SetUISchemaFieldPosition(position UISchemaFieldClassName) UISchemaFieldParams

uiFieldPosition 是一个选项参数,用于指定UISchema中的字段位置,默认为垂直排列 Example: ``` info = cli.Json(

"info",
cli.setVerboseName("项目信息"),
cli.setJsonSchema(
    <<<JSON

{"title":"A registration form","description":"A simple form example.","type":"object","required":["firstName","lastName"],"properties":{"name":{"type":"string","title":"Name","default":"Chuck"},"password":{"type":"string","title":"Password","minLength":3},"telephone":{"type":"string","title":"Telephone","minLength":10}}} JSON,

    cli.setUISchema(cli.uiGroups(
        cli.uiGroup(
            cli.uiField("name", 0.5),
            cli.uiField("password", 0.5, cli.uiFieldWidget(cli.uiWidgetPassword)),
        ),
        cli.uiGroup(cli.uiField("telephone", 1, cli.uiFieldPosition(cli.uiPosHorizontal))),
    )),
),

cli.setRequired(true), ) cli.check() ```

func (*CliApp) SetUISchemaFieldStyle

func (c *CliApp) SetUISchemaFieldStyle(css map[string]any) UISchemaFieldParams

func (*CliApp) SetUISchemaFieldWidget

func (c *CliApp) SetUISchemaFieldWidget(widget UISchemaWidgetType) UISchemaFieldParams

uiFieldWidget 是一个选项参数,用于指定UISchema中的字段使用的组件 Example: ``` info = cli.Json(

"info",
cli.setVerboseName("项目信息"),
cli.setJsonSchema(
    <<<JSON

{"title":"A registration form","description":"A simple form example.","type":"object","required":["firstName","lastName"],"properties":{"name":{"type":"string","title":"Name","default":"Chuck"},"password":{"type":"string","title":"Password","minLength":3},"telephone":{"type":"string","title":"Telephone","minLength":10}}} JSON,

    cli.setUISchema(cli.uiGroups(
        cli.uiGroup(
            cli.uiField("name", 0.5),
            cli.uiField("password", 0.5, cli.uiFieldWidget(cli.uiWidgetPassword)),
        ),
        cli.uiGroup(cli.uiField("telephone", 1)),
    )),
),

cli.setRequired(true), ) cli.check() ```

func (*CliApp) SetUISchemaGlobalFieldPosition

func (c *CliApp) SetUISchemaGlobalFieldPosition(style UISchemaFieldClassName) UISchemaParams

uiGlobalFieldPosition 是一个选项参数,用于指定UISchema中全局的字段位置,默认为垂直排列 Example: ``` info = cli.Json(

"info",
cli.setVerboseName("项目信息"),
cli.setJsonSchema(
    <<<JSON

{"title":"A registration form","description":"A simple form example.","type":"object","required":["firstName","lastName"],"properties":{"name":{"type":"string","title":"Name","default":"Chuck"},"password":{"type":"string","title":"Password","minLength":3},"telephone":{"type":"string","title":"Telephone","minLength":10}}} JSON,

    cli.setUISchema(cli.uiGlobalFieldPosition(cli.uiPosHorizontal)),
),

cli.setRequired(true), ) cli.check() ```

func (*CliApp) SetUISchemaGroups

func (c *CliApp) SetUISchemaGroups(groups ...uiSchemaGroup) UISchemaParams

uiGroups 是一个选项参数,用于指定UISchema中的字段整体分组,接受多个分组(cli.uiGroup) Example: ``` info = cli.Json(

"info",
cli.setVerboseName("项目信息"),
cli.setJsonSchema(
    <<<JSON

{"title":"A registration form","description":"A simple form example.","type":"object","required":["firstName","lastName"],"properties":{"name":{"type":"string","title":"Name","default":"Chuck"},"password":{"type":"string","title":"Password","minLength":3},"telephone":{"type":"string","title":"Telephone","minLength":10}}} JSON,

    cli.setUISchema(cli.uiGroups(
        cli.uiGroup(
            cli.uiField("name", 0.5),
            cli.uiField("password", 0.5, cli.uiFieldWidget(cli.uiWidgetPassword)),
        ),
        cli.uiGroup(cli.uiField("telephone", 1)),
    )),
),

cli.setRequired(true), ) cli.check() ```

func (*CliApp) SetUISchemaInnerGroups

func (c *CliApp) SetUISchemaInnerGroups(groups ...uiSchemaGroup) UISchemaFieldParams

uiFieldGroups 是一个选项参数,用于设置UISchema中字段的嵌套组 Example: ``` info = cli.Json(

"info",
cli.setVerboseName("项目信息"),
cli.setJsonSchema(
    <<<JSON

{"title":"A list of tasks","type":"object","required":["title"],"properties":{"title":{"type":"string","title":"Task list title"},"tasks":{"type":"array","title":"Tasks","items":{"type":"object","required":["title"],"properties":{"title":{"type":"string","title":"Title","description":"A sample title"},"details":{"type":"string","title":"Task details","description":"Enter the task details"},"done":{"type":"boolean","title":"Done?","default":false}}}}}} JSON,

    cli.setUISchema(cli.uiGroups(
        cli.uiGroup(cli.uiField("title", 1)),
        cli.uiGroup(cli.uiField(
            "tasks",
            1,
            cli.uiFieldGroups(cli.uiGroup(cli.uiField(
                "items",
                1,
                cli.uiFieldGroups(
                    cli.uiGroup(cli.uiField("title", 1)),
                    cli.uiGroup(cli.uiField("details", 1, cli.uiFieldWidget(cli.uiWidgetTextarea))),
                    cli.uiGroup(cli.uiField("done", 1)),
                ),
            ))),
        )),
    )),
),

cli.setRequired(true), ) cli.check() ```

func (*CliApp) SetVerboseName added in v1.3.1

func (c *CliApp) SetVerboseName(verboseName string) SetCliExtraParam

setVerboseName 是一个选项函数,设置参数的中文名 Example: ``` cli.String("target", cli.setVerboseName("目标")) ```

func (*CliApp) SetYakitPayload

func (c *CliApp) SetYakitPayload(b bool) SetCliExtraParam

setYakitPayload 是一个选项函数,设置参数建议值为Yakit payload的字典名列表 Example: ``` cli.String("dictName", cli.setYakitPayload(true)) ```

func (*CliApp) String added in v1.3.1

func (c *CliApp) String(name string, opts ...SetCliExtraParam) string

String 获取对应名称的命令行参数,并将其转换为 string 类型返回 Example: ``` target = cli.String("target") // --target yaklang.com 则 target 为 yaklang.com ```

func (*CliApp) StringSlice added in v1.3.1

func (c *CliApp) StringSlice(name string, options ...SetCliExtraParam) []string

StringSlice 获取对应名称的命令行参数,将其字符串根据","切割返回 []string 类型 Example: ``` targets = cli.StringSlice("targets") // --targets yaklang.com,google.com 则 targets 为 ["yaklang.com", "google.com"] ```

func (*CliApp) Text added in v1.3.1

func (c *CliApp) Text(name string, opts ...SetCliExtraParam) string

Text 获取对应名称的命令行参数,并将其转换为 string 类型返回 其作为一个独立脚本运行时与 cli.String 没有区别,仅在 Yakit 图形化中展示为文本框形式 Example: ``` target = cli.Text("target") // --target yaklang.com 则 target 为 yaklang.com ```

func (*CliApp) UI added in v1.3.3

func (c *CliApp) UI(opts ...UIParams)

func (*CliApp) Url added in v1.3.1

func (c *CliApp) Url(name string, opts ...SetCliExtraParam) []string

Url 获取对应名称的命令行参数,根据","切割并尝试将其转换为符合URL格式并返回 []string 类型 Example: ``` urls = cli.Url("urls") // --urls yaklang.com:443,google.com:443 则 urls 为 ["https://yaklang.com", "https://google.com"] ```

func (*CliApp) Urls added in v1.3.1

func (c *CliApp) Urls(name string, opts ...SetCliExtraParam) []string

Urls 获取对应名称的命令行参数,根据","切割并尝试将其转换为符合URL格式并返回 []string 类型 Example: ``` urls = cli.Urls("urls") // --urls yaklang.com:443,google.com:443 则 urls 为 ["https://yaklang.com", "https://google.com"] ```

func (*CliApp) YakCode added in v1.3.1

func (c *CliApp) YakCode(name string, opts ...SetCliExtraParam) string

YakCode 获取对应名称的命令行参数,并将其转换为 string 类型返回 其作为一个独立脚本运行时与 cli.String 没有区别,仅在 Yakit 图形化中展示为 Yak 代码形式 Example: ``` target = cli.YakCode("target") // --target yaklang.com 则 target 为 yaklang.com ```

func (*CliApp) YakitPlugin added in v1.3.1

func (c *CliApp) YakitPlugin(options ...SetCliExtraParam) []string

YakitPlugin 获取名称为 yakit-plugin-file 的命令行参数 根据其传入的值读取其对应文件内容并根据"|"切割并返回 []string 类型,表示各个插件名 Example: ``` plugins = cli.YakitPlugin() // --yakit-plugin-file plugins.txt 则 plugins 为 plugins.txt 文件中的各个插件名 ```

type SetCliExtraParam

type SetCliExtraParam func(c *cliExtraParams)

func SetTempArgs

func SetTempArgs(args []string) SetCliExtraParam

type UIParams added in v1.3.3

type UIParams func() // not used yet

type UISchema

type UISchema func(...UISchemaParams)

type UISchemaFieldClassName

type UISchemaFieldClassName string
const (
	UISchemaFieldPosDefault    UISchemaFieldClassName = ""
	UISchemaFieldPosHorizontal UISchemaFieldClassName = "json-schema-row-form"
)

type UISchemaFieldParams

type UISchemaFieldParams func(*uiSchemaField)

type UISchemaParams

type UISchemaParams func(*uiSchemaParams)

type UISchemaWidgetType

type UISchemaWidgetType string
const (
	UISchemaWidgetDefault  UISchemaWidgetType = ""
	UISchemaWidgetTable    UISchemaWidgetType = "table"
	UISchemaWidgetRadio    UISchemaWidgetType = "radio"
	UISchemaWidgetSelect   UISchemaWidgetType = "select"
	UISchemaWidgetCheckbox UISchemaWidgetType = "checkbox"
	UISchemaWidgetTextArea UISchemaWidgetType = "textarea"
	UISchemaWidgetPassword UISchemaWidgetType = "password"
	UISchemaWidgetColor    UISchemaWidgetType = "color"
	UISchemaWidgetEmail    UISchemaWidgetType = "email"
	UISchemaWidgetUri      UISchemaWidgetType = "uri"
	UISchemaWidgetDate     UISchemaWidgetType = "date"
	UISchemaWidgetDateTime UISchemaWidgetType = "date-time"
	UISchemaWidgetTime     UISchemaWidgetType = "time"
	UISchemaWidgetUpdown   UISchemaWidgetType = "updown"
	UISchemaWidgetRange    UISchemaWidgetType = "range"
	UISchemaWidgetFile     UISchemaWidgetType = "file"
	UISchemaWidgetFiles    UISchemaWidgetType = "files"
	UISchemaWidgetFolder   UISchemaWidgetType = "folder"
)

Jump to

Keyboard shortcuts

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