@acomo/cli 1.0.17 → 1.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -14037,7 +14037,7 @@ var EXIT_CODES = {
14037
14037
  VALIDATION: 3,
14038
14038
  NOT_FOUND: 4
14039
14039
  };
14040
- async function resolveParams(positional) {
14040
+ async function resolveBody(positional) {
14041
14041
  if (positional) {
14042
14042
  try {
14043
14043
  return JSON.parse(positional);
@@ -14047,6 +14047,12 @@ async function resolveParams(positional) {
14047
14047
  }
14048
14048
  return void 0;
14049
14049
  }
14050
+ function buildClientParams(operationId, namedParams, body) {
14051
+ const paramInfo = getOperationRequestSchema(operationId);
14052
+ if (!paramInfo?.requestBody) return namedParams;
14053
+ const { dtoName } = paramInfo.requestBody;
14054
+ return { ...namedParams, [dtoName]: body ?? {} };
14055
+ }
14050
14056
  function placeholderForType(type) {
14051
14057
  if (type === "string") return "";
14052
14058
  if (type === "number" || type === "integer") return 0;
@@ -14056,13 +14062,6 @@ function placeholderForType(type) {
14056
14062
  return {};
14057
14063
  return "";
14058
14064
  }
14059
- function buildExampleParams(params) {
14060
- const out = {};
14061
- for (const p of params) {
14062
- if (p.required) out[p.name] = placeholderForType(p.type);
14063
- }
14064
- return out;
14065
- }
14066
14065
  function buildExampleBody(properties) {
14067
14066
  const out = {};
14068
14067
  for (const p of properties) {
@@ -14166,7 +14165,6 @@ function buildApiCommandHelpDescriptor(operationId) {
14166
14165
  const pathParams = paramInfo.params.filter((p) => p.in === "path").map(toParamEntry);
14167
14166
  const queryParams = paramInfo.params.filter((p) => p.in === "query").map(toParamEntry);
14168
14167
  const requestBody = paramInfo.requestBody ? {
14169
- dtoName: paramInfo.requestBody.dtoName,
14170
14168
  properties: paramInfo.requestBody.properties.map((p) => {
14171
14169
  const entry = {
14172
14170
  name: p.name,
@@ -14178,29 +14176,38 @@ function buildApiCommandHelpDescriptor(operationId) {
14178
14176
  return entry;
14179
14177
  })
14180
14178
  } : null;
14181
- const minimalArgs = {
14182
- ...buildExampleParams(paramInfo.params)
14183
- };
14184
- if (paramInfo.requestBody) {
14185
- const bodyExample = buildExampleBody(paramInfo.requestBody.properties);
14186
- for (const [k, v] of Object.entries(bodyExample)) minimalArgs[k] = v;
14187
- }
14188
- const exampleCommand = `acomo ${operationId} '${JSON.stringify(minimalArgs)}'`;
14189
- const positionals = [
14179
+ const paramOptions = paramInfo.params.map((p) => ({
14180
+ name: p.name,
14181
+ type: p.type === "number" || p.type === "integer" ? "number" : p.type === "boolean" ? "boolean" : "string",
14182
+ description: normalizeDescription(p.description || ""),
14183
+ required: p.required
14184
+ }));
14185
+ const minimalArgs = paramInfo.requestBody ? buildExampleBody(paramInfo.requestBody.properties) : null;
14186
+ const optionsPart = paramInfo.params.filter((p) => p.required).map(
14187
+ (p) => `--${p.name} ${p.example !== void 0 ? String(p.example) : `<${p.type}>`}`
14188
+ ).join(" ");
14189
+ const bodyPart = minimalArgs && Object.keys(minimalArgs).length > 0 ? ` '${JSON.stringify(minimalArgs)}'` : "";
14190
+ const exampleCommand = `acomo ${operationId}${optionsPart ? " " + optionsPart : ""}${bodyPart}`;
14191
+ const hasBody = !!paramInfo.requestBody;
14192
+ const hasParams = paramInfo.params.length > 0;
14193
+ const usageParts = [`acomo ${operationId}`];
14194
+ if (hasParams) usageParts.push("[--option value...]");
14195
+ if (hasBody) usageParts.push("[body]");
14196
+ const positionals = hasBody ? [
14190
14197
  {
14191
- name: "params",
14198
+ name: "body",
14192
14199
  type: "object",
14193
14200
  required: false,
14194
- description: "JSON \u30D1\u30E9\u30E1\u30FC\u30BF"
14201
+ description: "\u30EA\u30AF\u30A8\u30B9\u30C8\u30DC\u30C7\u30A3 JSON"
14195
14202
  }
14196
- ];
14203
+ ] : [];
14197
14204
  return buildCommandHelp({
14198
14205
  command: operationId,
14199
14206
  kind: "api-command",
14200
14207
  summary,
14201
- usage: `acomo ${operationId} [params]`,
14208
+ usage: usageParts.join(" "),
14202
14209
  positionals,
14203
- options: GLOBAL_OPTIONS2,
14210
+ options: [...paramOptions, ...GLOBAL_OPTIONS2],
14204
14211
  inputSchema: {
14205
14212
  pathParams,
14206
14213
  queryParams,
@@ -14328,7 +14335,29 @@ async function main() {
14328
14335
  const pkg = JSON.parse(
14329
14336
  readFileSync4(resolve5(scriptDir, "../package.json"), "utf-8")
14330
14337
  );
14331
- const argv = yargs_default(hideBin(process.argv)).scriptName("acomo").usage("Usage: $0 <command> [options]").help().alias("h", "help").version(pkg.version).alias("v", "version");
14338
+ const argv = yargs_default(hideBin(process.argv)).scriptName("acomo").usage("Usage: $0 <command> [options]").help().alias("h", "help").version(pkg.version).alias("v", "version").fail((msg, _err, yargs) => {
14339
+ if (msg === "\u30B3\u30DE\u30F3\u30C9\u3092\u6307\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044\u3002") {
14340
+ yargs.showHelp();
14341
+ process.exit(0);
14342
+ }
14343
+ const jsonMode = !process.stdout.isTTY;
14344
+ if (jsonMode) {
14345
+ console.error(
14346
+ JSON.stringify({
14347
+ error: true,
14348
+ code: "VALIDATION_ERROR",
14349
+ message: msg,
14350
+ suggestion: "\u5FC5\u9808\u30D1\u30E9\u30E1\u30FC\u30BF\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002`acomo <command> --help` \u3067\u30D1\u30E9\u30E1\u30FC\u30BF\u60C5\u5831\u3092\u78BA\u8A8D\u3067\u304D\u307E\u3059\u3002"
14351
+ })
14352
+ );
14353
+ } else {
14354
+ console.error(`\u5FC5\u9808\u30D1\u30E9\u30E1\u30FC\u30BF\u304C\u4E0D\u8DB3\u3057\u3066\u3044\u307E\u3059: ${msg}`);
14355
+ console.error(
14356
+ "`acomo <command> --help` \u3067\u30D1\u30E9\u30E1\u30FC\u30BF\u60C5\u5831\u3092\u78BA\u8A8D\u3067\u304D\u307E\u3059\u3002"
14357
+ );
14358
+ }
14359
+ process.exit(EXIT_CODES.VALIDATION);
14360
+ });
14332
14361
  argv.command(
14333
14362
  command2(),
14334
14363
  describe(),
@@ -14360,20 +14389,45 @@ async function main() {
14360
14389
  const registry = buildOperationRegistry(configuration);
14361
14390
  for (const [operationId] of registry) {
14362
14391
  const paramInfo = getOperationRequestSchema(operationId);
14392
+ const hasBody = !!paramInfo?.requestBody;
14363
14393
  argv.command(
14364
- `${operationId} [params]`,
14394
+ hasBody ? `${operationId} [body]` : operationId,
14365
14395
  operationDescriptions[operationId] ?? operationId,
14366
14396
  (y) => {
14367
- y.positional("params", {
14368
- type: "string",
14369
- description: "JSON \u30D1\u30E9\u30E1\u30FC\u30BF"
14370
- });
14397
+ if (paramInfo) {
14398
+ for (const p of paramInfo.params) {
14399
+ const yargsType = p.type === "number" || p.type === "integer" ? "number" : p.type === "boolean" ? "boolean" : "string";
14400
+ y.option(p.name, {
14401
+ type: yargsType,
14402
+ description: p.description,
14403
+ demandOption: p.required
14404
+ });
14405
+ }
14406
+ }
14407
+ if (hasBody) {
14408
+ y.positional("body", {
14409
+ type: "string",
14410
+ description: "\u30EA\u30AF\u30A8\u30B9\u30C8\u30DC\u30C7\u30A3 JSON"
14411
+ });
14412
+ }
14371
14413
  return y;
14372
14414
  },
14373
14415
  async (cmdArgv) => {
14374
14416
  try {
14375
- const params = await resolveParams(
14376
- cmdArgv.params
14417
+ const body = await resolveBody(
14418
+ cmdArgv.body
14419
+ );
14420
+ const namedParams = {};
14421
+ if (paramInfo) {
14422
+ for (const p of paramInfo.params) {
14423
+ const val = cmdArgv[p.name];
14424
+ if (val !== void 0) namedParams[p.name] = val;
14425
+ }
14426
+ }
14427
+ const clientParams = buildClientParams(
14428
+ operationId,
14429
+ namedParams,
14430
+ body
14377
14431
  );
14378
14432
  const entry = registry.get(operationId);
14379
14433
  const apiConfig = createConfiguration();
@@ -14381,7 +14435,7 @@ async function main() {
14381
14435
  apiConfig
14382
14436
  );
14383
14437
  const rawResponse = await instance[entry.method + "Raw"](
14384
- params ?? {}
14438
+ clientParams
14385
14439
  );
14386
14440
  if (!rawResponse.raw.ok) {
14387
14441
  throw new ResponseError(