citadel_cli 1.0.0 → 1.1.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.
- package/README.md +148 -207
- package/dist/citadel.es.js +1289 -1449
- package/dist/citadel.umd.js +19 -19
- package/dist/command_examples/basic-commands.d.ts +2 -83
- package/dist/src/__test-utils__/factories.d.ts +29 -10
- package/dist/src/components/Citadel/Citadel.d.ts +11 -7
- package/dist/src/components/Citadel/components/AvailableCommands.d.ts +1 -8
- package/dist/src/components/Citadel/components/CommandInput.d.ts +0 -2
- package/dist/src/components/Citadel/config/CitadelConfigContext.d.ts +5 -2
- package/dist/src/components/Citadel/config/defaults.d.ts +15 -7
- package/dist/src/components/Citadel/config/types.d.ts +32 -20
- package/dist/src/components/Citadel/hooks/useCitadelState.d.ts +2 -1
- package/dist/src/components/Citadel/hooks/useCommandHistory.d.ts +19 -9
- package/dist/src/components/Citadel/hooks/useCommandParser.d.ts +18 -15
- package/dist/src/components/Citadel/hooks/useSegmentStack.d.ts +14 -0
- package/dist/src/components/Citadel/hooks/useSegmentStackVersion.d.ts +1 -0
- package/dist/src/components/Citadel/storage/BaseStorage.d.ts +2 -2
- package/dist/src/components/Citadel/storage/LocalStorage.d.ts +1 -1
- package/dist/src/components/Citadel/storage/MemoryStorage.d.ts +2 -2
- package/dist/src/components/Citadel/types/__tests__/command-registry.test.d.ts +1 -0
- package/dist/src/components/Citadel/types/__tests__/segment-stack.test.d.ts +1 -0
- package/dist/src/components/Citadel/types/command-registry.d.ts +84 -0
- package/dist/src/components/Citadel/types/command-trie.d.ts +49 -203
- package/dist/src/components/Citadel/types/help-command.d.ts +3 -3
- package/dist/src/components/Citadel/types/segment-stack.d.ts +62 -0
- package/dist/src/components/Citadel/types/state.d.ts +8 -22
- package/dist/src/components/Citadel/types/storage.d.ts +4 -3
- package/dist/src/components/Citadel/utils/logger.d.ts +21 -0
- package/dist/src/index.d.ts +0 -1
- package/package.json +3 -3
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { CommandSegment, ArgumentSegment, NullSegment } from './command-registry';
|
|
2
|
+
interface StackObserver {
|
|
3
|
+
update: () => void;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* A stack used to store command segments as they are (or were) entered by a user.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SegmentStack {
|
|
9
|
+
private segments;
|
|
10
|
+
readonly nullSegment: NullSegment;
|
|
11
|
+
private observers;
|
|
12
|
+
subscribe(observer: StackObserver): void;
|
|
13
|
+
unsubscribe(observer: StackObserver): void;
|
|
14
|
+
private notifyObservers;
|
|
15
|
+
/**
|
|
16
|
+
* Clears all segments from the stack
|
|
17
|
+
*/
|
|
18
|
+
clear(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Pushes a new segment onto the stack
|
|
21
|
+
*/
|
|
22
|
+
push(segment: CommandSegment): void;
|
|
23
|
+
/**
|
|
24
|
+
* Pushes an array of segments onto the stack
|
|
25
|
+
*/
|
|
26
|
+
pushAll(segments: CommandSegment[]): void;
|
|
27
|
+
/**
|
|
28
|
+
* Removes and returns the top segment from the stack
|
|
29
|
+
* Returns NullSegment if stack is empty
|
|
30
|
+
*/
|
|
31
|
+
pop(): CommandSegment;
|
|
32
|
+
/**
|
|
33
|
+
* Returns the top segment without removing it
|
|
34
|
+
* Returns NullSegment if stack is empty
|
|
35
|
+
*/
|
|
36
|
+
peek(): CommandSegment;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the number of segments in the stack
|
|
39
|
+
*/
|
|
40
|
+
size(): number;
|
|
41
|
+
/**
|
|
42
|
+
* Returns true if the stack has no segments
|
|
43
|
+
*/
|
|
44
|
+
isEmpty(): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Returns true if any segment in the stack is an argument
|
|
47
|
+
*/
|
|
48
|
+
get hasArguments(): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Returns all argument segments in the stack
|
|
51
|
+
*/
|
|
52
|
+
get arguments(): ArgumentSegment[];
|
|
53
|
+
/**
|
|
54
|
+
* Returns the command path as an array of segment names
|
|
55
|
+
*/
|
|
56
|
+
path(): string[];
|
|
57
|
+
/**
|
|
58
|
+
* Returns a copy of the internal segments array
|
|
59
|
+
*/
|
|
60
|
+
toArray(): CommandSegment[];
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -1,40 +1,26 @@
|
|
|
1
|
-
import { CommandNode } from './command-trie';
|
|
2
1
|
import { CommandResult } from './command-results';
|
|
3
2
|
import { CommandStorage, StoredCommand } from './storage';
|
|
4
|
-
|
|
5
|
-
readonly timestamp: number;
|
|
6
|
-
readonly command: string[];
|
|
7
|
-
result: CommandResult;
|
|
8
|
-
constructor(command: string[], result?: CommandResult);
|
|
9
|
-
}
|
|
3
|
+
import { SegmentStack } from './segment-stack';
|
|
10
4
|
export interface CitadelState {
|
|
11
|
-
commandStack: string[];
|
|
12
5
|
currentInput: string;
|
|
13
6
|
isEnteringArg: boolean;
|
|
14
|
-
currentNode?: CommandNode;
|
|
15
7
|
output: OutputItem[];
|
|
16
|
-
validation: {
|
|
17
|
-
isValid: boolean;
|
|
18
|
-
message?: string;
|
|
19
|
-
};
|
|
20
8
|
history: {
|
|
21
9
|
commands: StoredCommand[];
|
|
22
10
|
position: number | null;
|
|
23
|
-
savedInput: string | null;
|
|
24
11
|
storage?: CommandStorage;
|
|
25
12
|
};
|
|
26
13
|
}
|
|
27
14
|
export interface CitadelActions {
|
|
28
|
-
setCommandStack: (stack: string[]) => void;
|
|
29
15
|
setCurrentInput: (input: string) => void;
|
|
30
16
|
setIsEnteringArg: (isEntering: boolean) => void;
|
|
31
|
-
setCurrentNode: (node: CommandNode | undefined) => void;
|
|
32
17
|
addOutput: (output: OutputItem) => void;
|
|
33
|
-
|
|
34
|
-
isValid: boolean;
|
|
35
|
-
message?: string;
|
|
36
|
-
}) => void;
|
|
37
|
-
executeCommand: (path: string[], args?: string[]) => Promise<void>;
|
|
38
|
-
executeHistoryCommand: (index: number) => Promise<void>;
|
|
18
|
+
executeCommand: () => Promise<void>;
|
|
39
19
|
clearHistory: () => Promise<void>;
|
|
40
20
|
}
|
|
21
|
+
export declare class OutputItem {
|
|
22
|
+
readonly timestamp: number;
|
|
23
|
+
readonly command: string[];
|
|
24
|
+
result: CommandResult;
|
|
25
|
+
constructor(segmentStack: SegmentStack, result?: CommandResult);
|
|
26
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CommandSegment } from './command-registry';
|
|
1
2
|
/**
|
|
2
3
|
* Supported storage mechanisms for command history
|
|
3
4
|
*/
|
|
@@ -22,7 +23,7 @@ export interface StorageConfig {
|
|
|
22
23
|
* Represents a command entry to be stored in history
|
|
23
24
|
*/
|
|
24
25
|
export interface StoredCommand {
|
|
25
|
-
|
|
26
|
+
commandSegments: CommandSegment[];
|
|
26
27
|
timestamp: number;
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
@@ -32,11 +33,11 @@ export interface CommandStorage {
|
|
|
32
33
|
/**
|
|
33
34
|
* Add a command to storage
|
|
34
35
|
*/
|
|
35
|
-
|
|
36
|
+
addStoredCommand: (command: StoredCommand) => Promise<void>;
|
|
36
37
|
/**
|
|
37
38
|
* Get all stored commands
|
|
38
39
|
*/
|
|
39
|
-
|
|
40
|
+
getStoredCommands: () => Promise<StoredCommand[] | []>;
|
|
40
41
|
/**
|
|
41
42
|
* Clear all stored commands
|
|
42
43
|
*/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare enum LogLevel {
|
|
2
|
+
NONE = 0,
|
|
3
|
+
ERROR = 1,
|
|
4
|
+
WARN = 2,
|
|
5
|
+
INFO = 3,
|
|
6
|
+
DEBUG = 4,
|
|
7
|
+
TRACE = 5
|
|
8
|
+
}
|
|
9
|
+
export declare class Logger {
|
|
10
|
+
private static level;
|
|
11
|
+
private static prefix;
|
|
12
|
+
static configure(config: {
|
|
13
|
+
level: LogLevel;
|
|
14
|
+
prefix?: string;
|
|
15
|
+
}): void;
|
|
16
|
+
static trace(...args: any[]): void;
|
|
17
|
+
static debug(...args: any[]): void;
|
|
18
|
+
static info(...args: any[]): void;
|
|
19
|
+
static warn(...args: any[]): void;
|
|
20
|
+
static error(...args: any[]): void;
|
|
21
|
+
}
|
package/dist/src/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "citadel_cli",
|
|
3
|
-
"description": "A hierarchical command line
|
|
3
|
+
"description": "A hierarchical command line (CLI) for your webapp",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"react",
|
|
6
6
|
"command",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/jchilders/
|
|
15
|
+
"url": "git+https://github.com/jchilders/citadel_cli.git"
|
|
16
16
|
},
|
|
17
|
-
"version": "1.
|
|
17
|
+
"version": "1.1.0",
|
|
18
18
|
"type": "module",
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "tsc && vite build",
|