Documentation
¶
Overview ¶
Package script provides types to represent a parsed script file.
Index ¶
- Variables
- func ExpandEnv(str string) string
- type ArgMap
- type AsCommand
- type AuthConfigCommand
- type CaptureCommand
- type Command
- type CommandMeta
- type CopyCommand
- type EnvCommand
- type FromCommand
- type KubeConfigCommand
- type Machine
- type OutputCommand
- type RunCommand
- func (c *RunCommand) Args() map[string]string
- func (c *RunCommand) GetCmdShell() string
- func (c *RunCommand) GetCmdString() string
- func (c *RunCommand) GetEffectiveCmd() ([]string, error)
- func (c *RunCommand) GetEffectiveCmdStr() (string, error)
- func (c *RunCommand) GetParsedCmd() (string, []string, error)
- func (c *RunCommand) Index() int
- func (c *RunCommand) Name() string
- type Script
- type WorkdirCommand
Constants ¶
This section is empty.
Variables ¶
var ( CmdAs = "AS" CmdAuthConfig = "AUTHCONFIG" CmdCapture = "CAPTURE" CmdCopy = "COPY" CmdEnv = "ENV" CmdFrom = "FROM" CmdKubeConfig = "KUBECONFIG" CmdOutput = "OUTPUT" CmdRun = "RUN" CmdWorkDir = "WORKDIR" Defaults = struct { FromValue string WorkdirValue string KubeConfigValue string AuthPKValue string OutputValue string }{ FromValue: "local", WorkdirValue: "/tmp/crashdir", KubeConfigValue: func() string { kubecfg := os.Getenv("KUBECONFIG") if kubecfg == "" { kubecfg = filepath.Join(os.Getenv("HOME"), ".kube", "config") } return kubecfg }(), AuthPKValue: func() string { return filepath.Join(os.Getenv("HOME"), ".ssh", "id_rsa") }(), OutputValue: "out.tar.gz", } )
var ( Cmds = map[string]CommandMeta{ CmdAs: CommandMeta{Name: CmdAs, MinArgs: 1, MaxArgs: 2, Supported: true}, CmdAuthConfig: CommandMeta{Name: CmdAuthConfig, MinArgs: 1, MaxArgs: 3, Supported: true}, CmdCapture: CommandMeta{Name: CmdCapture, MinArgs: 1, MaxArgs: 2, Supported: true}, CmdCopy: CommandMeta{Name: CmdCopy, MinArgs: 1, MaxArgs: -1, Supported: true}, CmdEnv: CommandMeta{Name: CmdEnv, MinArgs: 1, MaxArgs: -1, Supported: true}, CmdFrom: CommandMeta{Name: CmdFrom, MinArgs: 1, MaxArgs: -1, Supported: true}, CmdKubeConfig: CommandMeta{Name: CmdKubeConfig, MinArgs: 1, MaxArgs: 1, Supported: true}, CmdOutput: CommandMeta{Name: CmdOutput, MinArgs: 1, MaxArgs: 1, Supported: true}, CmdRun: CommandMeta{Name: CmdRun, MinArgs: 1, MaxArgs: 2, Supported: true}, CmdWorkDir: CommandMeta{Name: CmdWorkDir, MinArgs: 1, MaxArgs: 1, Supported: true}, } )
Functions ¶
func ExpandEnv ¶ added in v0.1.1
ExpandEnv searches str for $value or ${value} which is then evaluated using os.ExpandEnv. expandVar supports escaping expansion using \$. For instance, when \$value or \${value} is encountered, it is not expanded, leaving the original values in the string as $value or ${value}.
Types ¶
type AsCommand ¶
type AsCommand struct {
// contains filtered or unexported fields
}
AsCommand represents AS directive:
AS userid:"userid" [groupid:"groupid"]
Param userid required; groupid optional
func NewAsCommand ¶
NewAsCommand returns *AsCommand with parsed arguments
func (*AsCommand) GetCredentials ¶
GetCredentials returns the uid and gid value extracted from Args
func (*AsCommand) GetGroupId ¶
GetGroupId returns the gid specified in AS
type AuthConfigCommand ¶
type AuthConfigCommand struct {
// contains filtered or unexported fields
}
AuthConfigCommand represents AUTHCONFIG directive:
AUTHCONFIG username:"username" private-key:"/path/to/key api-key:key"
Param username is required
func NewAuthConfigCommand ¶
func NewAuthConfigCommand(index int, rawArgs string) (*AuthConfigCommand, error)
NewAuthConfigCommand parses the rawArgs and returns an *AuthCommand
func (*AuthConfigCommand) Args ¶
func (c *AuthConfigCommand) Args() map[string]string
Args returns a slice of raw command arguments
func (*AuthConfigCommand) GetPrivateKey ¶
func (c *AuthConfigCommand) GetPrivateKey() string
GetPrivateKey returns the path of the private key configured
func (*AuthConfigCommand) GetUsername ¶
func (c *AuthConfigCommand) GetUsername() string
GetUsername returns the User ID configured
func (*AuthConfigCommand) Index ¶
func (c *AuthConfigCommand) Index() int
Index is the position of the command in the script
func (*AuthConfigCommand) Name ¶
func (c *AuthConfigCommand) Name() string
Name represents the name of the command
type CaptureCommand ¶
type CaptureCommand struct {
*RunCommand
}
CaptureCommand represents CAPTURE directive which can have one of the following two forms as shown below:
CAPTURE <command-string> CAPTURE cmd:"<command-string>" name:"cmd-name" desc:"cmd-desc"
The former takes no named parameter. When the latter form is used, parameter cmd: is required.
func NewCaptureCommand ¶
func NewCaptureCommand(index int, rawArgs string) (*CaptureCommand, error)
NewCaptureCommand returns *CaptureCommand with parsed arguments
func (*CaptureCommand) GetEffectiveCmd ¶
func (c *CaptureCommand) GetEffectiveCmd() ([]string, error)
GetEffectiveCmd returns the shell (if any) and command as a slice of strings
func (*CaptureCommand) GetEffectiveCmdStr ¶
func (c *CaptureCommand) GetEffectiveCmdStr() (string, error)
GetEffectiveCmdStr returns the effective command as a string which wraps the command around a shell quote if necessary
func (*CaptureCommand) GetParsedCmd ¶
func (c *CaptureCommand) GetParsedCmd() (string, []string, error)
GetParsedCmd returns the effective parsed command as commandName followed by a slice of command arguments
type Command ¶
type Command interface {
// Index is the position of the command in the script
Index() int
// Name represents the name of the command
Name() string
// Args returns a map of parsed arguments
Args() ArgMap
}
Command is an abtract representatio of command in a script
type CopyCommand ¶
type CopyCommand struct {
// contains filtered or unexported fields
}
CopyCommand represents a COPY directive which may have one of the following two forms:
COPY path0 path1 ... pathN COPY paths:"path0 path1 ... pathN"
The former uses no named parameters while the latter uses named parameter (i.e. paths)
func NewCopyCommand ¶
func NewCopyCommand(index int, rawArgs string) (*CopyCommand, error)
NewCopyCommand returns *CopyCommand
func (*CopyCommand) Args ¶
func (c *CopyCommand) Args() map[string]string
Args returns a slice of raw command arguments
func (*CopyCommand) Index ¶
func (c *CopyCommand) Index() int
Index is the position of the command in the script
func (*CopyCommand) Name ¶
func (c *CopyCommand) Name() string
Name represents the name of the command
func (*CopyCommand) Paths ¶
func (c *CopyCommand) Paths() []string
Paths returned a []string of paths to copy
type EnvCommand ¶
type EnvCommand struct {
// contains filtered or unexported fields
}
EnvCommand represents ENV directive which can have one of the following forms:
ENV var0=val0 var1=val0 ... varN=valN ENV vars:"var0=val0 var1=val0 ... varN=valN"
Supports multiple ENV in one script.
func NewEnvCommand ¶
func NewEnvCommand(index int, rawArgs string) (*EnvCommand, error)
NewEnvCommand returns parses the args as environment variables and returns *EnvCommand
func (*EnvCommand) Args ¶
func (c *EnvCommand) Args() map[string]string
Args returns a slice of raw command arguments
func (*EnvCommand) Envs ¶
func (c *EnvCommand) Envs() map[string]string
Envs returns slice of the parsed declared environment variables
func (*EnvCommand) Index ¶
func (c *EnvCommand) Index() int
Index is the position of the command in the script
func (*EnvCommand) Name ¶
func (c *EnvCommand) Name() string
Name represents the name of the command
type FromCommand ¶
type FromCommand struct {
// contains filtered or unexported fields
}
FromCommand represents FROM directive which may take one of the following forms:
FROM host0:port host1:port ... hostN:port FROM hosts:"host0:port host1:port ... hostN:port"
Each host must be specified as an address endpoint with host:port.
func NewFromCommand ¶
func NewFromCommand(index int, rawArgs string) (*FromCommand, error)
NewFromCommand parses the args and returns *FromCommand
func (*FromCommand) Args ¶
func (c *FromCommand) Args() map[string]string
Args returns a slice of raw command arguments
func (*FromCommand) Index ¶
func (c *FromCommand) Index() int
Index is the position of the command in the script
func (*FromCommand) Machines ¶
func (c *FromCommand) Machines() []Machine
Machines returns a slice of Machines to which to connect
func (*FromCommand) Name ¶
func (c *FromCommand) Name() string
Name represents the name of the command
type KubeConfigCommand ¶
type KubeConfigCommand struct {
// contains filtered or unexported fields
}
KubeConfigCommand represents a KUBECONFIG directive which can have one of the following forms:
KUBECONFIG path/to/kubeconfig KUBECONFIG path:"path/to/kubeconfig"
func NewKubeConfigCommand ¶
func NewKubeConfigCommand(index int, rawArgs string) (*KubeConfigCommand, error)
NewKubeConfigCommand creates a value of type KubeConfigCommand in a script
func (*KubeConfigCommand) Args ¶
func (c *KubeConfigCommand) Args() map[string]string
Args returns a slice of raw command arguments
func (*KubeConfigCommand) Index ¶
func (c *KubeConfigCommand) Index() int
Index is the position of the command in the script
func (*KubeConfigCommand) Name ¶
func (c *KubeConfigCommand) Name() string
Name represents the name of the command
func (*KubeConfigCommand) Path ¶
func (c *KubeConfigCommand) Path() string
Config returns the path to the config file
type Machine ¶
type Machine struct {
// contains filtered or unexported fields
}
Machine represents a machine as defined in FROM
type OutputCommand ¶
type OutputCommand struct {
// contains filtered or unexported fields
}
OutputCommand representes a OUTPUT directive which can have one of the following forms:
OUTPUT /path/to/output OUTPUT path:/path/to/output
func NewOutputCommand ¶
func NewOutputCommand(index int, rawArgs string) (*OutputCommand, error)
NewOutputCommand parses args and returns a new *OutputCommand value
func (*OutputCommand) Args ¶
func (c *OutputCommand) Args() map[string]string
Args returns a slice of raw command arguments
func (*OutputCommand) Index ¶
func (c *OutputCommand) Index() int
Index is the position of the command in the script
func (*OutputCommand) Name ¶
func (c *OutputCommand) Name() string
Name represents the name of the command
func (*OutputCommand) Path ¶
func (c *OutputCommand) Path() string
Path returns the parsed path for directory
type RunCommand ¶
type RunCommand struct {
// contains filtered or unexported fields
}
RunCommand represents RUN directive which can have one of the following two forms as shown below:
RUN <command-string> RUN cmd:"<command-string>" shell:"shell-path" desc:"cmd-desc"
The former takes no named parameter. When the latter form is used, parameter cmd: is required.
func NewRunCommand ¶
func NewRunCommand(index int, rawArgs string) (*RunCommand, error)
NewRunCommand returns *RunCommand with parsed arguments
func (*RunCommand) Args ¶
func (c *RunCommand) Args() map[string]string
Args returns a slice of raw command arguments
func (*RunCommand) GetCmdShell ¶
func (c *RunCommand) GetCmdShell() string
GetCmdShell returns shell program and arguments for running the command string (i.e. /bin/bash -c)
func (*RunCommand) GetCmdString ¶
func (c *RunCommand) GetCmdString() string
GetCmdString returns the raw CLI command string
func (*RunCommand) GetEffectiveCmd ¶
func (c *RunCommand) GetEffectiveCmd() ([]string, error)
GetEffectiveCmd returns the shell (if any) and command as a slice of strings
func (*RunCommand) GetEffectiveCmdStr ¶
func (c *RunCommand) GetEffectiveCmdStr() (string, error)
GetEffectiveCmdStr returns the effective command as a string which wraps the command around a shell quote if necessary
func (*RunCommand) GetParsedCmd ¶
func (c *RunCommand) GetParsedCmd() (string, []string, error)
GetParsedCmd returns the effective parsed command as commandName followed by a slice of command arguments
func (*RunCommand) Index ¶
func (c *RunCommand) Index() int
Index is the position of the command in the script
func (*RunCommand) Name ¶
func (c *RunCommand) Name() string
Name represents the name of the command
type Script ¶
type Script struct {
Preambles map[string][]Command // directive commands in the script
Actions []Command // action commands
}
Script is a collection of commands
type WorkdirCommand ¶
type WorkdirCommand struct {
// contains filtered or unexported fields
}
WorkdirCommand representes a WORKDIR which may have one of the following forms:
WORKDIR /path/to/workdir WORKDIR path:/path/to/workdir
func NewWorkdirCommand ¶
func NewWorkdirCommand(index int, rawArgs string) (*WorkdirCommand, error)
NewWorkdirCommand parses args and returns a new *WorkdirCommand value
func (*WorkdirCommand) Args ¶
func (c *WorkdirCommand) Args() map[string]string
Args returns a slice of raw command arguments
func (*WorkdirCommand) Index ¶
func (c *WorkdirCommand) Index() int
Index is the position of the command in the script
func (*WorkdirCommand) Name ¶
func (c *WorkdirCommand) Name() string
Name represents the name of the command
func (*WorkdirCommand) Path ¶
func (c *WorkdirCommand) Path() string
Path returns the parsed path for directory