Feat: add a --format flag to the status command
Related PR: #445 Related project scope:
cliRelated user: @jmaupetit
The problem
I wanted to use the status command output with other tools such as starship. Unfortunately, the current output format does not correspond to my needs.
Consequently, I added a --compact flag in #445, but @jmaupetit smartly pointed out the fact that it would more convenient to have a generic way to format the outputs.
Wanted solution
Examples of the wanted --format flag usage:
> watson status --format "{{ project }} {{ elpased:short }}"
my-project 79m
> watson status --format "{{ project }} started {{ elpased }}"
my-project started one hour and 19 minutes ago
> watson status --format "Project: {{ project }}, tags: {{ tags }}"
Project: my-project, tags: tag1, tag2
Interrogation
As @jmaupetit noted in https://github.com/TailorDev/Watson/issues/445#issuecomment-883389799:
One should define what should be in the context to "compile" the format template.
The context should be restricted to:
- the project
- assigned tags
- elapsed time
How do you plan to implement filters such as :short in your example?
How do you plan to implement filters such as
:shortin your example?
It can be done by reusing what I did in #445:
elapsedtime = (current['start']).humanize(only_distance=True,
granularity="minute")
elapsedtime = elapsedtime.split()[0] + "m"
I meant how do you apply filters (or not) in the template compilation process?
I meant how do you apply filters (or not) in the template compilation process?
I haven't thought about the compilation process yet.. Indeed, I'm not familiar with it. Nevertheless, I think filter usage could be avoided by extending the context (e.g. elapsed_short).
Sure, but we should define what short means :wink:
Sure, but we should define what
shortmeans
Of course! It's certainly not the best name anyway.
hey guys! I'm interested in the --format option as well.
I was thinking instead of using general directives like short for the time elapsed field, we could use directives to extract the time parts instead e.g:
> watson status --format "{{ project }} {{ elapsed:hour-part }}h {{ elapsed:minute-part }}m {{ elapsed:second-part }}s"
my-project 1h 16m 4s
or if you want the elapsed time fully in a certain unit:
> watson status --format "{{ project }} {{ elapsed:minutes }}m"
my-project 76m
and if the user doesn't put any directives it returns the default humanized version.
Let me know what you think and I'm available to give it a shot.