task icon indicating copy to clipboard operation
task copied to clipboard

Option to disable output of commands in summary

Open br-arruda opened this issue 8 months ago • 1 comments

Description

Hi, I read the issue #1350 and PR #1656. You have chosen summary to output multi-line description of a task, along with the commands inside the task.

My use case is to document tasks which have parameters. Currently --summary produces way more output than I wish it was exposed to someone trying to understand (or to remember) how to use my taskfiles.

For example, I have this field:

  terragrunt_apply:
    desc: |
      Executes the terraform apply command.

      CI: executes terraform in non-interactive way. Default: false
      PLAN: executes terraform plan before apply. Default: false

Which renders this way with task --list:

$ task
task: Available tasks for this project:
* terragrunt_apply:         Executes the terraform apply command.  CI: executes terraform in non-interactive way. Default: false PLAN: executes terraform plan before apply. Default: false 

--list is interesting because it list all tasks, but it collapses multi-line. --summary respect multi-line, but it only works one command at a time, and I can't control its output to only show the summary field's content, it will show also the task commands.

I tried to manipulate --list output, adding \n to the text inside description field and throwing the result inside printf, something like this:

tasks:
  default:
    cmds:
      - printf "$(task --list | sed 's/\\n/\\n\\t/g')"

Which produced:

* terragrunt_apply:         Executes the terraform apply command.
          CI: executes terraform in non-interactive way. Default: false
         PLAN: executes terraform plan before apply. Default: false

But I don't want to go this path, I would rather rely on task to make this.. So can you help this use case?

Thanks in advance!

br-arruda avatar May 19 '25 07:05 br-arruda

@br-arruda you might like this

version: '3'

tasks:
  default:
    desc: |
      Multi line desc

      Second line
      Third line
    cmds:
      - echo "{{.GREETING}}"
    vars:
      FOO: bar
  one:
    desc: |
      One task.
    cmds:
      - echo "one"

  help:
    vars:
      TASKS:
        sh: task --list --json {{.TASKFILE}} | yq '.tasks[] | .name' -oy
    cmds:
      - for: { var: TASKS }
        task: help-task
        vars:
          TASK_NAME: '{{.ITEM}}'

  help-task:
    cmds:
      - echo {{.TASK_NAME}}
      - echo {{$l := len .TASK_NAME}}{{repeat $l "="}}
      - task --list --json {{.TASKFILE}} | yq '.tasks[] | select(.name == {{quote .TASK_NAME}}) | .desc' -oy

which yields:

$ task help -s
default
=======
Multi line desc

Second line
Third line

one
===
One task.

trulede avatar May 23 '25 21:05 trulede