MCPcopy
hub / github.com/scribbletune/scribbletune / runCli

Function runCli

src/cli.ts:438–473  ·  view source on GitHub ↗
(argv: string[], deps?: CliDeps)

Source from the content-addressed store, hash-verified

436};
437
438export const runCli = (argv: string[], deps?: CliDeps): number => {
439 const stdout = deps?.stdout || console.log;
440 const stderr = deps?.stderr || console.error;
441 const writeMidi =
442 deps?.writeMidi ||
443 ((notes, fileName, bpm) => {
444 midi(notes, fileName, bpm);
445 });
446
447 try {
448 const parsed = parseCliArgs(argv);
449 if (!parsed) {
450 stdout(HELP_TEXT);
451 return 0;
452 }
453
454 let notes: NoteObject[] = [];
455 if (parsed.command === 'riff') {
456 notes = makeRiff(parsed);
457 } else if (parsed.command === 'chord') {
458 notes = makeChord(parsed);
459 } else {
460 notes = makeArp(parsed);
461 }
462
463 writeMidi(notes, parsed.outfile, parsed.bpm);
464 stdout(
465 `Generated ${parsed.command} clip (${notes.length} events) -> ${parsed.outfile}`
466 );
467 return 0;
468 } catch (e) {
469 stderr(e instanceof Error ? e.message : String(e));
470 stderr('Run with --help for usage');
471 return 1;
472 }
473};
474
475if (process.argv[1]?.includes('cli')) {
476 process.exit(runCli(process.argv.slice(2)));

Callers 2

cli.spec.tsFile · 0.90
cli.tsFile · 0.85

Calls 5

midiFunction · 0.90
parseCliArgsFunction · 0.85
makeRiffFunction · 0.85
makeChordFunction · 0.85
makeArpFunction · 0.85

Tested by

no test coverage detected