command

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2024 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CombinedOut added in v1.7.0

func CombinedOut(cmd BaseCmd) (string, error)

Execute CombinedOut on all library command types/interfaces.

func Out added in v1.7.0

func Out(cmd BaseCmd) (string, error)

Execute Out on all library command types/interfaces.

func Run added in v1.7.0

func Run(cmd BaseCmd) error

Execute Run on all library command types/interfaces.

func Start added in v1.7.0

func Start(cmd BaseCmd) error

Execute Start on all library command types/interfaces.

Types

type BaseCmd added in v1.7.0

type BaseCmd interface {
	GetExec() *exec.Cmd

	SetInput(string)
	SetInputf(string, ...any)

	Std(bool, bool, bool)
	Stdout(bool)
	Stdin(bool)
	Stderr(bool)

	Run() error
	Out() (string, error)
	Start() error
	CombinedOut() (string, error)

	SetAndStartf(string, ...any) error
	SetAndCombinedOutf(string, ...any) (string, error)
	SetAndOutf(string, ...any) (string, error)
	SetAndRunf(string, ...any) error

	SetAndStart(string) error
	SetAndCombinedOut(string) (string, error)
	SetAndOut(string) (string, error)
	SetAndRun(string) error
}

The universal base interface for the others, can be converted unidirectionally to all others.

func NewBaseCmd added in v1.7.0

func NewBaseCmd(command string) BaseCmd

Creates a new BaseCmd interface, which is completely universal and cross-platform.

func NewBaseCmdf added in v1.7.0

func NewBaseCmdf(command string, args ...any) BaseCmd

NewBaseCmd but with a fmt.Sprintf in it.

type Cmd

type Cmd struct {
	internal.Shared
	Shell struct {
		Enabled bool

		CustomSh struct {
			Enabled bool
			ShName  string
			ShArg   string // Shell execution cmd
		}
		// contains filtered or unexported fields
	}
	Chroot struct {
		Route   string
		Enabled bool
	}
}

func NewCmd added in v1.7.0

func NewCmd(command string) *Cmd

Create a cmd structure convertible to the default interface for your platform. Ex: Windows -> WindowsCmd. Unix -> UnixCmd.

func NewCmdf added in v1.7.0

func NewCmdf(command string, args ...any) *Cmd

It's the same as NewCmd(fmt.Sprintf(command,args...)).

func (Cmd) CombinedOut added in v1.3.0

func (sh Cmd) CombinedOut() (string, error)

It is the same as run, but returns one more string value (the output of the command).

func (*Cmd) CustomShell added in v1.3.0

func (sh *Cmd) CustomShell(shellName, execArg string)

Set a custom shell to exec the command.

func (*Cmd) DisableChroot added in v1.7.0

func (sh *Cmd) DisableChroot()

Disables Chroot.

func (*Cmd) EnableChroot added in v1.7.0

func (sh *Cmd) EnableChroot()

Enables Chroot.

func (*Cmd) GetChroot added in v1.7.0

func (sh *Cmd) GetChroot() (string, bool)

Returns whether chroot is enabled and its respective path.

func (Cmd) GetExec added in v1.3.0

func (sh Cmd) GetExec() *exec.Cmd

Returns the exec.Cmd structure with all parameters already configured.

func (Cmd) Out added in v1.3.0

func (sh Cmd) Out() (string, error)

It is the same as run, but skips the Std setting and returns an error value and the output as a string, i.e. exec.Command(<command>).Output().

func (Cmd) Run added in v1.3.0

func (sh Cmd) Run() error

Executes normally the command with the parameters set, with the classic exec.Command(<command>).Run().

func (*Cmd) RunWithShell added in v1.3.0

func (sh *Cmd) RunWithShell(set bool)

If the value is true use exec.Command([shell],[arg],input) instead of exec.Command(input[0],input[1:]...)

func (Cmd) SetAndCombinedOut added in v1.3.0

func (sh Cmd) SetAndCombinedOut(command string) (string, error)

It is the same as cmd := command.Cmd("<command>"); cmd.CombinedOut() but in a single argument, what it does is to put an internal input (the one provided) and execute it directly without affecting the main structure.

func (Cmd) SetAndCombinedOutf added in v1.6.0

func (sh Cmd) SetAndCombinedOutf(command string, args ...any) (string, error)

It is the same as a SetAndCombinedOut(fmt.Sprintf(command,args)) but shortened for better handling.

func (Cmd) SetAndOut added in v1.3.0

func (sh Cmd) SetAndOut(command string) (string, error)

It is the same as cmd := command.Cmd("<command>"); cmd.Out() but in a single argument, what it does is to put an internal input (the one provided) and execute it directly without affecting the main structure.

func (Cmd) SetAndOutf added in v1.6.0

func (sh Cmd) SetAndOutf(command string, args ...any) (string, error)

Is the same as a SetAndOut(fmt.Sprintf(command,args)) but shortened for better handling.

func (Cmd) SetAndRun added in v1.3.0

func (sh Cmd) SetAndRun(command string) error

It is the same as cmd := command.Cmd("<command>"); cmd.Run() but in a single argument, what it does is to put an internal input (the one provided) and execute it directly without affecting the main structure.

func (Cmd) SetAndRunf added in v1.6.0

func (sh Cmd) SetAndRunf(command string, args ...any) error

Is the same as a SetAndRun(fmt.Sprintf(command,args)) but shortened for better handling.

func (Cmd) SetAndStart added in v1.3.0

func (sh Cmd) SetAndStart(command string) error

It is the same as cmd := command.Cmd("<command>"); cmd.Start() but in a single argument, what it does is to put an internal input (the one provided) and execute it directly without affecting the main structure.

func (Cmd) SetAndStartf added in v1.6.0

func (sh Cmd) SetAndStartf(command string, args ...any) error

It is the same as a SetAndStart(fmt.Sprintf(command,args)) but shortened for better handling.

func (*Cmd) SetChroot added in v1.5.0

func (sh *Cmd) SetChroot(mountPoint string)

Configure the Chroot path and activate it.

func (*Cmd) SetChrootf added in v1.6.0

func (sh *Cmd) SetChrootf(mountPoint string, args ...any)

Same as SetChroot but with a fmt.Sprinf inside it.

func (Cmd) Start added in v1.3.0

func (sh Cmd) Start() error

Run the command in a new goroutine, just like cmd.Run(), but using exec.Command(<cmd>).Start().

func (*Cmd) UseBashShell added in v1.3.0

func (sh *Cmd) UseBashShell(set bool)

type SudoCmd added in v1.3.0

type SudoCmd struct {
	Cmd
	// contains filtered or unexported fields
}

func NewSudoCmd added in v1.7.0

func NewSudoCmd(command string, optionalPassword ...string) *SudoCmd

Creates a UnixCmd interface but with specific functions for executing sudo commands.

func NewSudoCmdf added in v1.7.0

func NewSudoCmdf(passwd, command string, args ...any) *SudoCmd

NewSudoCmd but with a fmt.Sprintf in it.

func (SudoCmd) CombinedOut added in v1.3.0

func (sh SudoCmd) CombinedOut() (string, error)

func (*SudoCmd) GetExec added in v1.7.0

func (sh *SudoCmd) GetExec() *exec.Cmd

func (SudoCmd) Out added in v1.3.0

func (sh SudoCmd) Out() (string, error)

func (*SudoCmd) Run added in v1.3.0

func (sh *SudoCmd) Run() error

func (*SudoCmd) SetPasswd added in v1.7.0

func (sh *SudoCmd) SetPasswd(password string)

Sudo parameters.

func (SudoCmd) Start added in v1.3.0

func (sh SudoCmd) Start() error

type UnixCmd

type UnixCmd interface {
	BaseCmd

	RunWithShell(bool)
	UseBashShell(bool)
	CustomShell(string, string)
	GetChroot() (string, bool)
	SetChroot(string)
	SetChrootf(string, ...any)
	EnableChroot()
	DisableChroot()
}

An exclusive interface for unix, which has the specific functions for that OS.

func NewUnixCmd added in v1.7.0

func NewUnixCmd(command string) UnixCmd

Creates a UnixCmd interface that is convertible to: UnixCmd -> UnixSudoCmd.

func NewUnixCmdf added in v1.7.0

func NewUnixCmdf(command string, args ...any) UnixCmd

NewUnixCmd but with a fmt.Sprintf in it.

type UnixSudoCmd

type UnixSudoCmd interface {
	UnixCmd

	SetPasswd(string)
}

Unix interface with extra functions to cover sudo execution.

type WindowsCmd added in v1.7.0

type WindowsCmd interface {
	BaseCmd

	RunWithPS(bool)

	SetRawExec(bool)
	RawExec() bool
	SetHideCmd(bool)
	HideCmd() bool

	UsingPS() bool
	UsingCmd() bool

	SetPSFlags(string)
	SetPSFlagsf(string, ...any)
	PSFlags() string

	SetCmdFlags(string)
	SetCmdFlagsf(string, ...any)
	CmdFlags() string
}

The exclusive command interface for windows, you can convert BaseCmd -> WindowsCmd with specific functions for that OS.

Jump to

Keyboard shortcuts

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