storebound/cli/lib/args.ts
CRT 1ed3f12eee storebound api: every App Store Connect and Google Play operation
- specs/: Apple's App Store Connect OpenAPI 4.5.1 and the Google discovery docs for androidpublisher v3 and
  playdeveloperreporting v1beta1, pinned with URL, date and SHA-256 (specs/SOURCES.json)
- tools/gen-api.ts: one row per operation (cli/api/apple.gen.ts 1303, cli/api/play.gen.ts 170), a scan of which
  operations the commands already call (cli/api/wrapped.gen.ts) and docs/api-coverage.md; CI checks freshness
- cli/api/client.ts + types.ts: generic URL / parameter building, retries with Retry-After, pagination, types derived
  from the rows; auth reuses ascJwt and the Play service account
- cli/api/gate.ts: GET runs, writes dry unless --yes in a TTY, owner-only operations need the id typed, nothing
  written under MCP or serve; MCP gets the read-only api_get
- storebound api list | coverage | apple|play <op|METHOD path>; skill store-api, README, CHANGELOG, tests
2026-10-11 15:37:09 +00:00

39 lines
1.6 KiB
TypeScript

// Tiny argv parser: positionals, --flag, --key value, --key=value.
export interface Args {
_: string[];
has(name: string): boolean;
get(name: string): string | undefined;
str(name: string, d: string): string;
num(name: string, d: number): number;
list(name: string): string[];
/** Every value of a flag given more than once (--param a=1 --param b=2), in order. */
many(name: string): string[];
}
export function parseArgs(argv: string[], booleans: string[] = []): Args {
const flags = new Map<string, string>();
const repeated = new Map<string, string[]>();
const set = (k: string, v: string) => { flags.set(k, v); repeated.set(k, [...(repeated.get(k) ?? []), v]); };
const _: string[] = [];
const bool = new Set(['dry', 'yes', 'help', 'json', 'verbose', 'all-pages', ...booleans]);
for (let i = 0; i < argv.length; i++) {
const a = argv[i]!;
if (!a.startsWith('--')) { _.push(a); continue; }
const eq = a.indexOf('=');
if (eq > 0) { set(a.slice(2, eq), a.slice(eq + 1)); continue; }
const name = a.slice(2);
const next = argv[i + 1];
if (bool.has(name) || name.startsWith('no-') || next === undefined || next.startsWith('--')) set(name, 'true');
else { set(name, next); i++; }
}
const get = (n: string) => flags.get(n);
return {
_,
has: n => flags.has(n),
get,
str: (n, d) => get(n) ?? d,
num: (n, d) => { const v = get(n); const x = v === undefined ? d : Number(v); if (Number.isNaN(x)) throw new Error(`--${n}: not a number`); return x; },
list: n => (get(n) ?? '').split(',').map(s => s.trim()).filter(Boolean),
many: n => repeated.get(n) ?? [],
};
}