match available formatters by prefix #31

Open
opened 2023-03-11 20:54:17 -06:00 by categulario · 2 comments
categulario commented 2023-03-11 20:54:17 -06:00 (Migrated from gitlab.com)

so that it's not necessary to write their entire name.

To implement this, a few things need to change:

Right now the selection of the formatter is done by parsing the argument given by command line matching for the exact name of a predefined formatter and if not, it is assumed that it is a custom formatter.

To match by prefix we would probably need to first collect all the available formatter's names (predefined and custom) as a sorted vector of strings and then try to match the best prefix, taking care that if the prefix is ambiguous we notify the user. All this code can probably live in formatters.rs.

The new matching mechanism has to be used in src/commands/display.rs:109 and the rest of the "display" family of commands (month, today, week, yesterday). Matching unit tests can be done on the matching function but at least one test would need to emulate the passing of the args from cli for every command that receives a --format argument.

Things to do:

  • what if a formatter has a name that is a prefix of some other formatter's name? (think csv and csv_better). Unit test for this.
  • unit test matching a prefix that exists (succes)
  • unit test matching a prefix that doesn't exist (existing error)
  • Unit test matching an ambiguous prefix (new error for this case)
  • integration test for display
  • integration test for month
  • integration test for today
  • integration test for week
  • integration test for yesterday

Further questions

  • Are we missing a way to list existing formatters? (like t f or t l --formatters)
so that it's not necessary to write their entire name. To implement this, a few things need to change: Right now the selection of the formatter is done by [parsing](https://gitlab.com/categulario/tiempo-rs/-/blob/main/src/formatters.rs#L57) the argument given by command line matching for the exact name of a predefined formatter and if not, it is assumed that it is a custom formatter. To match by prefix we would probably need to first collect all the available formatter's names (predefined and custom) as a sorted vector of strings and then try to match the best prefix, taking care that if the prefix is ambiguous we notify the user. All this code can probably live in `formatters.rs`. The new matching mechanism has to be used in `src/commands/display.rs:109` and the rest of the "display" family of commands (month, today, week, yesterday). Matching unit tests can be done on the matching function but at least one test would need to emulate the passing of the args from cli for every command that receives a `--format` argument. Things to do: * [ ] what if a formatter has a name that is a prefix of some other formatter's name? (think `csv` and `csv_better`). Unit test for this. * [ ] unit test matching a prefix that exists (succes) * [ ] unit test matching a prefix that doesn't exist (existing error) * [ ] Unit test matching an ambiguous prefix (new error for this case) * [ ] integration test for `display` * [ ] integration test for `month` * [ ] integration test for `today` * [ ] integration test for `week` * [ ] integration test for `yesterday` Further questions * Are we missing a way to list existing formatters? (like `t f` or `t l --formatters`)
categulario commented 2023-03-14 15:38:53 -06:00 (Migrated from gitlab.com)

changed the description

changed the description
categulario commented 2023-03-14 15:52:03 -06:00 (Migrated from gitlab.com)

changed the description

changed the description
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: categulario/tiempo-rs#31
No description provided.