This repository was archived by the owner on Mar 25, 2024. It is now read-only.
Refactor command-line arguments parsing#118
Open
unclechu wants to merge 1 commit intosmallhadroncollider:developfrom
Open
Refactor command-line arguments parsing#118unclechu wants to merge 1 commit intosmallhadroncollider:developfrom
unclechu wants to merge 1 commit intosmallhadroncollider:developfrom
Conversation
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
```
Owner
|
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 A gentle reminder that this is still open. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
develop?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
--helpis 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.
--helpand-hare also handled automatically as a generic thing. No need to describe them separately.Initially I’ve tried to call
taskell --helpand got this in response: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: