Skip to content

matr-builder/tlkn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

tlkn

matr builder basic helper util funcs

Debug mode

To enable debug mode set debug to true

  tlkn.Debug = true

Bash(ctx context.Context, cmd string) (out []byte, err error)

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"
  `)

BashCmd(ctx context.Context, cmd string) func() error

Simple wrapper around Bash func for use with Parallel

  cmd := tlkn.BashCmd(context.Background(), "ls -la")

  if err := cmd(); err != nil {
    log.Fatal(err)
  }

Parallel(fns ...func error) error

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(prompt string, args ...interface) (s string)

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 

PromptRequired(prompt string, args ...interface) (s string)

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(prompt string, args ...interface) bool

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)

PromptChoose(prompt string, list []string) int

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])

Credits

Special thanks to the many packages that were used directly or as inspiration.

prompts : segmentio/go-prompt

About

Currently just basic helpers for matr builder

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages