Watson icon indicating copy to clipboard operation
Watson copied to clipboard

Feat: add a --format flag to the status command

Open EmileRolley opened this issue 4 years ago • 7 comments

Related PR: #445 Related project scope: cli Related 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.

EmileRolley avatar Jul 20 '21 14:07 EmileRolley

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?

jmaupetit avatar Jul 20 '21 15:07 jmaupetit

How do you plan to implement filters such as :short in 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"

EmileRolley avatar Jul 20 '21 15:07 EmileRolley

I meant how do you apply filters (or not) in the template compilation process?

jmaupetit avatar Jul 20 '21 16:07 jmaupetit

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).

EmileRolley avatar Jul 21 '21 07:07 EmileRolley

Sure, but we should define what short means :wink:

jmaupetit avatar Jul 21 '21 08:07 jmaupetit

Sure, but we should define what short means

Of course! It's certainly not the best name anyway.

EmileRolley avatar Jul 21 '21 15:07 EmileRolley

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.

vuvincent avatar Apr 12 '23 22:04 vuvincent