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

Function getCommandArguments

cli/src/cli/registryCore.ts:61–89  ·  view source on GitHub ↗
(
    command: Command,
    argv: string[],
)

Source from the content-addressed store, hash-verified

59 options: command.options || {},
60 strict: true,
61 allowPositionals: true,
62 });
63 const args = positionals.slice(4);
64 validateCommandArguments(command, args, options);
65 return { options, args };
66 } catch (error) {
67 if (error instanceof InvalidCommandArgumentsError) {
68 throw error;
69 }
70 if (error instanceof TypeError) {
71 printCommandUsage(command);
72 throw new InvalidCommandArgumentsError(error.message);
73 }
74 throw error;
75 }
76}
77
78function validateCommandArguments(command: Command, args: string[], values: { [name: string]: unknown }) {
79 if (values['help']) {
80 return;
81 }
82
83 if (command.args) {
84 const hasVariableArgs = command.args.some((arg) => arg.endsWith('...'));
85 const hasExpectedArgs = hasVariableArgs
86 ? args.length >= command.args.length
87 : args.length === command.args.length;
88 if (!hasExpectedArgs) {
89 printCommandUsage(command);
90 throw new InvalidCommandArgumentsError(`Expected ${command.args.length} arguments, got ${args.length}`);
91 }
92 }

Callers 1

parseCliInvocationFunction · 0.90

Calls 2

printCommandUsageFunction · 0.90
validateCommandArgumentsFunction · 0.85

Tested by

no test coverage detected