infeeeee / kimai2-cmd

Command line client for Kimai2, the open source, self-hosted time tracker
MIT License
24 stars 6 forks source link

Add interactive "start" when the project or activity are not mentioned #28

Open eliandoran opened 2 years ago

eliandoran commented 2 years ago

Greetings @infeeeee,

First, I find this CLI tool to be great and I would like to use it in my daily routine. However, to be personally more efficient I thought to start an activity faster directly from the CLI.

If the user knows the project and activity to start, they can use this:

$ kimai2-cmd start [project] [activity]

However, there are two different cases which are not currently covered by this command.

Interactive selection of the activity

At work it is usually more convenient to select the activity from a list but to prefill the project, as such:

$ kimai2-cmd start [project]

Attempting to do this at the moment will result in an exception:

npm run start start "Sandbox"                                                                                                                      

> kimai2-cmd@1.3.1 start
> node kimai2-cmd.js "start" "Sandbox"

/home/elian/Projects/kimai2-cmd/kimai2-cmd.js:336
                   if (element.name.toLowerCase() == name.toLowerCase()) {
                                                          ^

TypeError: Cannot read properties of undefined (reading 'toLowerCase')
   at /home/elian/Projects/kimai2-cmd/kimai2-cmd.js:336:60
   at processTicksAndRejections (node:internal/process/task_queues:96:5)

Node.js v17.7.2

After this PR, the user is taken straight to the activity list (equivalent to kimai2-cmd -> "Start new measurement" -> select the project).

Interactive selection of the project

If the user is extra lazy and simply wants to start an activity, but without knowing the project or the activity:

$ kimai2-cmd start [project]

At the moment, this results in an exception:

> kimai2-cmd@1.3.1 start
> node kimai2-cmd.js "start"

/home/elian/Projects/kimai2-cmd/kimai2-cmd.js:340
                    if (element.name.toLowerCase() == name.toLowerCase()) {
                                                           ^

TypeError: Cannot read properties of undefined (reading 'toLowerCase')
    at /home/elian/Projects/kimai2-cmd/kimai2-cmd.js:340:60
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Node.js v17.7.2

After this PR, the user is simply sent to the normal UI workflow for starting an activity (select project, then select activity).

Motivation

As mentioned previously, this can save the user for a few keystrokes. This is especially useful when the user does not have many projects or has a specific schedule. I want to use this at work to save a few keystrokes (since I usually have ~16 activities for an 8-hours workday).

If this modification does not fit your expectations for the classic CLI (especially since we are mixing the classic CLI with the interactive one), feel free to tell me. I have also tried to keep the modifications to the code as minimal as possible.

infeeeee commented 2 years ago

Woah, seems nice, thank you!

I will take a more in-depth look in the following days.

I don't use kimai nowadays, so if you have other ideas you want to implement feel free to create PRs.

eliandoran commented 2 years ago

Thank you, @infeeeee . Let me know if it's OK for you. I will probably want to do some more similar changes to the stop command as well, will keep you posted.

If I may, did you switch to some other time tracking solution? Or do you no longer need to track your time?

infeeeee commented 2 years ago

I started to work at a company, I'm not self employed any more, I used kimai alone. I'm trying to convince the company to switch to kimai, but they are not ready yet.

I also don't code in js anymore, switched to python nowadays for projects like this.