matr builder basic helper util funcs
To enable debug mode set debug to true
tlkn.Debug = true
Note: leading whitespace will be trimmed. On multi-line strings each line's leading whitespace will be trimmed
// one liner
err := tlkn.Bash(context.Background(), "ls -la")
// multi line
// note: each line will be trimmed of leading whitespace
err := tlkn.Bask(`ls -la
echo "hello"
`)
Simple wrapper around Bash func for use with Parallel
cmd := tlkn.BashCmd(context.Background(), "ls -la")
if err := cmd(); err != nil {
log.Fatal(err)
}
Run multiple funcs in parallel. Exits if any funcs return an error
ctx := context.Background()
err := tlkn.Parallel(
tlkn.BashCmd(ctx, "echo \"0\"")
tlkn.BashCmd(ctx, "echo \"1\"")
tlkn.BashCmd(ctx, "echo \"2\"")
tlkn.BashCmd(ctx, "echo \"3\"")
tlkn.BashCmd(ctx, "echo \"4\"")
)
if err != nil {
log.Fatal(err)
}
Prompt prompts user for input with default value.
v := tlkn.Prompt("Username:")
// returns string value or "" if no value given
fmt.Println(v) // prints string value
Prompt prompts user for input with default value and requires an input.
v := tlkn.PromptRequired("state:")
// returns string value if none present prompt is re-displayed
fmt.Println(v)
PromptConfirm continues prompting until the input is boolean-ish.
v := tlkn.PromptConfirm("do you hate writing docs:")
// accepted cli inputs:
// "Yes", "yes", "y", "Y"
// "No", "no", "n", "N"
// prints bool response
fmt.Println(v)
Choose prompts for a single selection from list
, returning in the index.
choices := []string{"dev", "qa", "staging", "prod"}
// return selected choice index
v := tlkn.PromptChoose("Where would you like to deploy?", choices)
// prints choice string
fmt.Println("Deploying to:", choices[v])
Special thanks to the many packages that were used directly or as inspiration.
prompts : segmentio/go-prompt