
* command/terminal: allow restart to change process args Add -args flag to "restart" command. For example, "restart -args a b c" will pass args a b c to the new process. Add "-c" flag to pass the checkpoint name. This is needed to disambiguate the checkpoint name and arglist. Reverted unnecessary changes. * Applied reviewer comments. Vendored argv. Change the syntax of restart. When the target is is in recording mode, it always interprets the args as a checkpoint. Otherwise, it interprets the args as commandline args. The flag "-args" is still there, to handle the case in which the user wants to pass an empty args on restart. * Add restartargs.go. Change "restart -args" to "restart -noargs" to clarify that this flag is used to start a process with an empty arg.
35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
// Package argv parse command line string into arguments array using the bash syntax.
|
|
package argv
|
|
|
|
import "strings"
|
|
|
|
// ParseEnv parsing environment variables as key/value pair.
|
|
//
|
|
// Item will be ignored if one of the key and value is empty.
|
|
func ParseEnv(env []string) map[string]string {
|
|
var m map[string]string
|
|
for _, e := range env {
|
|
secs := strings.SplitN(e, "=", 2)
|
|
if len(secs) == 2 {
|
|
key := strings.TrimSpace(secs[0])
|
|
val := strings.TrimSpace(secs[1])
|
|
if key == "" || val == "" {
|
|
continue
|
|
}
|
|
if m == nil {
|
|
m = make(map[string]string)
|
|
}
|
|
m[key] = val
|
|
}
|
|
}
|
|
return m
|
|
}
|
|
|
|
// Argv split cmdline string as array of argument array by the '|' character.
|
|
//
|
|
// The parsing rules is same as bash. The environment variable will be replaced
|
|
// and string surround by '`' will be passed to reverse quote parser.
|
|
func Argv(cmdline []rune, env map[string]string, reverseQuoteParser ReverseQuoteParser) ([][]string, error) {
|
|
return NewParser(NewScanner(cmdline, env), reverseQuoteParser).Parse()
|
|
}
|