taskell icon indicating copy to clipboard operation
taskell copied to clipboard

Refactor command-line arguments parsing

Open unclechu opened this issue 3 years ago • 2 comments

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

unclechu avatar Feb 02 '22 01:02 unclechu

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.

smallhadroncollider avatar Feb 03 '22 16:02 smallhadroncollider

@smallhadroncollider A gentle reminder that this is still open.

wenzel-hoffman avatar Sep 09 '22 02:09 wenzel-hoffman