Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Refactor command-line arguments parsing #118

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

unclechu
Copy link

@unclechu unclechu commented Feb 2, 2022

If appropriate:

  • Have you added new tests for additional functionality?

    Technically there are no additional functionality. I was aiming to not change any of the previous behavior (except fixing visible issue like --help is being interpreted as a file name). If it was parsing some pure data technically I can come up with a test but it would change the implementation quiet significantly. I can do this in a separate MR if you want me to.


Use “optparse-applicative” library. The parser is also the spec. The same code describes the arguments and parses them. Usage info is generated automatically from the parser. --help and -h are also handled automatically as a generic thing. No need to describe them separately.

Initially I’ve tried to call taskell --help and got this in response:

Create /home/wenzel/dev/haskell/taskell/--help? (Y/n):

Which confused me. I went to look at the code to see how the arguments parsing can be improved.

Usually you parse some pure data type out from command-line arguments. And then you decide what to do with that pure data. But I parsed monadic actions directly in order to keep this implementation close to the previous one.

An example of the auto-generated usage info:

$ result/bin/taskell --help
Taskell - A CLI kanban board/task manager

Usage: taskell [file | (-v|--version) | (-t|--trello <trello-board-id>) file |
                 (-g|--github [orgs/<org> | repos/<username>/<repo>]) file |
                 [-i|--info] file]

Available options:
  -h,--help                Show this help text
  -v,--version             Show version number
  -t,--trello <trello-board-id>
                           Create a new taskell file from the given Trello board
                           ID
  -g,--github [orgs/<org> | repos/<username>/<repo>]
                           Create a new taskell file from the given GitHub
                           identifier
  -i,--info                Display information about a file

Use “optparse-applicative” library.
The parser is also the spec. The same code describes the arguments and
parses them. Usage info is generated automatically from the parser.
`--help` and `-h` are also handled automatically as a generic thing.
No need to describe them separately.

Initially I’ve tried to call `taskell --help` and got this in response:

> Create /home/wenzel/dev/haskell/taskell/--help? (Y/n):

Which confused me. I went to look at the code to see how the arguments
parsing can be improved.

Usually you parse some pure data type out from command-line arguments.
And then you decide what to do with that pure data.
But I parsed monadic actions directly in order to keep this
implementation close to the previous one.

An example of the auto-generated usage info:

``` console
$ result/bin/taskell --help
Taskell - A CLI kanban board/task manager

Usage: taskell [file | (-v|--version) | (-t|--trello <trello-board-id>) file |
                 (-g|--github [orgs/<org> | repos/<username>/<repo>]) file |
                 [-i|--info] file]

Available options:
  -h,--help                Show this help text
  -v,--version             Show version number
  -t,--trello <trello-board-id>
                           Create a new taskell file from the given Trello board
                           ID
  -g,--github [orgs/<org> | repos/<username>/<repo>]
                           Create a new taskell file from the given GitHub
                           identifier
  -i,--info                Display information about a file
```
@unclechu unclechu changed the base branch from master to develop February 2, 2022 02:00
@smallhadroncollider
Copy link
Owner

smallhadroncollider commented Feb 3, 2022

This seems very sensible. The CLI parsing stuff was some of the earliest code I wrote – and this was my first Haskell project. I planned to use this in the v2 rewrite.

I'm just about to take a few weeks off in order to move house, so I may not be able to check this until next month.

@wenzel-hoffman
Copy link

wenzel-hoffman commented Sep 9, 2022

@smallhadroncollider A gentle reminder that this is still open.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants