case-app
case-app copied to clipboard
Better help message
The help messages generated by case-app are currently rather raw. All the options are printed, without any grouping of related options, with no reflow of text depending on the terminal width, no colors, etc. For example:
$ cs launch --help
Command: launch
Usage: cs launch <org:name:version|app-name[:version]*>
--main-class | -M | --main <string>
--extra-jars <string*>
Extra JARs to be added to the classpath of the launched application. Directories accepted too.
--property | -D <key=value>
Set Java properties before launching the app
--fork <bool?>
…
(there's approx. ~70 options like this in this command!)
scopt or picocli could be used as sources of inspiration (there's probably many other libraries worth a look too…)
About implementing that, colors and reflow should just be a matter of changing some methods in Help
.
Grouping arguments is more tricky I think, and requires some changes in the typelevel core of case-app. In more detail, I believe it should be possible to group arguments, by
- adding a
val group: String = ""
argument toRecurse
, - adding a
recurse: HList
argument toHListParserBuilder.apply
, and passing itrecurse
around here, - adding a
group: List[String]
field toArg
, - adding a
group: Option[String]
field toRecursiveConsParser
, - in
HListParserBuilder.hconsRecursive
, we should be able to callrecurse.head
in a typesafe way, and passrecurse.head.group
toRecursiveConsParser
.
We should then adjust RecursiveConsParser.args
, so that it prepends its group (if it has one) to each of the Arg
s it returns.
Lastly, in Help
, we can then use the Arg.group
of its args
to group / show arguments however we want in the help message generated there. I didn't actually try to implement it, hopefully I didn't miss blockers along the way.
Users would then be able to group arguments like
case class Group1(arg: String = "", n: Int = 0)
case class Group2(other: String = "", m: Int = 0)
case class Options(
@Recurse("Group 1")
group1: Group1 = Group1(),
@Recurse("Group 2")
group2: Group2 = Group2()
)