command

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const ExecTag = "exec"

ExecTag stands for the path of executable file in command. If we want this util works , we must add Exec in the struct and use NewExec() to initialize it, because the default way to initialize Exec means None in code.

View Source
const ParaTag = "para"

ParaTag stands for parameters in command. We can use it in struct fields as a tag. Just like Port below

type Iptables Struct {
	Exec
	Port string `para:"-p"`
}

If the field is not string type or []string type , it will bring an error. If the tag value like "-p" is empty string , the para will just add the field value into the command just as some single value parameter in command. If the value of field is empty string or empty string slice or empty slice, the field and tag will all be skipped.

View Source
const SubCommandTag = "sub_command"

SubCommandTag stands for the sub command in common command. We can use it in struct fields as a tag. Just like MatchExtension below

type Iptables Struct {
	Exec
	MatchExtension Match `sub_command:""`
}

type Match Struct {
	Exec
	Port string `para:"-p"`
}

Field with SubcommandTag needs to be a struct with Exec.

Variables

This section is empty.

Functions

func Marshal

func Marshal(i interface{}) (string, []string, error)

func SearchKey

func SearchKey(value reflect.Value) (string, bool)

func ToCommand

func ToCommand(i interface{}) (*exec.Cmd, error)

Types

type Exec

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

Exec is the interface of a command. We need to inherit it in the struct of command. User must add ExecTag as the tag of Exec field. Example:

type Iptables struct {
	Exec           `exec:"iptables"`
	Tables         string `para:"-t"`
}

func NewExec

func NewExec() Exec

Jump to

Keyboard shortcuts

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