File tree Expand file tree Collapse file tree 9 files changed +453
-0
lines changed
Expand file tree Collapse file tree 9 files changed +453
-0
lines changed Original file line number Diff line number Diff line change 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 ) ;
Original file line number Diff line number Diff line change 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 ) ;
Original file line number Diff line number Diff line change 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 ) ;
Original file line number Diff line number Diff line change 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 ) ;
Original file line number Diff line number Diff line change 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 ) ;
Original file line number Diff line number Diff line change 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 ) ;
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments