Skip to content

Add templating support to CLI flags list/list-all #2348

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

timrulebosch
Copy link

This PR is 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 the existing slim-sprig functions available in Task.

Primary motivation for the PR is to generate documentation for a library of Taskfiles. Some of the documentation can be extracted from the existing Taskfile schema, and other elements of the documentation are embedded in the Taskfiles. This later embedded documentation (example here) would be made available to the templating mechanism as well (PR in development).

As it currently stands, the PR replaces the --list code (a for loop) with the templating mechanism.

Example

mddoc.template

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

Console Output

$ 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

Notes:

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

Outstanding items needed to complete PR:

  • Refinement of operation - e.g. relationship between list list-all and template CLI options.
  • Documentation with examples.
  • Application to the --summary command?
  • Support template definition in the taskrc file.?

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