From 09a35998c3913a7ee8782fce418bff40e7ac3782 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Sat, 25 Jan 2014 12:26:46 +0400 Subject: [PATCH] added another test for usage generation --- README.md | 19 +++++++++++++++++-- spec/usage_spec.lua | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2e83b39..0767a39 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Not everything stated here is implemented. Features: -* Declarative and usual interfaces. +* Declarative and classic interfaces. Declarative: @@ -21,7 +21,7 @@ Features: :count "*" ``` - Usual: + Classic: ```lua parser:argument("input", { @@ -66,3 +66,18 @@ Features: * Supports default values and automatic conversions for arguments. * Automatically generates error, usage and help(__NYI__) messages. * Supports commands(e.g. in [git](http://git-scm.com/) CLI `add`, `commit`, `push`, etc. are commands). Each command has its own set of options and arguments. +* Automatically generates tips on typos(__NYI__). + + Example: + + ```lua + parser:option "-f" "--from" + parser:command "install" + + parser:parse{"--form", "there"} + -- Error: unknown option --form + -- Did you mean --from? + + parser:parse{"isntall"} + -- Error: unknown command isntall + -- Did you mean install? diff --git a/spec/usage_spec.lua b/spec/usage_spec.lua index 6741197..c2b7967 100644 --- a/spec/usage_spec.lua +++ b/spec/usage_spec.lua @@ -48,6 +48,20 @@ describe("tests related to usage message generation", function() ) end) + it("creates correct usage message for subcommands", function() + local parser = argparse.parser "foo" + parser:flag "-q" "--quiet" + local run = parser:command "run" + run:option "--where" + + parser:prepare() + + assert.equal( + [=[Usage: foo run [--where ]]=], + run:prepare():get_usage() + ) + end) + describe("usage generation can be customized", function() it("uses message provided by user", function() local parser = argparse.parser "foo"