MCPcopy Create free account
hub / github.com/ProtonDriveApps/sdk / getCommand

Function getCommand

cli/src/cli/registryCore.ts:30–59  ·  view source on GitHub ↗
(
    commands: Command[],
    groupName: string,
    commandName: string,
    initOptions: InitConfig,
)

Source from the content-addressed store, hash-verified

28
29export function getCommand(commands: Command[], groupName: string, commandName: string): Command {
30 if (groupName === 'fs') {
31 groupName = 'filesystem';
32 }
33
34 let matches = commands.filter((command) => command.group.startsWith(groupName) && command.name === commandName);
35 if (matches.length === 1) {
36 return matches[0];
37 }
38
39 matches = commands.filter((command) => command.group.startsWith(groupName) && command.name.startsWith(commandName));
40 if (matches.length === 1) {
41 return matches[0];
42 }
43
44 if (matches.length === 0) {
45 matches = commands.filter((command) => command.group.startsWith(groupName));
46 }
47
48 printUsage(matches.length > 0 ? matches : commands);
49 throw new CommandNotFoundError(`Command not found: ${groupName || ''} ${commandName || ''}`);
50}
51
52export function getCommandArguments(
53 command: Command,
54 argv: string[],
55): { options: { [name: string]: unknown }; args: string[] } {
56 try {
57 const { values: options, positionals } = parseArgs({
58 args: argv,
59 options: command.options || {},
60 strict: true,
61 allowPositionals: true,
62 });

Callers 1

parseCliInvocationFunction · 0.90

Calls 2

printUsageFunction · 0.90
filterMethod · 0.80

Tested by

no test coverage detected