From e43b2a00c08db45e1ac52d806f7e7f402bda6627 Mon Sep 17 00:00:00 2001 From: Giovanni Bassi Date: Wed, 14 Oct 2015 21:42:05 -0300 Subject: [PATCH] Add docopt See more about docopt at http://docopt.org/ This is specific for the library at https://www.npmjs.com/package/docopt --- docopt/docopt-tests.ts | 11 +++++++++++ docopt/docopt.d.ts | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 docopt/docopt-tests.ts create mode 100644 docopt/docopt.d.ts diff --git a/docopt/docopt-tests.ts b/docopt/docopt-tests.ts new file mode 100644 index 000000000..b8c1a2c25 --- /dev/null +++ b/docopt/docopt-tests.ts @@ -0,0 +1,11 @@ +/// +/// + +var doc = ` +Usage: + quick_example.coffee tcp [--timeout=] + quick_example.coffee serial [--baud=9600] [--timeout=] + quick_example.coffee -h | --help | --version +`; +var {docopt} = require('docopt'); +console.log(docopt(doc, { version: '0.1.1rc' })); diff --git a/docopt/docopt.d.ts b/docopt/docopt.d.ts new file mode 100644 index 000000000..ea2330a19 --- /dev/null +++ b/docopt/docopt.d.ts @@ -0,0 +1,23 @@ +// Type definitions for Docopt v0.6.2 +// Project: http://docopt.org/ +// Definitions by: Giovanni Bassi +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface DocoptOption { + /** is an optional argument vector. It defaults to the arguments passed to your program (process.argv[2..]). You can also supply it with an array of strings, as with process.argv. For example: ['--verbose', '-o', 'hai.txt'] */ + argv?: Array, + /** (default:true) specifies whether the parser should automatically print the help message (supplied as doc) in case -h or --help options are encountered. After showing the usage-message, the program will terminate. If you want to handle -h or --help options manually (the same as other options), set help=false. */ + help?: boolean, + /** (default:null) is an optional argument that specifies the version of your program. If supplied, then, if the parser encounters --version option, it will print the supplied version and terminate. version could be any printable object, but most likely a string, e.g. '2.1.0rc1'. */ + version?: any, + /** (default false) If set to true will disallow mixing options and positional argument. I.e. after first positional argument, all arguments will be interpreted as positional even if the look like options. This can be used for strict compatibility with POSIX, or if you want to dispatch your arguments to other programs. */ + options_first?: boolean, + /** (default true) If set to false will cause docopt to throw exceptions instead of printing the error to console and terminating the application. This flag is mainly for testing purposes. */ + exit?: boolean +} +declare module "docopt" { + /** + * @param doc should be a string with the help message, written according to rules of the docopt language. + */ + export function docopt(doc: string, options: DocoptOption): any; +}