Skip to content

Proposal: Add templating support for CLI flags list/list-all #2293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

trulede
Copy link
Contributor

@trulede trulede commented Jun 10, 2025

This is a proposal (code is finished) adding template support for CLI commands --list / --list-all. The implementation adds an optional flag (--template) which is used to specify a template file(s). When specified, the template files(s) are loaded and rendered. The templating mechanism makes use of slim-sprig functions.

Rational is to allow generation of documentation from Taskfiles, or provide custom formatting for these commands.

fixes #1695
fixes #2261
related #1916
related #931 (perhaps)
related #2091

If the proposal is welcome, then at least the following might also be of interest for this PR:

  • Documentation with examples.
  • Application to the --summary command.
  • Support template definition in the taskrc file.
  • Printing debug info during task execution, using some combination of previous items.
  • Additional tests.
  • Base templating on JSON data from (i.e. e.ToEditorOutput()). Perhaps?

Example

mddoc.template

# Taskfile
Available tasks for this project:
{{ range . }}
## {{.Task}}
{{.Desc}}
{{if len .Aliases}}
### Aliases
{{range .Aliases}}- {{.}}
{{end}}{{end}}{{end}}

Console Ouput

$ task --list-all --template mddoc.template
# Taskfile
Available tasks for this project:

## clean
Cleans temp files and folders

### Aliases
- clear

## default


## format
Runs golangci-lint and formats any Go files

### Aliases
- fmt
- f

## generate
Runs all generate tasks

### Aliases
- gen
- g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to disable output of commands in summary Generate documentation based on your taskfile
1 participant