go-task / task

A task runner / simpler Make alternative written in Go
https://taskfile.dev
MIT License
11.56k stars 618 forks source link

EXIT_CODE is empty when ignore_error:true #1826

Open officel opened 2 months ago

officel commented 2 months ago

In v3.39.2, EXIT_CODE seem to be empty if ignore_error: true. I would like the error message to be suppressed or EXIT_CODE to be passed.

somedir/Taskfile.yml

version: '3'
includes:
  base:
    taskfile: ~/Taskfile.yml
    flatten: true

tasks:
  description:
    desc: task description.
    aliases:
      - desc
    silent: true
    cmds:
      - date -I sec

I have multiple repository directories. I want to share the default task in a global Taskfile.

~/Taskfile.yml

version: '3'

tasks:
  default:
    summary: |
      default task is list tasks.
    cmds:
      # - defer: echo "exit code is {{.EXIT_CODE}}"
      - defer: '{{if .EXIT_CODE}} task --list-all --sort alphanumeric{{end}}'
      - cmd: task --list --sort alphanumeric
        # ignore_error: true
    dir: "{{.USER_WORKING_DIR}}"
    silent: true
    aliases:
      - ls
<ommit>

In some directory, there is a task with desc, so the execution result of task is --list.

In the home directory and in directories that use the global ~/Taskfile.yml, there are no tasks with desc, so the execution result of task should be --list-all.

in some dir

$ task
task: Available tasks for this project:
* description:       task description.      (aliases: desc)

in home dir

$ task
task: No tasks with description available. Try --list-all to list all tasks
task: Available tasks for this project:
* default:                            (aliases: ls)
* list-all:                           (aliases: la)
* test:special-variables:             (aliases: test:sv)
task: Failed to run task "default": exit status 1

in home dir and ignore_error: true. so .EXIT_CODE is empty

$ task
task: No tasks with description available. Try --list-all to list all tasks

any ideas?