adding envs tagging/interpolation

This commit is contained in:
brent saner
2024-06-17 04:33:30 -04:00
parent eed9c34ebf
commit b64c318a4a
18 changed files with 734 additions and 1575 deletions

View File

@@ -1,34 +1,123 @@
package exec_extra
var (
StructTagCmdArgs string = "cmdarg"
import (
`r00t2.io/goutils/bitmask`
)
var (
CmdArgsTag string = "cmdarg"
/*
CmdArgsOptPreferShort, if specified, prefers the "short" argument over "long" if both are specified.
The default is to prefer long.
CmdArgsDictSep specifies the string to use to separate keys and values.
Can be specified per-field via the `prefer_short` option (no value/value ignored).
To override at the struct field level, use the tag value:
`<CmdArgsTag>:"dictsep=<str>"`
Where str is the string to use. e.g.:
`cmdarg:"short=d,long=data,dictsep=."`
Would render a map value of map[string]string{"foo": "bar"} as:
`-d foo.bar`
*/
CmdArgsOptPreferShort cmdArgOpt = func(opts *cmdArgsOpts) (err error) {
opts.preferShort = true
return
}
/*
CmdArgsOptShortEquals, if specified, renders short flags *with* an equals sign
(if using POSIX args).
Has no effect if using Windows traditional syntax or if there is no value for the field.
*/
CmdArgsOptShortEquals cmdArgOpt = func(opts *cmdArgsOpts) (err error) {
opts.preferShort = true
return
}
CmdArgsOptLongNoEquals cmdArgOpt = func(opts *cmdArgsOpts) (err error) {
opts.preferShort = true
return
}
CmdArgsDictSep string = ":"
)
// CmdArgOptNone is an "empty option" and does nothing.
const CmdArgOptNone bitmask.MaskBit = 0
const (
/*
CmdArgOptPreferShort prefers short options where possible.
Has no effect if Windows traditional syntax is used.
The default is to use long options.
See also CmdArgOptPreferLong.
Corresponding struct tag option: prefer_short
*/
CmdArgOptPreferShort cmdArgOpt = 1 << iota
/*
CmdArgOptPreferLong prefers long options where possible.
Has no effect if Windows traditional syntax is used.
This behavior is the default, but it can be used to
override a CmdArgOptPreferShort from a parent.
Corresponding struct tag option: prefer_long
*/
CmdArgOptPreferLong
/*
CmdArgOptShortEquals will use an equals separator
for short flags instead of a space (the default).
Has no effect if Windows traditional syntax is used.
Corresponding struct tag option: short_equals
*/
CmdArgOptShortEquals
/*
CmdArgOptShortNoEquals will use a space separator
for short flags instead of an equals.
Has no effect if Windows traditional syntax is used.
This behavior is the default, but it can be used to
override a CmdArgOptPreferShort from a parent.
Corresponding struct tag option: no_short_equals
*/
CmdArgOptShortNoEquals
/*
CmdArgOptLongEquals will use an equals separator
for long flags instead of a space.
Has no effect if Windows traditional syntax is used.
This behavior is the default, but it can be used to
override a CmdArgOptLongNoEquals from a parent.
Corresponding struct tag option: long_equals
*/
CmdArgOptLongEquals
/*
CmdArgOptLongNoEquals will use a space separator
for short flags instead of an equals.
Has no effect if Windows traditional syntax is used.
This behavior is the default, but it can be used to
override a CmdArgOptPreferShort from a parent.
Corresponding struct tag option: no_long_equals
*/
CmdArgOptLongNoEquals
/*
CmdArgOptForceNoPosix forces the resulting command string to use "traditional Windows" flag notation.
Traditionally, Windows used flags like `/f` instead of POSIX `-f`, `/c:value` instead of `-c value`
or `-c=value`, etc.
Has no effect if not running on Windows.
This behavior is the default, but it can be used to
override a CmdArgOptPreferShort from a parent.
See also the inverse of this option, CmdArgOptForcePosix.
Corresponding struct tag option: force_no_posix
*/
CmdArgOptForceNoPosix
/*
CmdArgOptForcePosix forces the resulting command string to use "POSIX" flag notation.
Traditionally, Windows used flags like `/f` instead of POSIX `-f`, `/c:value` instead of `-c value`
or `-c=value`, etc.
If this option is passed, then the POSIX flag syntax (-a/--arg) will be used instead.
Note that on Windows runtime, the default is to use the traditional slash-based syntax.
If you are generating command strings for Powershell or third-party software, you probably
want to use CmdArgsOptForcePosix instead.
See also the inverse of this option, CmdArgsOptForceNoPosix.
Corresponding struct tag option: force_posix
*/
CmdArgOptForcePosix
)