args

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FirstListArgsHelp = `` /* 639-byte string literal not displayed */
View Source
var MultipleListsArgsHelp = `` /* 1021-byte string literal not displayed */
View Source
var MultipleMinMaxArgsHelp = `` /* 1008-byte string literal not displayed */
View Source
var RestSliceMaxHelp = `` /* 1284-byte string literal not displayed */
View Source
var TagCompletedArgsHelp = `` /* 696-byte string literal not displayed */

Functions

This section is empty.

Types

type FirstListArgs

type FirstListArgs struct {
	Args struct {
		Hosts  []Host `description:"A list of hosts with minimum and maximum requirements" required:"1-2"`
		Target Proxy  `description:"A single, required remaining argument" required:"1"`
	} `positional-args:"yes" required:"yes"`
}

FirstListArgs shows how to use several positionals, of which the first is a list, but not the last.

func (*FirstListArgs) Execute

func (c *FirstListArgs) Execute(args []string) error

Execute - Since the positional arguments for this command all have a maximum allowed number of items, any word given in excess will be stored in the args []string parameter of this function.

type Host

type Host string

Host is another type used as a positional argument.

func (*Host) Complete

func (p *Host) Complete(ctx carapace.Context) carapace.Action

Complete generates completions for the Host type.

type IP

type IP []string

IP is another argument field, but which implements a slightly more complicated completion interface.

func (*IP) Complete

func (ip *IP) Complete(ctx carapace.Context) carapace.Action

Complete produces completions for the IP type.

type MultipleListsArgs

type MultipleListsArgs struct {
	Args struct {
		// The Vuln positional slot is of type IP, which is an aliased []string.
		// This is so that we can implement a completer around this type.
		//
		// Notice, here, that there is no individual min/max requirement for
		// this slot, in additional to no global requirement on the struct itself.
		// Thus, this positional slot can be empty.
		Vuln IP `description:"Vulnerable IP addresses to check"`

		// Other is a positional slot requiring at least one element, and at most two.
		// Consequently:
		// - If one argument is passed, it will be stored in this slot.
		// - If two arguments, one is stored here, and the first is stored in Vuln
		// - If three or more, two will be stored here, and the others in Vuln.
		Other []Host `description:"Other list of IP addresses" required:"1-2"`
	} `positional-args:"yes"`
}

MultipleListsArgs shows how to declare multiple lists as positional arguments, and how provided arguments are dispatched onto their slots.

func (*MultipleListsArgs) Execute

func (c *MultipleListsArgs) Execute(args []string) error

Execute - Note that the args []string parameter will ALWAYS be empty, since all positional slots of the commands are lists, and at least one of them has no maximum number of arguments.

type MultipleMinMaxArgs

type MultipleMinMaxArgs struct {
	Args struct {
		Hosts     []Host  `description:"A list of hosts with minimum and maximum requirements" required:"1-2"`
		Proxies   []Proxy `description:"A list of proxies, with min/max requirements overlapping with Hosts" required:"1-2"`
		Addresses IP      `description:"A last list of IPs, which will store any words given in excess" required:"1"`
	} `positional-args:"yes" required:"yes"`
}

MultipleMinMaxArgs shows how to use multiple lists as positionals, with overlapping min/max requirements. Note that here, the two first slots (Hosts and Proxies), have "overlapping" requirements: - If 2 args are given, each will get one - If 3 args, Hosts will get 2, and proxies will get 1 - If 4 args, each will get 2

Since the IP slot is also a list, all arguments in excess (here, if more than 5 args) will be stored in it.

func (*MultipleMinMaxArgs) Execute

func (c *MultipleMinMaxArgs) Execute(args []string) error

Execute - Note that the args []string parameter will ALWAYS be empty, since all positional slots of the commands are lists, and at least one of them has no maximum number of arguments.

type Proxy

type Proxy string

Proxy is another type used as a positional argument.

func (*Proxy) Complete

func (p *Proxy) Complete(ctx carapace.Context) carapace.Action

Complete generates completions for the Proxy type.

type RestSliceMax

type RestSliceMax struct {
	Args struct {
		IP     string   `description:"An IPv4 address"`
		Emails []string `description:"A list of email addresses" required:"1-2"`
	} `positional-args:"yes"`
}

RestSliceMax is a command demonstrating how specifying a maximum requirement on a remainder slice positional slot will behave when the previous slots are NOT slices.

func (*RestSliceMax) Execute

func (c *RestSliceMax) Execute(args []string) error

type TagCompletedArgs

type TagCompletedArgs struct {
	Args struct {
		// Files accepts at most two values, and the completions for them will be restricted to files with a '.go' extension.
		// Since this slot has a min and max requirement value, once one argument is provided at the command-line, completions
		// will be proposed both for this slot and for the next one, up until the maximum requirements are fulfilled.
		Files []string `description:"A list of files with min/max requirements" required:"1-2" complete:"FilterExt,go"`

		// JSONConfig also completes files, but with a .json extension.
		JSONConfig string `description:"the target of your command (anything string-based)" required:"1" complete:"FilterExt,json"`
	} `positional-args:"yes" required:"yes"`
}

TagCompletedArgs shows how to specify completers with struct tags.

func (*TagCompletedArgs) Execute

func (c *TagCompletedArgs) Execute(args []string) error

Execute - Here, since the last positional slot is not a list, and the first one is a list but has a maximum number of arguments allowed, any arg in excess is stored in args []string parameter.

Jump to

Keyboard shortcuts

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