mumoshu / variant2

Turn your bash scripts into a modern, single-executable CLI app today
MIT License
141 stars 11 forks source link

Feature request: `name` field for exec blocks #55

Open korenyoni opened 2 years ago

korenyoni commented 2 years ago

A name field for an exec block would be helpful in cleaning up output when a non-exit zero code is intentional.

For example:

➜  my-cli component init eks/irsa/external-dns .                                       
Component . already initialized
Error: command "bash -c     if [[ -d . ]] && [[ "false" == "false" ]]; then
      echo "Component . already initialized"
      exit 1
    fi

    if [[ -d /Users/yonatankoren/software/example/terragrunt/_components/eks/irsa/external-dns ]]; then
      mkdir -p .
      cat /Users/yonatankoren/software/software/example/terragrunt/_components/eks/irsa/external-dns/terragrunt.hcl | sed "s!COMPONENT!eks/irsa/external-dns!g" > ./terragrunt.hcl # use delimiter other than / (which exists in component names)
    else
      echo "Error: component does not exist"
      exit 1
    fi
": exit status 1

If the exec block accepted a name, it could look something like this:

exec {
    name = "init-component"
    command = "bash"
    ...

Then when a non-exit zero code occurs, only the name is reported and not the whole command:

Component . already initialized
Error: init-component: exit status 1