Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CmdFormat ¶
type CmdFormat int
CmdFormat defines a way of formatting shell commands in a devbox config.
type Commands ¶
type Commands struct {
// MarshalAs determines how MarshalJSON encodes the shell commands.
// UnmarshalJSON will set MarshalAs automatically so that commands
// marshal back to their original format. The default zero-value
// formats them as an array.
MarshalAs CmdFormat
Cmds []string
}
Commands marshals and unmarshals shell commands from a devbox config as either a single string or an array of strings. It preserves the original value such that:
data == marshal(unmarshal(data)))
func (*Commands) AppendScript ¶
AppendScript appends each line of a script to s.Cmds. It also applies the following formatting rules:
- Trim leading newlines from the script.
- Trim trailing whitespace from the script.
- If the first line of the script begins with one or more tabs ('\t'), then unindent each line by that same number of tabs.
- Remove trailing whitespace from each line.
Note that unindenting only happens when a line starts with at least as many tabs as the first line. If it starts with fewer tabs, then it is not unindented at all.
Example ¶
shCmds := Commands{}
shCmds.AppendScript(`
# This script will be unindented by the number of leading tabs
# on the first line.
if true; then
echo "this is always printed"
fi`,
)
b, _ := cuecfg.MarshalJSON(&shCmds)
fmt.Println(string(b))
Output: [ "# This script will be unindented by the number of leading tabs", "# on the first line.", "if true; then", "\techo \"this is always printed\"", "fi" ]
func (Commands) MarshalJSON ¶
MarshalJSON marshals shell commands according to s.MarshalAs. It marshals commands to a string by joining s.Cmds with newlines.
func (*Commands) String ¶
String formats the commands as a single string by joining them with newlines.
func (*Commands) UnmarshalJSON ¶
UnmarshalJSON unmarshals shell commands from a string, an array of strings, or null. When the JSON value is a string, it unmarshals into the first index of s.Cmds.