Skip to content

Commit

Permalink
Move Context.invokeCommands to State.fork
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangoree committed Feb 6, 2024
1 parent 5bf6519 commit 1350e6b
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 215 deletions.
2 changes: 2 additions & 0 deletions notes/notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
- [x] Filesystem based command router
- [x] Param routes
- [x] Options getter
- [ ] Custom option types (e.g., "bigint", "number-string", "hex") with custom
validation and input masking
- [x] Options config
- [x] Option parsing
- [x] string
Expand Down
42 changes: 42 additions & 0 deletions packages/clide-js/src/cli/commands/bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { command } from 'src/core/command';

/**
* Test Cases:
*
* // Defaults passed to invoked command?
* - DEFAULT, no value, no prompt, no passed value -> no option
*
* // Defaults passed to invoked command?
* - DEFAULT, no value, no prompt, no passed value -> no default
*
* // Parsed values passed to invoked command?
* - No default, VALUE, no prompt, no passed value -> no default
*
* // Prompt updates AND passed to invoked command?
* - No default, no value, PROMPT, no passed value -> no default
*
* // Override passed to invoked command?
* - No default, no value, no prompt, PASSED_VALUE -> no default
*
*
* // Values updated from invoked default?
* - no default, no value, no prompt, no passed value -> DEFAULT
*
* // Default priority?
* - DEFAULT, no value, no prompt, no passed value -> DEFAULT
*/

export default command({
description: 'Get a greeting',
options: {
foo: {
type: 'string',
default: 'default bar',
},
},
handler: async ({ options, end }) => {
console.log('------\nBar Values:', options.values, '\n------');

end();
},
});
45 changes: 45 additions & 0 deletions packages/clide-js/src/cli/commands/foo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { command } from 'src/core/command';
import bar from './bar';

/**
* Test Cases:
*
* // Defaults passed to invoked command? ✅
* - DEFAULT, no value, no prompt, no passed value -> no default
*
* // Parsed values passed to invoked command?
* - No default, VALUE, no prompt, no passed value -> no default
*
* // Prompt updates AND passed to invoked command?
* - No default, no value, PROMPT, no passed value -> no default
*
* // Override passed to invoked command?
* - No default, no value, no prompt, PASSED_VALUE -> no default
*
*
* // Values updated from invoked default?
* - no default, no value, no prompt, no passed value -> DEFAULT
*
* // Default priority?
* - DEFAULT, no value, no prompt, no passed value -> DEFAULT
*/

export default command({
description: 'Get a greeting',
options: {
foo: {
type: 'string',
default: 'default foo',
},
},
handler: async ({ next, fork, options }) => {
console.log('------\nFoo Values:', options.values, '\n------');

const res = await fork({
commands: [bar],
optionValues: options.values,
});

next(res);
},
});
53 changes: 0 additions & 53 deletions packages/clide-js/src/cli/commands/hello.ts

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions packages/clide-js/src/cli/commands/hello/alice.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/clide-js/src/cli/commands/hello/bob.ts

This file was deleted.

Loading

0 comments on commit 1350e6b

Please sign in to comment.