Skip to content

Implement stdout output customization attribute for Command objects #2482

@deepbrook

Description

@deepbrook

Description

I've found myself writing a lot of echo "<explanation of what next cmd does> commands with the silent: true property set, whenever I'm writing tasks for my users.

Let's pretend we want to supply a task that creates a file given via CLI_ARGS, without disclosing to our users what magic we used to do so (because of reasons). Currently, I would have to write something like this:

version: 3
tasks:
  create-file:
    cmds:
      - cmd: echo "Creating requested file at {{ .CLI_ARGS }}..."
        silent: true
      - cmd: touch {{ .CLI_ARGS }}
        silent: true
      - cmd: echo "done!"
        silent: true

output:

> task create-file -- foo.txt
Creating requested file at foo.txt...
done!

This bloats the task, and makes it tedious to write and parse.

My request would be a new echo field, which would implicitly set silent: true on the command object, and print the echo field's value instead when it's run. Also, allowing it to be the only field set would do away
with all the { cmd: "echo <msg>", "silent": true} constructs:

version: 3
tasks:
  create-file:
    cmds:
      - echo : Creating requested file at {{ .CLI_ARGS }}...
        cmd: touch {{ .CLI_ARGS }}
      - echo: done!

The output should be identical:

> task create-file -- foo.txt
Creating requested file at foo.txt...
done!

In summary:

Add a new field echo to the command object:

  • When set to a non-empty string, its value is printed to stdout and the object's silent property implicitly set to true
  • When no cmd or defer attribute is set, the command should behave identical to { cmd: "echo <msg>", "silent": true}

Metadata

Metadata

Assignees

No one assigned

    Labels

    state: needs triageWaiting to be triaged by a maintainer.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions