cli

package
v1.3.4-beta6 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

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,

	"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,
	"FileOrContent": DefaultCliApp.FileOrContent,
	"LineDict":      DefaultCliApp.LineDict,

	"setHelp":     DefaultCliApp.SetHelp,
	"setDefault":  DefaultCliApp.SetDefault,
	"setRequired": DefaultCliApp.SetRequired,

	"setVerboseName": DefaultCliApp.SetVerboseName,

	"setCliGroup": DefaultCliApp.SetCliGroup,

	"setMultipleSelect": DefaultCliApp.SetMultipleSelect,

	"setSelectOption": DefaultCliApp.SetSelectOption,

	"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,

	"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) 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) 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) 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) 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) 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) 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) 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) SetVerboseName added in v1.3.1

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

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

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()

Jump to

Keyboard shortcuts

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