Skip to content

Commit 885d9ad

Browse files
committed
chore: add usage suite w/ fixtures
1 parent c7c97b3 commit 885d9ad

File tree

9 files changed

+453
-0
lines changed

9 files changed

+453
-0
lines changed

test/fixtures/args.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env node
2+
const sade = require('../../lib');
3+
4+
sade('bin')
5+
.command('foo <dir>')
6+
.action(dir => {
7+
console.log(`~> ran "foo" with "${dir}" arg`);
8+
})
9+
.command('bar [dir]')
10+
.action(dir => {
11+
dir = dir || '~default~';
12+
console.log(`~> ran "bar" with "${dir}" arg`);
13+
})
14+
.parse(process.argv);

test/fixtures/basic.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env node
2+
const sade = require('../../lib');
3+
4+
sade('bin')
5+
.command('foo')
6+
.action(() => {
7+
console.log('~> ran "foo" action');
8+
})
9+
.parse(process.argv);

test/fixtures/default.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env node
2+
const sade = require('../../lib');
3+
4+
sade('bin')
5+
.command('foo', null, { default:true })
6+
.action(() => console.log('~> ran "foo" action'))
7+
8+
.command('bar')
9+
.action(() => console.log('~> ran "bar" action'))
10+
11+
.parse(process.argv);

test/fixtures/options.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env node
2+
const sade = require('../../lib');
3+
4+
sade('bin')
5+
.option('-g, --global', 'global')
6+
.command('foo')
7+
.option('-l, --long', 'long flag')
8+
.option('-s, --short', 'short flag')
9+
.option('-h, --hello', 'override')
10+
.action(opts => {
11+
if (opts.long) return console.log('~> ran "long" option');
12+
if (opts.short) return console.log('~> ran "short" option');
13+
if (opts.hello) return console.log('~> ran "hello" option');
14+
console.log(`~> default with ${JSON.stringify(opts)}`);
15+
})
16+
17+
.command('bar <dir>')
18+
.option('--only', 'no short alias')
19+
.action((dir, opts) => {
20+
let pre = opts.only ? '~> (only)' : '~>';
21+
console.log(pre + ` "bar" with "${dir}" value`);
22+
})
23+
.parse(process.argv);

test/fixtures/repeat.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env node
2+
const sade = require('../../lib');
3+
4+
sade('bin')
5+
.command('foo', 'original')
6+
.command('foo', 'duplicate')
7+
.action(() => {
8+
console.log('~> ran "foo" action');
9+
})
10+
.parse(process.argv);

test/fixtures/subs.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env node
2+
const sade = require('../../lib');
3+
4+
sade('bin')
5+
.command('remote')
6+
.action(opts => {
7+
console.log('~> ran "remote" action');
8+
})
9+
10+
.command('remote add <name> <url>')
11+
.action((name, uri, opts) => {
12+
console.log(`~> ran "remote add" with "${name}" and "${uri}" args`);
13+
})
14+
15+
.command('remote rename <old> <new>')
16+
.action((old, nxt, opts) => {
17+
console.log(`~> ran "remote rename" with "${old}" and "${nxt}" args`);
18+
})
19+
20+
.parse(process.argv);

test/fixtures/unknown1.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env node
2+
const sade = require('../../lib');
3+
4+
sade('bin')
5+
.option('-g, --global', 'global flag')
6+
7+
.command('foo')
8+
.option('-l, --local', 'command flag')
9+
.action(opts => {
10+
console.log(`~> ran "foo" with ${JSON.stringify(opts)}`);
11+
})
12+
13+
.parse(process.argv, {
14+
unknown: () => false
15+
});

test/fixtures/unknown2.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env node
2+
const sade = require('../../lib');
3+
4+
sade('bin')
5+
.option('-g, --global', 'global flag')
6+
7+
.command('foo')
8+
.option('-l, --local', 'command flag')
9+
.action(opts => {
10+
console.log(`~> ran "foo" with ${JSON.stringify(opts)}`);
11+
})
12+
13+
.parse(process.argv, {
14+
unknown: x => `Custom error: ${x}`
15+
});

0 commit comments

Comments
 (0)