summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md15
-rw-r--r--colors/README.md8
-rw-r--r--examples/README.md2
-rw-r--r--flags/README.md37
-rwxr-xr-xflags/tests/all_bool.ts44
-rwxr-xr-xflags/tests/bool.ts254
-rwxr-xr-xflags/tests/dash.ts29
-rwxr-xr-xflags/tests/default_bool.ts43
-rwxr-xr-xflags/tests/dotted.ts19
-rwxr-xr-xflags/tests/kv_short.ts8
-rwxr-xr-xflags/tests/long.ts33
-rwxr-xr-xflags/tests/num.ts57
-rw-r--r--flags/tests/parse.ts290
-rwxr-xr-xflags/tests/short.ts77
-rwxr-xr-xflags/tests/stop_early.ts14
-rwxr-xr-xflags/tests/unknown.ts150
-rwxr-xr-xflags/tests/whitespace.ts2
-rwxr-xr-xformat.ts2
-rw-r--r--logging/README.md11
-rw-r--r--logging/handlers/console.ts44
-rw-r--r--path/README.md2
21 files changed, 570 insertions, 571 deletions
diff --git a/README.md b/README.md
index 1aa6eb5d6..74043c3e2 100644
--- a/README.md
+++ b/README.md
@@ -5,13 +5,14 @@
This repository contains collections of modules that create a standard library
for Deno.
-| Collection | Description |
-| ---------------------------- | --------------------------------------------------------------- |
-| [colors](./colors/) | Modules that generate ANSI color codes for the console. |
-| [net](./net/) | A framework for creating HTTP/HTTPS servers inspired by GoLang. |
-| [path](./path/) | File path manipulation. |
-| [flags](./flags/) | Command line arguments parser. |
-| [logging](./logging/) | Command line logging |
+| Collection | Description |
+| --------------------- | --------------------------------------------------------------- |
+| [colors](./colors/) | Modules that generate ANSI color codes for the console. |
+| [net](./net/) | A framework for creating HTTP/HTTPS servers inspired by GoLang. |
+| [path](./path/) | File path manipulation. |
+| [flags](./flags/) | Command line arguments parser. |
+| [logging](./logging/) | Command line logging |
+
---
Copyright 2018 the Deno authors. All rights reserved. MIT license.
diff --git a/colors/README.md b/colors/README.md
index f20d1939a..bdaa3d51e 100644
--- a/colors/README.md
+++ b/colors/README.md
@@ -6,8 +6,8 @@ inspired by packages like [chalk](https://www.npmjs.com/package/chalk) and
## Usage
-The main modules exports a single function name `color` which is a function
-that provides chaining to stack colors. Basic usage looks like this:
+The main modules exports a single function name `color` which is a function that
+provides chaining to stack colors. Basic usage looks like this:
```ts
import { color } from "https://deno.land/x/colors/main.ts";
@@ -18,8 +18,8 @@ console.log(color.bgBlue.red.bold("Hello world!"));
## TODO
- Currently, it just assumes it is running in an environment that supports ANSI
- escape code terminal coloring. It should actually detect, specifically
- windows and adjust properly.
+ escape code terminal coloring. It should actually detect, specifically windows
+ and adjust properly.
- Test coverage is very basic at the moment.
diff --git a/examples/README.md b/examples/README.md
index 2e920f479..874626ec4 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -3,6 +3,7 @@
These files are accessible for import via "https://deno.land/x/examples/".
Try it:
+
```
> deno https://deno.land/x/examples/gist.ts README.md
```
@@ -10,6 +11,7 @@ Try it:
## Alias Based Installation
Add this to your `.bash_profile`
+
```
export GIST_TOKEN=ABC # Generate at https://github.com/settings/tokens
alias gist="deno https://deno.land/x/examples/gist.ts --allow-net --allow-env"
diff --git a/flags/README.md b/flags/README.md
index 4afda374c..9d09a2210 100644
--- a/flags/README.md
+++ b/flags/README.md
@@ -4,7 +4,7 @@ Command line arguments parser for Deno based on minimist
# Example
-``` ts
+```ts
import { args } from "deno";
import { parse } from "https://deno.land/x/flags/index.ts";
@@ -32,8 +32,8 @@ $ deno example.ts -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
## const parsedArgs = parse(args, options = {});
-`parsedArgs._` contains all the arguments that didn't have an option associated with
-them.
+`parsedArgs._` contains all the arguments that didn't have an option associated
+with them.
Numeric-looking arguments will be returned as numbers unless `options.string` or
`options.boolean` is set for that argument name.
@@ -42,18 +42,19 @@ Any arguments after `'--'` will not be parsed and will end up in `parsedArgs._`.
options can be:
-* `options.string` - a string or array of strings argument names to always treat as
-strings
-* `options.boolean` - a boolean, string or array of strings to always treat as
-booleans. if `true` will treat all double hyphenated arguments without equal signs
-as boolean (e.g. affects `--foo`, not `-f` or `--foo=bar`)
-* `options.alias` - an object mapping string names to strings or arrays of string
-argument names to use as aliases
-* `options.default` - an object mapping string argument names to default values
-* `options.stopEarly` - when true, populate `parsedArgs._` with everything after the
-first non-option
-* `options['--']` - when true, populate `parsedArgs._` with everything before the `--`
-and `parsedArgs['--']` with everything after the `--`. Here's an example:
-* `options.unknown` - a function which is invoked with a command line parameter not
-defined in the `options` configuration object. If the function returns `false`, the
-unknown option is not added to `parsedArgs`.
+- `options.string` - a string or array of strings argument names to always treat
+ as strings
+- `options.boolean` - a boolean, string or array of strings to always treat as
+ booleans. if `true` will treat all double hyphenated arguments without equal
+ signs as boolean (e.g. affects `--foo`, not `-f` or `--foo=bar`)
+- `options.alias` - an object mapping string names to strings or arrays of
+ string argument names to use as aliases
+- `options.default` - an object mapping string argument names to default values
+- `options.stopEarly` - when true, populate `parsedArgs._` with everything after
+ the first non-option
+- `options['--']` - when true, populate `parsedArgs._` with everything before
+ the `--` and `parsedArgs['--']` with everything after the `--`. Here's an
+ example:
+- `options.unknown` - a function which is invoked with a command line parameter
+ not defined in the `options` configuration object. If the function returns
+ `false`, the unknown option is not added to `parsedArgs`.
diff --git a/flags/tests/all_bool.ts b/flags/tests/all_bool.ts
index aaa936bf6..879de5cc0 100755
--- a/flags/tests/all_bool.ts
+++ b/flags/tests/all_bool.ts
@@ -3,30 +3,30 @@ import { parse } from "../index.ts";
// flag boolean true (default all --args to boolean)
test(function flagBooleanTrue() {
- const argv = parse(['moo', '--honk', 'cow'], {
- boolean: true
- });
-
- assertEqual(argv, {
- honk: true,
- _: ['moo', 'cow']
- });
-
- assertEqual(typeof argv.honk, 'boolean');
+ const argv = parse(["moo", "--honk", "cow"], {
+ boolean: true
+ });
+
+ assertEqual(argv, {
+ honk: true,
+ _: ["moo", "cow"]
+ });
+
+ assertEqual(typeof argv.honk, "boolean");
});
// flag boolean true only affects double hyphen arguments without equals signs
test(function flagBooleanTrueOnlyAffectsDoubleDash() {
- var argv = parse(['moo', '--honk', 'cow', '-p', '55', '--tacos=good'], {
- boolean: true
- });
-
- assertEqual(argv, {
- honk: true,
- tacos: 'good',
- p: 55,
- _: ['moo', 'cow']
- });
-
- assertEqual(typeof argv.honk, 'boolean');
+ var argv = parse(["moo", "--honk", "cow", "-p", "55", "--tacos=good"], {
+ boolean: true
+ });
+
+ assertEqual(argv, {
+ honk: true,
+ tacos: "good",
+ p: 55,
+ _: ["moo", "cow"]
+ });
+
+ assertEqual(typeof argv.honk, "boolean");
});
diff --git a/flags/tests/bool.ts b/flags/tests/bool.ts
index eae3df23c..ee4f5e1c3 100755
--- a/flags/tests/bool.ts
+++ b/flags/tests/bool.ts
@@ -2,157 +2,157 @@ import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
import { parse } from "../index.ts";
test(function flagBooleanDefaultFalse() {
- const argv = parse(['moo'], {
- boolean: ['t', 'verbose'],
- default: { verbose: false, t: false }
- });
-
- assertEqual(argv, {
- verbose: false,
- t: false,
- _: ['moo']
- });
-
- assertEqual(typeof argv.verbose, 'boolean');
- assertEqual(typeof argv.t, 'boolean');
+ const argv = parse(["moo"], {
+ boolean: ["t", "verbose"],
+ default: { verbose: false, t: false }
+ });
+
+ assertEqual(argv, {
+ verbose: false,
+ t: false,
+ _: ["moo"]
+ });
+
+ assertEqual(typeof argv.verbose, "boolean");
+ assertEqual(typeof argv.t, "boolean");
});
test(function booleanGroups() {
- const argv = parse([ '-x', '-z', 'one', 'two', 'three' ], {
- boolean: ['x','y','z']
- });
-
- assertEqual(argv, {
- x : true,
- y : false,
- z : true,
- _ : [ 'one', 'two', 'three' ]
- });
-
- assertEqual(typeof argv.x, 'boolean');
- assertEqual(typeof argv.y, 'boolean');
- assertEqual(typeof argv.z, 'boolean');
+ const argv = parse(["-x", "-z", "one", "two", "three"], {
+ boolean: ["x", "y", "z"]
+ });
+
+ assertEqual(argv, {
+ x: true,
+ y: false,
+ z: true,
+ _: ["one", "two", "three"]
+ });
+
+ assertEqual(typeof argv.x, "boolean");
+ assertEqual(typeof argv.y, "boolean");
+ assertEqual(typeof argv.z, "boolean");
});
test(function booleanAndAliasWithChainableApi() {
- const aliased = [ '-h', 'derp' ];
- const regular = [ '--herp', 'derp' ];
- const opts = {
- herp: { alias: 'h', boolean: true }
- };
- const aliasedArgv = parse(aliased, {
- boolean: 'herp',
- alias: { h: 'herp' }
- });
- const propertyArgv = parse(regular, {
- boolean: 'herp',
- alias: { h: 'herp' }
- });
- const expected = {
- herp: true,
- h: true,
- '_': [ 'derp' ]
- };
-
- assertEqual(aliasedArgv, expected);
- assertEqual(propertyArgv, expected);
+ const aliased = ["-h", "derp"];
+ const regular = ["--herp", "derp"];
+ const opts = {
+ herp: { alias: "h", boolean: true }
+ };
+ const aliasedArgv = parse(aliased, {
+ boolean: "herp",
+ alias: { h: "herp" }
+ });
+ const propertyArgv = parse(regular, {
+ boolean: "herp",
+ alias: { h: "herp" }
+ });
+ const expected = {
+ herp: true,
+ h: true,
+ _: ["derp"]
+ };
+
+ assertEqual(aliasedArgv, expected);
+ assertEqual(propertyArgv, expected);
});
test(function booleanAndAliasWithOptionsHash() {
- const aliased = [ '-h', 'derp' ];
- const regular = [ '--herp', 'derp' ];
- const opts = {
- alias: { 'h': 'herp' },
- boolean: 'herp'
- };
- const aliasedArgv = parse(aliased, opts);
- const propertyArgv = parse(regular, opts);
- const expected = {
- herp: true,
- h: true,
- '_': [ 'derp' ]
- };
- assertEqual(aliasedArgv, expected);
- assertEqual(propertyArgv, expected);
+ const aliased = ["-h", "derp"];
+ const regular = ["--herp", "derp"];
+ const opts = {
+ alias: { h: "herp" },
+ boolean: "herp"
+ };
+ const aliasedArgv = parse(aliased, opts);
+ const propertyArgv = parse(regular, opts);
+ const expected = {
+ herp: true,
+ h: true,
+ _: ["derp"]
+ };
+ assertEqual(aliasedArgv, expected);
+ assertEqual(propertyArgv, expected);
});
test(function booleanAndAliasArrayWithOptionsHash() {
- const aliased = [ '-h', 'derp' ];
- const regular = [ '--herp', 'derp' ];
- const alt = [ '--harp', 'derp' ];
- const opts = {
- alias: { 'h': ['herp', 'harp'] },
- boolean: 'h'
- };
- const aliasedArgv = parse(aliased, opts);
- const propertyArgv = parse(regular, opts);
- const altPropertyArgv = parse(alt, opts);
- const expected = {
- harp: true,
- herp: true,
- h: true,
- '_': [ 'derp' ]
- };
- assertEqual(aliasedArgv, expected);
- assertEqual(propertyArgv, expected);
- assertEqual(altPropertyArgv, expected);
+ const aliased = ["-h", "derp"];
+ const regular = ["--herp", "derp"];
+ const alt = ["--harp", "derp"];
+ const opts = {
+ alias: { h: ["herp", "harp"] },
+ boolean: "h"
+ };
+ const aliasedArgv = parse(aliased, opts);
+ const propertyArgv = parse(regular, opts);
+ const altPropertyArgv = parse(alt, opts);
+ const expected = {
+ harp: true,
+ herp: true,
+ h: true,
+ _: ["derp"]
+ };
+ assertEqual(aliasedArgv, expected);
+ assertEqual(propertyArgv, expected);
+ assertEqual(altPropertyArgv, expected);
});
test(function booleanAndAliasUsingExplicitTrue() {
- const aliased = [ '-h', 'true' ];
- const regular = [ '--herp', 'true' ];
- const opts = {
- alias: { h: 'herp' },
- boolean: 'h'
- };
- const aliasedArgv = parse(aliased, opts);
- const propertyArgv = parse(regular, opts);
- const expected = {
- herp: true,
- h: true,
- '_': [ ]
- };
-
- assertEqual(aliasedArgv, expected);
- assertEqual(propertyArgv, expected);
+ const aliased = ["-h", "true"];
+ const regular = ["--herp", "true"];
+ const opts = {
+ alias: { h: "herp" },
+ boolean: "h"
+ };
+ const aliasedArgv = parse(aliased, opts);
+ const propertyArgv = parse(regular, opts);
+ const expected = {
+ herp: true,
+ h: true,
+ _: []
+ };
+
+ assertEqual(aliasedArgv, expected);
+ assertEqual(propertyArgv, expected);
});
// regression, see https://github.com/substack/node-optimist/issues/71
// boolean and --x=true
test(function booleanAndNonBoolean() {
- const parsed = parse(['--boool', '--other=true'], {
- boolean: 'boool'
- });
-
- assertEqual(parsed.boool, true);
- assertEqual(parsed.other, 'true');
-
- const parsed2 = parse(['--boool', '--other=false'], {
- boolean: 'boool'
- });
-
- assertEqual(parsed2.boool, true);
- assertEqual(parsed2.other, 'false');
+ const parsed = parse(["--boool", "--other=true"], {
+ boolean: "boool"
+ });
+
+ assertEqual(parsed.boool, true);
+ assertEqual(parsed.other, "true");
+
+ const parsed2 = parse(["--boool", "--other=false"], {
+ boolean: "boool"
+ });
+
+ assertEqual(parsed2.boool, true);
+ assertEqual(parsed2.other, "false");
});
test(function booleanParsingTrue() {
- const parsed = parse(['--boool=true'], {
- default: {
- boool: false
- },
- boolean: ['boool']
- });
-
- assertEqual(parsed.boool, true);
+ const parsed = parse(["--boool=true"], {
+ default: {
+ boool: false
+ },
+ boolean: ["boool"]
+ });
+
+ assertEqual(parsed.boool, true);
});
test(function booleanParsingFalse() {
- const parsed = parse(['--boool=false'], {
- default: {
- boool: true
- },
- boolean: ['boool']
- });
-
- assertEqual(parsed.boool, false);
+ const parsed = parse(["--boool=false"], {
+ default: {
+ boool: true
+ },
+ boolean: ["boool"]
+ });
+
+ assertEqual(parsed.boool, false);
});
diff --git a/flags/tests/dash.ts b/flags/tests/dash.ts
index 5a55372c2..2008cce43 100755
--- a/flags/tests/dash.ts
+++ b/flags/tests/dash.ts
@@ -2,27 +2,22 @@ import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
import { parse } from "../index.ts";
test(function hyphen() {
- assertEqual(parse([ '-n', '-' ]), { n: '-', _: [] });
- assertEqual(parse([ '-' ]), { _: [ '-' ] });
- assertEqual(parse([ '-f-' ]), { f: '-', _: [] });
- assertEqual(
- parse([ '-b', '-' ], { boolean: 'b' }),
- { b: true, _: [ '-' ] }
- );
- assertEqual(
- parse([ '-s', '-' ], { string: 's' }),
- { s: '-', _: [] }
- );
+ assertEqual(parse(["-n", "-"]), { n: "-", _: [] });
+ assertEqual(parse(["-"]), { _: ["-"] });
+ assertEqual(parse(["-f-"]), { f: "-", _: [] });
+ assertEqual(parse(["-b", "-"], { boolean: "b" }), { b: true, _: ["-"] });
+ assertEqual(parse(["-s", "-"], { string: "s" }), { s: "-", _: [] });
});
test(function doubleDash() {
- assertEqual(parse([ '-a', '--', 'b' ]), { a: true, _: [ 'b' ] });
- assertEqual(parse([ '--a', '--', 'b' ]), { a: true, _: [ 'b' ] });
- assertEqual(parse([ '--a', '--', 'b' ]), { a: true, _: [ 'b' ] });
+ assertEqual(parse(["-a", "--", "b"]), { a: true, _: ["b"] });
+ assertEqual(parse(["--a", "--", "b"]), { a: true, _: ["b"] });
+ assertEqual(parse(["--a", "--", "b"]), { a: true, _: ["b"] });
});
test(function moveArgsAfterDoubleDashIntoOwnArray() {
- assertEqual(
- parse([ '--name', 'John', 'before', '--', 'after' ], { '--': true }),
- { name: 'John', _: [ 'before' ], '--': [ 'after' ] });
+ assertEqual(
+ parse(["--name", "John", "before", "--", "after"], { "--": true }),
+ { name: "John", _: ["before"], "--": ["after"] }
+ );
});
diff --git a/flags/tests/default_bool.ts b/flags/tests/default_bool.ts
index 954ab2838..b43c52e8d 100755
--- a/flags/tests/default_bool.ts
+++ b/flags/tests/default_bool.ts
@@ -2,31 +2,30 @@ import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
import { parse } from "../index.ts";
test(function booleanDefaultTrue() {
- const argv = parse([], {
- boolean: 'sometrue',
- default: { sometrue: true }
- });
- assertEqual(argv.sometrue, true);
+ const argv = parse([], {
+ boolean: "sometrue",
+ default: { sometrue: true }
+ });
+ assertEqual(argv.sometrue, true);
});
test(function booleanDefaultFalse() {
- const argv = parse([], {
- boolean: 'somefalse',
- default: { somefalse: false }
- });
- assertEqual(argv.somefalse, false);
+ const argv = parse([], {
+ boolean: "somefalse",
+ default: { somefalse: false }
+ });
+ assertEqual(argv.somefalse, false);
});
test(function booleanDefaultNull() {
- const argv = parse([], {
- boolean: 'maybe',
- default: { maybe: null }
- });
- assertEqual(argv.maybe, null);
- const argv2 = parse(['--maybe'], {
- boolean: 'maybe',
- default: { maybe: null }
- });
- assertEqual(argv2.maybe, true);
-
-})
+ const argv = parse([], {
+ boolean: "maybe",
+ default: { maybe: null }
+ });
+ assertEqual(argv.maybe, null);
+ const argv2 = parse(["--maybe"], {
+ boolean: "maybe",
+ default: { maybe: null }
+ });
+ assertEqual(argv2.maybe, true);
+});
diff --git a/flags/tests/dotted.ts b/flags/tests/dotted.ts
index 68f8d63c8..03f72dc83 100755
--- a/flags/tests/dotted.ts
+++ b/flags/tests/dotted.ts
@@ -2,18 +2,21 @@ import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
import { parse } from "../index.ts";
test(function dottedAlias() {
- const argv = parse(['--a.b', '22'], {default: {'a.b': 11}, alias: {'a.b': 'aa.bb'}});
- assertEqual(argv.a.b, 22);
- assertEqual(argv.aa.bb, 22);
+ const argv = parse(["--a.b", "22"], {
+ default: { "a.b": 11 },
+ alias: { "a.b": "aa.bb" }
+ });
+ assertEqual(argv.a.b, 22);
+ assertEqual(argv.aa.bb, 22);
});
test(function dottedDefault() {
- const argv = parse('', {default: {'a.b': 11}, alias: {'a.b': 'aa.bb'}});
- assertEqual(argv.a.b, 11);
- assertEqual(argv.aa.bb, 11);
+ const argv = parse("", { default: { "a.b": 11 }, alias: { "a.b": "aa.bb" } });
+ assertEqual(argv.a.b, 11);
+ assertEqual(argv.aa.bb, 11);
});
test(function dottedDefaultWithNoAlias() {
- const argv = parse('', {default: {'a.b': 11}});
- assertEqual(argv.a.b, 11);
+ const argv = parse("", { default: { "a.b": 11 } });
+ assertEqual(argv.a.b, 11);
});
diff --git a/flags/tests/kv_short.ts b/flags/tests/kv_short.ts
index 545f722bd..93aa76387 100755
--- a/flags/tests/kv_short.ts
+++ b/flags/tests/kv_short.ts
@@ -2,11 +2,11 @@ import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
import { parse } from "../index.ts";
test(function short() {
- const argv = parse([ '-b=123' ]);
- assertEqual(argv, { b: 123, _: [] });
+ const argv = parse(["-b=123"]);
+ assertEqual(argv, { b: 123, _: [] });
});
test(function multiShort() {
- const argv = parse([ '-a=whatever', '-b=robots' ]);
- assertEqual(argv, { a: 'whatever', b: 'robots', _: [] });
+ const argv = parse(["-a=whatever", "-b=robots"]);
+ assertEqual(argv, { a: "whatever", b: "robots", _: [] });
});
diff --git a/flags/tests/long.ts b/flags/tests/long.ts
index 5a8cbf6c8..57e48ecbe 100755
--- a/flags/tests/long.ts
+++ b/flags/tests/long.ts
@@ -2,24 +2,17 @@ import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
import { parse } from "../index.ts";
test(function longOpts() {
- assertEqual(
- parse([ '--bool' ]),
- { bool : true, _ : [] },
- );
- assertEqual(
- parse([ '--pow', 'xixxle' ]),
- { pow : 'xixxle', _ : [] },
- );
- assertEqual(
- parse([ '--pow=xixxle' ]),
- { pow : 'xixxle', _ : [] },
- );
- assertEqual(
- parse([ '--host', 'localhost', '--port', '555' ]),
- { host : 'localhost', port : 555, _ : [] },
- );
- assertEqual(
- parse([ '--host=localhost', '--port=555' ]),
- { host : 'localhost', port : 555, _ : [] },
- );
+ assertEqual(parse(["--bool"]), { bool: true, _: [] });
+ assertEqual(parse(["--pow", "xixxle"]), { pow: "xixxle", _: [] });
+ assertEqual(parse(["--pow=xixxle"]), { pow: "xixxle", _: [] });
+ assertEqual(parse(["--host", "localhost", "--port", "555"]), {
+ host: "localhost",
+ port: 555,
+ _: []
+ });
+ assertEqual(parse(["--host=localhost", "--port=555"]), {
+ host: "localhost",
+ port: 555,
+ _: []
+ });
});
diff --git a/flags/tests/num.ts b/flags/tests/num.ts
index c31a2fd4c..66cbcb7ad 100755
--- a/flags/tests/num.ts
+++ b/flags/tests/num.ts
@@ -2,33 +2,38 @@ import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
import { parse } from "../index.ts";
test(function nums() {
- const argv = parse([
- '-x', '1234',
- '-y', '5.67',
- '-z', '1e7',
- '-w', '10f',
- '--hex', '0xdeadbeef',
- '789'
- ]);
- assertEqual(argv, {
- x : 1234,
- y : 5.67,
- z : 1e7,
- w : '10f',
- hex : 0xdeadbeef,
- _ : [ 789 ]
- });
- assertEqual(typeof argv.x, 'number');
- assertEqual(typeof argv.y, 'number');
- assertEqual(typeof argv.z, 'number');
- assertEqual(typeof argv.w, 'string');
- assertEqual(typeof argv.hex, 'number');
- assertEqual(typeof argv._[0], 'number');
+ const argv = parse([
+ "-x",
+ "1234",
+ "-y",
+ "5.67",
+ "-z",
+ "1e7",
+ "-w",
+ "10f",
+ "--hex",
+ "0xdeadbeef",
+ "789"
+ ]);
+ assertEqual(argv, {
+ x: 1234,
+ y: 5.67,
+ z: 1e7,
+ w: "10f",
+ hex: 0xdeadbeef,
+ _: [789]
+ });
+ assertEqual(typeof argv.x, "number");
+ assertEqual(typeof argv.y, "number");
+ assertEqual(typeof argv.z, "number");
+ assertEqual(typeof argv.w, "string");
+ assertEqual(typeof argv.hex, "number");
+ assertEqual(typeof argv._[0], "number");
});
test(function alreadyNumber() {
- const argv = parse([ '-x', 1234, 789 ]);
- assertEqual(argv, { x : 1234, _ : [ 789 ] });
- assertEqual(typeof argv.x, 'number');
- assertEqual(typeof argv._[0], 'number');
+ const argv = parse(["-x", 1234, 789]);
+ assertEqual(argv, { x: 1234, _: [789] });
+ assertEqual(typeof argv.x, "number");
+ assertEqual(typeof argv._[0], "number");
});
diff --git a/flags/tests/parse.ts b/flags/tests/parse.ts
index ca86e6aa1..29a500868 100644
--- a/flags/tests/parse.ts
+++ b/flags/tests/parse.ts
@@ -1,182 +1,192 @@
import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
import { parse } from "../index.ts";
-
test(function _arseArgs() {
- assertEqual(
- parse([ '--no-moo' ]),
- { moo : false, _ : [] },
- );
- assertEqual(
- parse([ '-v', 'a', '-v', 'b', '-v', 'c' ]),
- { v : ['a','b','c'], _ : [] },
- );
+ assertEqual(parse(["--no-moo"]), { moo: false, _: [] });
+ assertEqual(parse(["-v", "a", "-v", "b", "-v", "c"]), {
+ v: ["a", "b", "c"],
+ _: []
+ });
});
-
+
test(function comprehensive() {
- assertEqual(
- parse([
- '--name=meowmers', 'bare', '-cats', 'woo',
- '-h', 'awesome', '--multi=quux',
- '--key', 'value',
- '-b', '--bool', '--no-meep', '--multi=baz',
- '--', '--not-a-flag', 'eek'
- ]),
- {
- c : true,
- a : true,
- t : true,
- s : 'woo',
- h : 'awesome',
- b : true,
- bool : true,
- key : 'value',
- multi : [ 'quux', 'baz' ],
- meep : false,
- name : 'meowmers',
- _ : [ 'bare', '--not-a-flag', 'eek' ]
- }
- );
+ assertEqual(
+ parse([
+ "--name=meowmers",
+ "bare",
+ "-cats",
+ "woo",
+ "-h",
+ "awesome",
+ "--multi=quux",
+ "--key",
+ "value",
+ "-b",
+ "--bool",
+ "--no-meep",
+ "--multi=baz",
+ "--",
+ "--not-a-flag",
+ "eek"
+ ]),
+ {
+ c: true,
+ a: true,
+ t: true,
+ s: "woo",
+ h: "awesome",
+ b: true,
+ bool: true,
+ key: "value",
+ multi: ["quux", "baz"],
+ meep: false,
+ name: "meowmers",
+ _: ["bare", "--not-a-flag", "eek"]
+ }
+ );
});
test(function flagBoolean() {
- const argv = parse([ '-t', 'moo' ], { boolean: 't' });
- assertEqual(argv, { t : true, _ : [ 'moo' ] });
- assertEqual(typeof argv.t, 'boolean');
+ const argv = parse(["-t", "moo"], { boolean: "t" });
+ assertEqual(argv, { t: true, _: ["moo"] });
+ assertEqual(typeof argv.t, "boolean");
});
test(function flagBooleanValue() {
- const argv = parse(['--verbose', 'false', 'moo', '-t', 'true'], {
- boolean: [ 't', 'verbose' ],
- default: { verbose: true }
- });
-
- assertEqual(argv, {
- verbose: false,
- t: true,
- _: ['moo']
- });
-
- assertEqual(typeof argv.verbose, 'boolean');
- assertEqual(typeof argv.t, 'boolean');
+ const argv = parse(["--verbose", "false", "moo", "-t", "true"], {
+ boolean: ["t", "verbose"],
+ default: { verbose: true }
+ });
+
+ assertEqual(argv, {
+ verbose: false,
+ t: true,
+ _: ["moo"]
+ });
+
+ assertEqual(typeof argv.verbose, "boolean");
+ assertEqual(typeof argv.t, "boolean");
});
test(function newlinesInParams() {
- const args = parse([ '-s', "X\nX" ])
- assertEqual(args, { _ : [], s : "X\nX" });
-
- // reproduce in bash:
- // VALUE="new
- // line"
- // deno program.js --s="$VALUE"
- const args2 = parse([ "--s=X\nX" ])
- assertEqual(args2, { _ : [], s : "X\nX" });
+ const args = parse(["-s", "X\nX"]);
+ assertEqual(args, { _: [], s: "X\nX" });
+
+ // reproduce in bash:
+ // VALUE="new
+ // line"
+ // deno program.js --s="$VALUE"
+ const args2 = parse(["--s=X\nX"]);
+ assertEqual(args2, { _: [], s: "X\nX" });
});
test(function strings() {
- const s = parse([ '-s', '0001234' ], { string: 's' }).s;
- assertEqual(s, '0001234');
- assertEqual(typeof s, 'string');
-
- const x = parse([ '-x', '56' ], { string: 'x' }).x;
- assertEqual(x, '56');
- assertEqual(typeof x, 'string');
+ const s = parse(["-s", "0001234"], { string: "s" }).s;
+ assertEqual(s, "0001234");
+ assertEqual(typeof s, "string");
+
+ const x = parse(["-x", "56"], { string: "x" }).x;
+ assertEqual(x, "56");
+ assertEqual(typeof x, "string");
});
test(function stringArgs() {
- const s = parse([ ' ', ' ' ], { string: '_' })._;
- assertEqual(s.length, 2);
- assertEqual(typeof s[0], 'string');
- assertEqual(s[0], ' ');
- assertEqual(typeof s[1], 'string');
- assertEqual(s[1], ' ');
+ const s = parse([" ", " "], { string: "_" })._;
+ assertEqual(s.length, 2);
+ assertEqual(typeof s[0], "string");
+ assertEqual(s[0], " ");
+ assertEqual(typeof s[1], "string");
+ assertEqual(s[1], " ");
});
test(function emptyStrings() {
- const s = parse([ '-s' ], { string: 's' }).s;
- assertEqual(s, '');
- assertEqual(typeof s, 'string');
+ const s = parse(["-s"], { string: "s" }).s;
+ assertEqual(s, "");
+ assertEqual(typeof s, "string");
- const str = parse([ '--str' ], { string: 'str' }).str;
- assertEqual(str, '');
- assertEqual(typeof str, 'string');
+ const str = parse(["--str"], { string: "str" }).str;
+ assertEqual(str, "");
+ assertEqual(typeof str, "string");
- const letters = parse([ '-art' ], {
- string: [ 'a', 't' ]
- });
+ const letters = parse(["-art"], {
+ string: ["a", "t"]
+ });
- assertEqual(letters.a, '');
- assertEqual(letters.r, true);
- assertEqual(letters.t, '');
+ assertEqual(letters.a, "");
+ assertEqual(letters.r, true);
+ assertEqual(letters.t, "");
});
-
test(function stringAndAlias() {
- const x = parse([ '--str', '000123' ], {
- string: 's',
- alias: { s: 'str' }
- });
-
- assertEqual(x.str, '000123');
- assertEqual(typeof x.str, 'string');
- assertEqual(x.s, '000123');
- assertEqual(typeof x.s, 'string');
-
- const y = parse([ '-s', '000123' ], {
- string: 'str',
- alias: { str: 's' }
- });
-
- assertEqual(y.str, '000123');
- assertEqual(typeof y.str, 'string');
- assertEqual(y.s, '000123');
- assertEqual(typeof y.s, 'string');
+ const x = parse(["--str", "000123"], {
+ string: "s",
+ alias: { s: "str" }
+ });
+
+ assertEqual(x.str, "000123");
+ assertEqual(typeof x.str, "string");
+ assertEqual(x.s, "000123");
+ assertEqual(typeof x.s, "string");
+
+ const y = parse(["-s", "000123"], {
+ string: "str",
+ alias: { str: "s" }
+ });
+
+ assertEqual(y.str, "000123");
+ assertEqual(typeof y.str, "string");
+ assertEqual(y.s, "000123");
+ assertEqual(typeof y.s, "string");
});
test(function slashBreak() {
- assertEqual(
- parse([ '-I/foo/bar/baz' ]),
- { I : '/foo/bar/baz', _ : [] }
- );
- assertEqual(
- parse([ '-xyz/foo/bar/baz' ]),
- { x : true, y : true, z : '/foo/bar/baz', _ : [] }
- );
+ assertEqual(parse(["-I/foo/bar/baz"]), { I: "/foo/bar/baz", _: [] });
+ assertEqual(parse(["-xyz/foo/bar/baz"]), {
+ x: true,
+ y: true,
+ z: "/foo/bar/baz",
+ _: []
+ });
});
test(function alias() {
- const argv = parse([ '-f', '11', '--zoom', '55' ], {
- alias: { z: 'zoom' }
- });
- assertEqual(argv.zoom, 55);
- assertEqual(argv.z, argv.zoom);
- assertEqual(argv.f, 11);
+ const argv = parse(["-f", "11", "--zoom", "55"], {
+ alias: { z: "zoom" }
+ });
+ assertEqual(argv.zoom, 55);
+ assertEqual(argv.z, argv.zoom);
+ assertEqual(argv.f, 11);
});
test(function multiAlias() {
- const argv = parse([ '-f', '11', '--zoom', '55' ], {
- alias: { z: [ 'zm', 'zoom' ] }
- });
- assertEqual(argv.zoom, 55);
- assertEqual(argv.z, argv.zoom);
- assertEqual(argv.z, argv.zm);
- assertEqual(argv.f, 11);
+ const argv = parse(["-f", "11", "--zoom", "55"], {
+ alias: { z: ["zm", "zoom"] }
+ });
+ assertEqual(argv.zoom, 55);
+ assertEqual(argv.z, argv.zoom);
+ assertEqual(argv.z, argv.zm);
+ assertEqual(argv.f, 11);
});
test(function nestedDottedObjects() {
- const argv = parse([
- '--foo.bar', '3', '--foo.baz', '4',
- '--foo.quux.quibble', '5', '--foo.quux.o_O',
- '--beep.boop'
- ]);
-
- assertEqual(argv.foo, {
- bar : 3,
- baz : 4,
- quux : {
- quibble : 5,
- o_O : true
- }
- });
- assertEqual(argv.beep, { boop : true });
-}); \ No newline at end of file
+ const argv = parse([
+ "--foo.bar",
+ "3",
+ "--foo.baz",
+ "4",
+ "--foo.quux.quibble",
+ "5",
+ "--foo.quux.o_O",
+ "--beep.boop"
+ ]);
+
+ assertEqual(argv.foo, {
+ bar: 3,
+ baz: 4,
+ quux: {
+ quibble: 5,
+ o_O: true
+ }
+ });
+ assertEqual(argv.beep, { boop: true });
+});
diff --git a/flags/tests/short.ts b/flags/tests/short.ts
index 7e1203c5f..00c9dcc80 100755
--- a/flags/tests/short.ts
+++ b/flags/tests/short.ts
@@ -2,56 +2,43 @@ import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
import { parse } from "../index.ts";
test(function numbericShortArgs() {
- assertEqual(parse([ '-n123' ]), { n: 123, _: [] });
- assertEqual(
- parse([ '-123', '456' ]),
- { 1: true, 2: true, 3: 456, _: [] }
- );
+ assertEqual(parse(["-n123"]), { n: 123, _: [] });
+ assertEqual(parse(["-123", "456"]), { 1: true, 2: true, 3: 456, _: [] });
});
test(function short() {
- assertEqual(
- parse([ '-b' ]),
- { b : true, _ : [] },
- );
- assertEqual(
- parse([ 'foo', 'bar', 'baz' ]),
- { _ : [ 'foo', 'bar', 'baz' ] },
- );
- assertEqual(
- parse([ '-cats' ]),
- { c : true, a : true, t : true, s : true, _ : [] },
- );
- assertEqual(
- parse([ '-cats', 'meow' ]),
- { c : true, a : true, t : true, s : 'meow', _ : [] },
- );
- assertEqual(
- parse([ '-h', 'localhost' ]),
- { h : 'localhost', _ : [] },
- );
- assertEqual(
- parse([ '-h', 'localhost', '-p', '555' ]),
- { h : 'localhost', p : 555, _ : [] },
- );
+ assertEqual(parse(["-b"]), { b: true, _: [] });
+ assertEqual(parse(["foo", "bar", "baz"]), { _: ["foo", "bar", "baz"] });
+ assertEqual(parse(["-cats"]), { c: true, a: true, t: true, s: true, _: [] });
+ assertEqual(parse(["-cats", "meow"]), {
+ c: true,
+ a: true,
+ t: true,
+ s: "meow",
+ _: []
+ });
+ assertEqual(parse(["-h", "localhost"]), { h: "localhost", _: [] });
+ assertEqual(parse(["-h", "localhost", "-p", "555"]), {
+ h: "localhost",
+ p: 555,
+ _: []
+ });
});
-
+
test(function mixedShortBoolAndCapture() {
- assertEqual(
- parse([ '-h', 'localhost', '-fp', '555', 'script.js' ]),
- {
- f : true, p : 555, h : 'localhost',
- _ : [ 'script.js' ]
- }
- );
+ assertEqual(parse(["-h", "localhost", "-fp", "555", "script.js"]), {
+ f: true,
+ p: 555,
+ h: "localhost",
+ _: ["script.js"]
+ });
});
-
+
test(function shortAndLong() {
- assertEqual(
- parse([ '-h', 'localhost', '-fp', '555', 'script.js' ]),
- {
- f : true, p : 555, h : 'localhost',
- _ : [ 'script.js' ]
- }
- );
+ assertEqual(parse(["-h", "localhost", "-fp", "555", "script.js"]), {
+ f: true,
+ p: 555,
+ h: "localhost",
+ _: ["script.js"]
+ });
});
diff --git a/flags/tests/stop_early.ts b/flags/tests/stop_early.ts
index a47c9bd4a..62725e6cf 100755
--- a/flags/tests/stop_early.ts
+++ b/flags/tests/stop_early.ts
@@ -3,12 +3,12 @@ import { parse } from "../index.ts";
// stops parsing on the first non-option when stopEarly is set
test(function stopParsing() {
- const argv = parse(['--aaa', 'bbb', 'ccc', '--ddd'], {
- stopEarly: true
- });
+ const argv = parse(["--aaa", "bbb", "ccc", "--ddd"], {
+ stopEarly: true
+ });
- assertEqual(argv, {
- aaa: 'bbb',
- _: ['ccc', '--ddd']
- });
+ assertEqual(argv, {
+ aaa: "bbb",
+ _: ["ccc", "--ddd"]
+ });
});
diff --git a/flags/tests/unknown.ts b/flags/tests/unknown.ts
index 8cc48285e..ff5f2041c 100755
--- a/flags/tests/unknown.ts
+++ b/flags/tests/unknown.ts
@@ -2,95 +2,95 @@ import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
import { parse } from "../index.ts";
test(function booleanAndAliasIsNotUnknown() {
- const unknown = [];
- function unknownFn(arg) {
- unknown.push(arg);
- return false;
- }
- const aliased = [ '-h', 'true', '--derp', 'true' ];
- const regular = [ '--herp', 'true', '-d', 'true' ];
- const opts = {
- alias: { h: 'herp' },
- boolean: 'h',
- unknown: unknownFn
- };
- const aliasedArgv = parse(aliased, opts);
- const propertyArgv = parse(regular, opts);
+ const unknown = [];
+ function unknownFn(arg) {
+ unknown.push(arg);
+ return false;
+ }
+ const aliased = ["-h", "true", "--derp", "true"];
+ const regular = ["--herp", "true", "-d", "true"];
+ const opts = {
+ alias: { h: "herp" },
+ boolean: "h",
+ unknown: unknownFn
+ };
+ const aliasedArgv = parse(aliased, opts);
+ const propertyArgv = parse(regular, opts);
- assertEqual(unknown, ['--derp', '-d']);
+ assertEqual(unknown, ["--derp", "-d"]);
});
test(function flagBooleanTrueAnyDoubleHyphenArgumentIsNotUnknown() {
- const unknown = [];
- function unknownFn(arg) {
- unknown.push(arg);
- return false;
- }
- const argv = parse(['--honk', '--tacos=good', 'cow', '-p', '55'], {
- boolean: true,
- unknown: unknownFn
- });
- assertEqual(unknown, ['--tacos=good', 'cow', '-p']);
- assertEqual(argv, {
- honk: true,
- _: []
- });
+ const unknown = [];
+ function unknownFn(arg) {
+ unknown.push(arg);
+ return false;
+ }
+ const argv = parse(["--honk", "--tacos=good", "cow", "-p", "55"], {
+ boolean: true,
+ unknown: unknownFn
+ });
+ assertEqual(unknown, ["--tacos=good", "cow", "-p"]);
+ assertEqual(argv, {
+ honk: true,
+ _: []
+ });
});
test(function stringAndAliasIsNotUnkown() {
- const unknown = [];
- function unknownFn(arg) {
- unknown.push(arg);
- return false;
- }
- const aliased = [ '-h', 'hello', '--derp', 'goodbye' ];
- const regular = [ '--herp', 'hello', '-d', 'moon' ];
- const opts = {
- alias: { h: 'herp' },
- string: 'h',
- unknown: unknownFn
- };
- const aliasedArgv = parse(aliased, opts);
- const propertyArgv = parse(regular, opts);
+ const unknown = [];
+ function unknownFn(arg) {
+ unknown.push(arg);
+ return false;
+ }
+ const aliased = ["-h", "hello", "--derp", "goodbye"];
+ const regular = ["--herp", "hello", "-d", "moon"];
+ const opts = {
+ alias: { h: "herp" },
+ string: "h",
+ unknown: unknownFn
+ };
+ const aliasedArgv = parse(aliased, opts);
+ const propertyArgv = parse(regular, opts);
- assertEqual(unknown, ['--derp', '-d']);
+ assertEqual(unknown, ["--derp", "-d"]);
});
test(function defaultAndAliasIsNotUnknown() {
- const unknown = [];
- function unknownFn(arg) {
- unknown.push(arg);
- return false;
- }
- const aliased = [ '-h', 'hello' ];
- const regular = [ '--herp', 'hello' ];
- const opts = {
- default: { 'h': 'bar' },
- alias: { 'h': 'herp' },
- unknown: unknownFn
- };
- const aliasedArgv = parse(aliased, opts);
- const propertyArgv = parse(regular, opts);
+ const unknown = [];
+ function unknownFn(arg) {
+ unknown.push(arg);
+ return false;
+ }
+ const aliased = ["-h", "hello"];
+ const regular = ["--herp", "hello"];
+ const opts = {
+ default: { h: "bar" },
+ alias: { h: "herp" },
+ unknown: unknownFn
+ };
+ const aliasedArgv = parse(aliased, opts);
+ const propertyArgv = parse(regular, opts);
- assertEqual(unknown, []);
+ assertEqual(unknown, []);
});
test(function valueFollowingDoubleHyphenIsNotUnknown() {
- const unknown = [];
- function unknownFn(arg) {
- unknown.push(arg);
- return false;
- }
- const aliased = [ '--bad', '--', 'good', 'arg' ];
- const opts = {
- '--': true,
- unknown: unknownFn
- };
- const argv = parse(aliased, opts);
+ const unknown = [];
+ function unknownFn(arg) {
+ unknown.push(arg);
+ return false;
+ }
+ const aliased = ["--bad", "--", "good", "arg"];
+ const opts = {
+ "--": true,
+ unknown: unknownFn
+ };
+ const argv = parse(aliased, opts);
- assertEqual(unknown, ['--bad']);
- assertEqual(argv, {
- '--': ['good', 'arg'],
- '_': []
- })
+ assertEqual(unknown, ["--bad"]);
+ assertEqual(argv, {
+ "--": ["good", "arg"],
+ _: []
+ });
});
diff --git a/flags/tests/whitespace.ts b/flags/tests/whitespace.ts
index 24a291587..f50518b4f 100755
--- a/flags/tests/whitespace.ts
+++ b/flags/tests/whitespace.ts
@@ -2,5 +2,5 @@ import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
import { parse } from "../index.ts";
test(function whitespaceShouldBeWhitespace() {
- assertEqual(parse([ '-x', '\t' ]).x, '\t');
+ assertEqual(parse(["-x", "\t"]).x, "\t");
});
diff --git a/format.ts b/format.ts
index 25a56641d..949fa9ce9 100755
--- a/format.ts
+++ b/format.ts
@@ -27,7 +27,7 @@ async function main() {
await checkVersion();
const prettier = run({
- args: ["bash", "-c", "prettier --write *.ts **/*.ts"]
+ args: ["bash", "-c", "prettier --write *.ts */**/*.ts *.md */**/*.md"]
});
const s = await prettier.status();
exit(s.code);
diff --git a/logging/README.md b/logging/README.md
index b444b411b..26047d9a2 100644
--- a/logging/README.md
+++ b/logging/README.md
@@ -2,11 +2,14 @@
Very much work in progress. Contributions welcome.
-This library is heavily inspired by Python's [logging](https://docs.python.org/3/library/logging.html#logging.Logger.log) module, altough
-it's not planned to be a direct port. Having separate loggers, handlers, formatters and filters gives developer very granular control over logging
-which is most desirable for server side software.
+This library is heavily inspired by Python's
+[logging](https://docs.python.org/3/library/logging.html#logging.Logger.log)
+module, altough it's not planned to be a direct port. Having separate loggers,
+handlers, formatters and filters gives developer very granular control over
+logging which is most desirable for server side software.
Todo:
+
- [ ] implement formatters
- [ ] implement `FileHandler`
-- [ ] tests \ No newline at end of file
+- [ ] tests
diff --git a/logging/handlers/console.ts b/logging/handlers/console.ts
index 219a3baec..8db0add31 100644
--- a/logging/handlers/console.ts
+++ b/logging/handlers/console.ts
@@ -1,26 +1,26 @@
-import { BaseHandler } from '../handler.ts';
-import { LogLevel } from '../levels.ts';
+import { BaseHandler } from "../handler.ts";
+import { LogLevel } from "../levels.ts";
export class ConsoleHandler extends BaseHandler {
- _log(level, ...args) {
- switch (level) {
- case LogLevel.DEBUG:
- console.log(...args);
- return;
- case LogLevel.INFO:
- console.info(...args);
- return;
- case LogLevel.WARNING:
- console.warn(...args);
- return;
- case LogLevel.ERROR:
- console.error(...args);
- return;
- case LogLevel.CRITICAL:
- console.error(...args);
- return;
- default:
- return;
- }
+ _log(level, ...args) {
+ switch (level) {
+ case LogLevel.DEBUG:
+ console.log(...args);
+ return;
+ case LogLevel.INFO:
+ console.info(...args);
+ return;
+ case LogLevel.WARNING:
+ console.warn(...args);
+ return;
+ case LogLevel.ERROR:
+ console.error(...args);
+ return;
+ case LogLevel.CRITICAL:
+ console.error(...args);
+ return;
+ default:
+ return;
}
+ }
}
diff --git a/path/README.md b/path/README.md
index d4f693577..924b0a993 100644
--- a/path/README.md
+++ b/path/README.md
@@ -3,5 +3,5 @@
Usage:
```ts
-import * as path from 'https://deno.land/x/path/index.ts'
+import * as path from "https://deno.land/x/path/index.ts";
```