From 6ca0662862dffcc67ff4016aaa04cf314d81608e Mon Sep 17 00:00:00 2001 From: defanor Date: Sat, 16 Dec 2017 06:11:12 +0300 Subject: Generate usage strings for help messages --- README.md | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index bcefff4..cb38e87 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ while keeping them language-agnostic and more user- and shell scripting-friendly than JSON and similar formats. Given a type, it derives instances to print and parse it as -command-line arguments. The resulting deserialization wouldn't be as -nice as that of +command-line arguments, as well as to compose usage instructions. The +resulting deserialization wouldn't be as nice as that of e.g. [optparse-generic](https://hackage.haskell.org/package/optparse-generic), but the aim here is to handle more or less arbitrary types. @@ -46,6 +46,12 @@ What would look like this in a shell: --foobar foo 1 'a string' bar ``` +And its usage string -- like this: + +``` +[--something STRING] [--foobar (foo INT STRING | bar)] (foo INT STRING | bar) +``` + More verbose versions can be produced and parsed with `alwaysUseSelName = True` and/or `omitNamedOptions = False`: @@ -54,3 +60,33 @@ More verbose versions can be produced and parsed with nothing just foo 1 'a string' bar --something nothing --foobar just foo --arg1 1 --arg2 'a string' --foobar2 bar ``` + +And here is output of the `help` function from the same file, with all +the (alwaysUseSelName, omitNamedOptions) combinations: + +``` +(True,True) +["--foo","[]","--bar","a string"] +--foo ([] | : INT ([] | :...)) [--bar STRING] +(True,True) +["--foo","[]"] +--foo ([] | : INT ([] | :...)) [--bar STRING] +(True,False) +["--foo","[]","--bar","just","a string"] +--foo ([] | : INT ([] | :...)) --bar (nothing | just STRING) +(True,False) +["--foo","[]","--bar","nothing"] +--foo ([] | : INT ([] | :...)) --bar (nothing | just STRING) +(False,True) +["[]","--bar","a string"] +([] | : INT ([] | :...)) [--bar STRING] +(False,True) +["[]"] +([] | : INT ([] | :...)) [--bar STRING] +(False,False) +["[]","just","a string"] +([] | : INT ([] | :...)) (nothing | just STRING) +(False,False) +["[]","nothing"] +([] | : INT ([] | :...)) (nothing | just STRING) +``` -- cgit v1.2.3