GothenburgBitFactory / timewarrior

Timewarrior - Commandline Time Tracking and Reporting
https://timewarrior.net
MIT License
1.25k stars 94 forks source link

Tag order in CLI arguments is not preserved #621

Closed sebastiancarlos closed 2 months ago

sebastiancarlos commented 3 months ago
$ timew start "one" "two" "three" :yes
...
Note: 'one' is a new tag.
Note: 'three' is a new tag.
Note: 'two' is a new tag.
Tracking one three two
...
$ timew export | tail -n 2
{"id":1,"start":"20240703T145454Z","tags":["one","three","two"]}
]

It seems that the order is alphabetical. Feel free to close this ticket if you see no advantage in keeping the cli order, as I think the priority is maintaining backwards compatibility.

The reason I want this is because I want the first tag to always be the taskwarrior uuid, but it moves around depending on the first character.

smemsh commented 3 months ago

probably the tags should be thought of as a set, not a list, and their order not relied upon, but rather their presence.

lauft commented 2 months ago

@sebastiancarlos Just like @smemsh said, tags are implemented as a set, so the order is not guaranteed. I would be interested in your use case why you need the Taskwarrior UUID always at the first position... 🤔

sebastiancarlos commented 2 months ago

@lauft Got it, thanks.

My use case is that I want to:

Given that the tags are sets, I ended up prefixing the fields.

# on-modify.timewarrior
...
def extract_tags_from(json_obj):
    # Note: The tags are sorted alphabetically by timewarrior, so here they are
    # prefixed by the type of tag so they always appear in the same order in
    # the summary.

    # get first 8 characters of the UUID
    tags = [f'uuid:{json_obj["uuid"][:8]}']

    if 'project' in json_obj:
        # add projects a tag
        tags.append(f'project:{json_obj["project"]}')

    if 'ticket' in json_obj:
        # add ticket as a tag
        tags.append(f'ticket:{json_obj["ticket"]}')

    # append description as a tag
    tags.append(f'desc:{json_obj["description"]}')

    return tags
...