MCPcopy Create free account
hub / github.com/agenticsorg/edge-agents / main

Function main

scripts/sparc2/src/cli/cli.ts:775–895  ·  view source on GitHub ↗
(args: string[] = Deno.args)

Source from the content-addressed store, hash-verified

773 * @param args Command line arguments
774 */
775export async function main(args: string[] = Deno.args): Promise<void> {
776 try {
777 // Parse command and options
778 if (args.length === 0) {
779 printHelp();
780 return;
781 }
782
783 const commandName = args[0];
784
785 if (commandName === "--help" || commandName === "-h") {
786 printHelp();
787 return;
788 }
789
790 if (commandName === "--version" || commandName === "-v") {
791 console.log(`SPARC2 CLI v${VERSION}`);
792 return;
793 }
794
795 const command = commands.find((cmd) => cmd.name === commandName);
796
797 if (!command) {
798 console.error(`Unknown command: ${commandName}`);
799 printHelp();
800 Deno.exit(1);
801 }
802
803 // Check if command-specific help is requested
804 if (args.includes("--help") || args.includes("-h")) {
805 printCommandHelp(command);
806 return;
807 }
808
809 // Parse command options
810 const options: Record<string, any> = {};
811 const commandArgs: Record<string, any> = {};
812
813 for (let i = 1; i < args.length; i++) {
814 const arg = args[i];
815
816 if (arg.startsWith("--")) {
817 // Long option
818 const optionName = arg.slice(2);
819 const option = command.options.find((opt) => opt.name === optionName);
820
821 if (!option) {
822 console.error(`Unknown option: ${arg}`);
823 Deno.exit(1);
824 }
825
826 if (option.type === "boolean") {
827 options[optionName] = true;
828 } else {
829 if (i + 1 >= args.length) {
830 console.error(`Option ${arg} requires a value`);
831 Deno.exit(1);
832 }

Callers 5

testAnalyzeCommandFunction · 0.90
testExecuteCommandFunction · 0.90
testConfigCommandFunction · 0.90
testHelpCommandFunction · 0.90
cli.tsFile · 0.70

Calls 2

printCommandHelpFunction · 0.85
printHelpFunction · 0.70

Tested by

no test coverage detected