From 2e4fc6a84df258ab33a861ffc6817e4ed5906dbb Mon Sep 17 00:00:00 2001 From: Mike Wu Date: Wed, 13 Mar 2024 22:20:34 +0900 Subject: [PATCH] feat: auto-submit on -y flag (#124) --- cli.ts | 6 ++++++ lib/interact-for-open-api-object.ts | 6 ++++++ lib/types.ts | 1 + 3 files changed, 13 insertions(+) diff --git a/cli.ts b/cli.ts index c94e043..0a66681 100644 --- a/cli.ts +++ b/cli.ts @@ -115,8 +115,14 @@ async function cli(args: ParsedArgs) { const commandParams: Record = {} + /** + * Whether or not to auto-select first option + */ + const is_interactive = args.y !== true + const ctx: ContextHelpers = { api, + is_interactive, } for (const k in args) { diff --git a/lib/interact-for-open-api-object.ts b/lib/interact-for-open-api-object.ts index 1997b0e..52020a5 100644 --- a/lib/interact-for-open-api-object.ts +++ b/lib/interact-for-open-api-object.ts @@ -46,6 +46,12 @@ export const interactForOpenApiObject = async ( const haveAllRequiredParams = required.every((k) => args.params[k]) + const should_auto_submit = + !ctx.is_interactive && haveAllRequiredParams && !args.isSubProperty + if (should_auto_submit) { + return args.params + } + const propSortScore = (prop: string) => { if (required.includes(prop)) return 100 - ergonomicPropOrder.indexOf(prop) if (args.params[prop] !== undefined) diff --git a/lib/types.ts b/lib/types.ts index 1125710..602d3dc 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -2,4 +2,5 @@ import { ApiDefinitions } from "./get-api-definitions" export interface ContextHelpers { api: ApiDefinitions + is_interactive: boolean }