Skip to content

Commit cd3a2d7

Browse files
committed
core: Updated shell tests + docs
1 parent 8384e85 commit cd3a2d7

9 files changed

Lines changed: 380 additions & 140 deletions

File tree

packages/core/src/features/shell/command.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,52 @@
11
import { ShellContext } from "./shell";
22

3+
/**
4+
* Represents a command-line flag or parameter.
5+
*/
36
export interface Option {
7+
/** The full name of the option (e.g., "all" for --all). */
48
long: string;
9+
/** The single-character alias (e.g., "a" for -a). */
510
short: string;
11+
/** If true, the shell expects a value to follow this option (e.g., --file <name>). */
612
isInput: boolean;
713
}
814

15+
/**
16+
* Documentation metadata used by the `help` or `man` commands.
17+
*/
918
export interface Manual {
19+
/** A brief one-line summary of what the command does. */
1020
purpose?: string;
21+
/** A string representing the syntax (e.g., "ls [OPTION]... [FILE]..."). */
1122
usage?: string;
23+
/** A detailed explanation of the command's behavior. */
1224
description?: string;
25+
/** A mapping of option names to their descriptions for the help output. */
1326
options?: object;
1427
}
1528

1629
export type CommandOutput = number | undefined | void;
1730
export type Execute = (args: string[], context: ShellContext) => Promise<CommandOutput> | CommandOutput;
1831

32+
/**
33+
* Defines a shell command, including its execution logic, arguments requirements, and manual page.
34+
*/
1935
export class Command {
2036
#name?: string;
2137
options: Option[] = [];
2238
manual?: Manual;
2339
requireArgs?: boolean;
2440
requireOptions?: boolean;
2541

42+
/**
43+
* The core logic to run when the command is invoked.
44+
*/
2645
execute: Execute = () => {};
2746

47+
/**
48+
* Sets the command name and initializes the default usage string if not already set.
49+
*/
2850
setName(name?: string): Command {
2951
this.#name = name;
3052

@@ -60,11 +82,17 @@ export class Command {
6082
return this;
6183
}
6284

85+
/**
86+
* Registers a new option/flag for this command.
87+
*/
6388
addOption({ short, long, isInput = false }: Omit<Option, "isInput"> & { isInput?: boolean }): Command {
6489
this.options.push({ short, long, isInput });
6590
return this;
6691
}
6792

93+
/**
94+
* Retrieves an option definition by either its short or long name.
95+
*/
6896
getOption(key: string): Option | undefined {
6997
return this.options.find((option) => option.short === key || option.long === key);
7098
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export * from "./command";
22
export * from "./commands";
33
export * from "./shell";
4-
export * from "./stream";
4+
export * from "./stream";
5+
export * from "./shellEnvironment";
6+
export * from "./shellInterpreter";

0 commit comments

Comments
 (0)