citadel_cli 1.1.6 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/README.md +68 -105
  2. package/dist/App.test.d.ts +1 -0
  3. package/dist/__test-utils__/factories.d.ts +0 -2
  4. package/dist/citadel.es.js +999 -721
  5. package/dist/citadel.umd.js +10 -10
  6. package/dist/components/Citadel/Citadel.d.ts +1 -0
  7. package/dist/components/Citadel/components/AvailableCommands.d.ts +5 -1
  8. package/dist/components/Citadel/components/CommandOutputLine.d.ts +2 -0
  9. package/dist/components/Citadel/config/defaults.d.ts +5 -1
  10. package/dist/components/Citadel/config/types.d.ts +17 -3
  11. package/dist/components/Citadel/hooks/useCitadelState.d.ts +0 -2
  12. package/dist/components/Citadel/hooks/useCommandHistory.d.ts +2 -2
  13. package/dist/components/Citadel/services/__tests__/HistoryService.test.d.ts +1 -0
  14. package/dist/components/Citadel/storage/StorageFactory.d.ts +1 -0
  15. package/dist/components/Citadel/storage/__tests__/StorageFactory.test.d.ts +1 -0
  16. package/dist/components/Citadel/types/__tests__/command-dsl.test.d.ts +1 -0
  17. package/dist/components/Citadel/types/__tests__/help-command.test.d.ts +1 -0
  18. package/dist/components/Citadel/types/__tests__/state.test.d.ts +1 -0
  19. package/dist/components/Citadel/types/command-dsl.d.ts +32 -0
  20. package/dist/components/Citadel/types/command-registry.d.ts +13 -1
  21. package/dist/components/Citadel/types/index.d.ts +1 -0
  22. package/dist/components/Citadel/types/state.d.ts +2 -0
  23. package/dist/components/Citadel/utils/typography.d.ts +8 -0
  24. package/dist/examples/__tests__/runtimeConfigCommands.test.d.ts +1 -0
  25. package/dist/examples/devopsCommands.d.ts +2 -0
  26. package/dist/examples/localDevCommands.d.ts +2 -0
  27. package/dist/examples/runtimeConfigCommands.d.ts +15 -0
  28. package/dist/examples/runtimeConfigDemo.d.ts +13 -0
  29. package/package.json +1 -1
package/README.md CHANGED
@@ -24,31 +24,27 @@ npm i citadel_cli
24
24
  A core concept in Citadel are commands. Commands are things like "user add 1234"
25
25
  or "qa1 deploy my_feature_branch". To initialize and add commands:
26
26
 
27
- 1. Create a `CommandRegistry` instance
28
- 2. Add one or more commands to that registry
27
+ 1. Define commands with the typed DSL
28
+ 2. Build a `CommandRegistry` from those definitions
29
29
  3. Pass the registry to `Citadel`
30
30
 
31
31
  ```typescript
32
32
  import {
33
33
  Citadel,
34
- CommandRegistry,
35
- TextCommandResult,
34
+ command,
35
+ createCommandRegistry,
36
+ text,
36
37
  } from "citadel_cli";
37
38
 
38
- // 1. Create the registry
39
- const registry = new CommandRegistry();
39
+ // 1. Define and register commands
40
+ const registry = createCommandRegistry([
41
+ command("greet")
42
+ .describe("Say hello to someone")
43
+ .arg("name", (arg) => arg.describe("Who are we greeting?"))
44
+ .handle(async ({ namedArgs }) => text(`Hello ${namedArgs.name} world!`)),
45
+ ]);
40
46
 
41
- // 2. Add commands
42
- registry.addCommand(
43
- [
44
- { type: "word", name: "greet" },
45
- { type: "argument", name: "name", description: "Who are we greeting?" },
46
- ],
47
- "Say hello to someone", // Description used by the built-in `help` command
48
- async (args: string[]) => new TextCommandResult(`Hello ${args[0]} world!`)
49
- );
50
-
51
- // 3. Pass the registry to the component
47
+ // 2. Pass the registry to the component
52
48
  function App() {
53
49
  return <Citadel commandRegistry={registry} />;
54
50
  }
@@ -64,28 +60,68 @@ to the full word. For the above example, typing <kbd>g</kbd> would expand
64
60
  in-place to `greet ` (with a trailing space) whereupon you can enter in a value
65
61
  for the `name` argument.
66
62
 
67
- ## `addCommand` Details
63
+ For hierarchical commands, expansion is prefix-based and unambiguous:
68
64
 
69
- The `addCommand` method has the following signature:
65
+ - `us` can resolve to `user show`
66
+ - `ud` can resolve to `user deactivate`
67
+ - If two options share a prefix (`show` and `search`), continue until unique:
68
+ `ush` => `user show`, `use` => `user search`
70
69
 
71
- ```typescript
72
- addCommand(segments: CommandSegment[], description: string, handler: CommandHandler): void
73
- ```
70
+ ## Help Text
74
71
 
75
- `segments[]` - Each `CommandSegment` in this array consists of a `type` (one of
76
- "word" or "argument"), a `name`, and an optional `description`
72
+ Argument segment `description` values are shown as argument-level help text.
73
+ Example built-in help output:
77
74
 
78
- `description` - Description of the command itself. Used by the built-in help
79
- command
75
+ ```text
76
+ user show <userId> - Show user details
77
+ <userId>: Enter user ID
78
+ ```
80
79
 
81
- `handler` - What gets executed when <kbd>Enter</kbd> is pressed. The handler
82
- must return one of the following:
80
+ Handlers must return one of the following:
83
81
 
84
82
  - `TextCommandResult`
85
83
  - `JsonCommandResult`
86
84
  - `ImageCommandResult`
87
85
  - `ErrorCommandResult`
88
86
 
87
+ ## Typed DSL
88
+
89
+ For clearer command authoring, you can define commands with a DSL and compile
90
+ them into a `CommandRegistry`:
91
+
92
+ ```typescript
93
+ import {
94
+ Citadel,
95
+ command,
96
+ createCommandRegistry,
97
+ text,
98
+ } from "citadel_cli";
99
+
100
+ const registry = createCommandRegistry([
101
+ command("user.show")
102
+ .describe("Show user details")
103
+ .arg("userId", (arg) => arg.describe("Enter user ID"))
104
+ .handle(async ({ namedArgs }) => {
105
+ return text(`Showing user ${namedArgs.userId}`);
106
+ }),
107
+ ]);
108
+
109
+ function App() {
110
+ return <Citadel commandRegistry={registry} />;
111
+ }
112
+ ```
113
+
114
+ DSL handlers receive:
115
+
116
+ - `rawArgs`: positional values (`string[]`)
117
+ - `namedArgs`: argument-name map (`Record<string, string | undefined>`)
118
+ - `commandPath`: dot-delimited path string
119
+
120
+ ## Legacy `addCommand` API
121
+
122
+ `CommandRegistry#addCommand` still works and is fully supported. The DSL is now
123
+ the recommended authoring path for new command definitions.
124
+
89
125
  ### Arguments
90
126
 
91
127
  1. Each command can have zero or more arguments
@@ -128,10 +164,12 @@ given below, along with their default values.
128
164
  const config = {
129
165
  commandTimeoutMs: 10000,
130
166
  includeHelpCommand: true,
167
+ fontFamily: '"JetBrains Mono", monospace',
168
+ fontSize: '0.875rem', // CSS size (e.g. '14px') or Tailwind class (e.g. 'text-sm')
131
169
  maxHeight: '80vh',
132
170
  initialHeight: '40vh',
133
171
  minHeight: '200',
134
- outputFontSize: '0.875rem',
172
+ outputFontSize: 'text-xs', // optional override for output text only
135
173
  resetStateOnHide: false,
136
174
  showCitadelKey: '.',
137
175
  cursorType: 'blink', // 'blink', 'spin', 'solid', or 'bbs'
@@ -151,79 +189,4 @@ Then to make the component aware of them:
151
189
 
152
190
  ## Contributing
153
191
 
154
- Contributions are welcome.
155
-
156
- 1. Clone the repository:
157
- ```bash
158
- git clone https://github.com/jchilders/citadel_cli.git
159
- cd citadel_cli
160
- ```
161
-
162
- 2. Install dependencies:
163
- ```bash
164
- npm install
165
- ```
166
-
167
- 3. Build the package:
168
- ```bash
169
- npm run build
170
- ```
171
-
172
- 4. (Optional but recommended) Link citadel so you can import it into a parallel project
173
- ```bash
174
- npm link
175
- ```
176
-
177
- 5. (Optional) From the directory of the project you want to import Citadel into:
178
- ```bash
179
- npm unlink citadel_cli && npm link citadel_cli
180
- # ... your normal dev process ...
181
- ```
182
-
183
- Load your appliation and press <kbd>.</kbd>
184
-
185
- ### Bug Reports and Feature Requests
186
-
187
- - Use the GitHub Issues section to report bugs or suggest features
188
- - Before creating a new issue, please check if a similar issue already exists
189
- - Provide as much detail as possible in bug reports:
190
- - Steps to reproduce the issue
191
- - Expected behavior
192
- - Actual behavior
193
- - Browser/environment information
194
- - Error messages or screenshots if applicable
195
-
196
- ### Development Process
197
-
198
- 1. Fork the repository
199
- 2. Create a new branch for your feature or bugfix:
200
- ```bash
201
- git checkout -b feature/your-feature-name
202
- # or
203
- git checkout -b fix/your-bugfix-name
204
- ```
205
- 3. Make your changes
206
- 4. Write or update tests as needed
207
- 5. Run the test suite to ensure everything passes:
208
- ```bash
209
- npm run test
210
- ```
211
- 6. Commit your changes with a clear and descriptive commit message
212
- 7. Push to your fork and submit a pull request
213
-
214
- ### Pull Request Guidelines
215
-
216
- - Keep your changes focused. Submit separate pull requests for separate features/fixes
217
- - Follow the existing code style and conventions
218
- - Include tests for new functionality
219
- - Update documentation as needed
220
- - Ensure all tests pass
221
- - Describe your changes in detail in the pull request description
222
-
223
- ### Code Style
224
-
225
- - Follow TypeScript best practices
226
- - Use meaningful variable and function names
227
- - Comment complex logic or non-obvious code
228
- - Keep functions focused and modular
229
- - Use consistent formatting (the project uses ESLint and Prettier)
192
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines on developing, testing, and releasing Citadel CLI.
@@ -0,0 +1 @@
1
+ export {};
@@ -25,8 +25,6 @@ export declare const setupCitadelStateHook: () => {
25
25
  hook: import('@testing-library/react').RenderHookResult<{
26
26
  state: CitadelState;
27
27
  actions: CitadelActions;
28
- getAvailableCommands_s: () => string[];
29
- getAvailableCommandSegments: () => CommandSegment[];
30
28
  }, unknown>;
31
29
  mockHistory: CommandHistory;
32
30
  mockActions: CommandHistoryActions;