List experiment #2091
Labels
area: ui
Changes related to the UI of Task.
breaking change
Changes that are not backward compatible.
status: proposed
Experimental feature - Pending feedback on proposal.
Context
This is a proposal for a new API for the
--list
flag. It aims to unify the API for outputting tasks in a more consistent and intuitive way.Obviously, we cannot break the API for the existing
--list
flag in v3, so I am proposing that the new API go behind an experiment (i.e.TASK_X_LIST
). This will allow us to iterate and gather feedback on the design without worrying about breaking anything for existing users. The flag should come with a warning to users that it does not have a backward-compatible guarantee and should not be relied upon for scripts/CI. If the experiment is successful, then we could replace the existing--list
and--list-all
flags in a new major version release.We may also want to consider the naming of the flag itself. In this proposal I have continued to call the flag
--list
, but in theory this flag could be used to format/display all sorts of things (tasks, taskfiles, DAGs, Profiling Reports etc). Maybe a more generic name would be suitable. Some ideas below:--list
--query
This would also allow us to release the functionality in v3 since the change would not be breaking.
Design
This proposal has 3 main aims:
--list
flag.--list
flag.The following subsections describe the proposed API design in more detail:
Tags
tags
is a new field that can be added to a task. It allows the user to attach some arbitrary metadata to a task that can then be used later for filtering and grouping. Multiple tags can be specified per task:Filtering (
--filter
)Filtering allows the user to filter the list of tasks using task attributes. We can do this by supporting some basic wildcard functionality (or maybe regex?). The flag can be supplied multiple times to add more filters. These filters are applied in the order specified.
!
can be prefixed to a filter to negate its effect (i.e. it becomes an exclusion). Initial supported filtering attributes are:name
desc
tags
Example usage:
task --list --filter name=foo*
- Only lists tasks that start with "foo".task --list --filter name={foo,bar}*
- Only lists tasks whose names start with "foo" or "bar".task --list --filter !desc=
- Removes tasks with no description (matches the current--list
behavior).--filter !desc
for this.task --list --filter tags=foo
- Only lists tasks with the tag "foo".Sorting (
--sort
/--sort-by
)Not much change here. This will work the same way as it does now.
Example usage:
task --list --sort none
task --list --sort alphanumeric
However, we could add some additional sorting options:
task --list --sort alphanumeric --reverse
- Reverse the sort ordertask --list --sort-by desc
- Sort bydesc
instead ofname
Formatting (
--format
)Instead of having a separate flag for each format (we only have
--json
right now), we can use a single--format
flag that accepts a string. This will allow us to add new formats in the future without having to add new flags.Example usage:
task --list --format text
- defaulttask --list --format json
In addition to this, we could create an API for raw string formatting using templating:
task --list --format '{{.Name}} - [{{.Aliases}}]'
Quiet (
--quiet
)The current
--silent
flag is a bit of a misnomer. It doesn't silence the output, it just prints a non-formatted list. I propose that we follow the more conventional--quiet
flag for this style of unformatted list. See the Docker CLI as a reference.Example usage:
task --list --quiet
task --list -q
There is no reason this does not also apply to other uses of
silent
too (e.g. in the Taskfile or when calling tasks using--silent
)..taskrc.yml
In addition to the above flags. Users might find it useful to change the defaults for their project. We could use our new configuration file to achieve this rather than complicating the Taskfile schema:
Specifying a flag on the command line should override the
.taskrc.yml
settings.The text was updated successfully, but these errors were encountered: