Skip to content

Commit

Permalink
feat: auto-submit on -y flag (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikewuu authored Mar 13, 2024
1 parent a5de0c5 commit 2e4fc6a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,14 @@ async function cli(args: ParsedArgs) {

const commandParams: Record<string, any> = {}

/**
* 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) {
Expand Down
6 changes: 6 additions & 0 deletions lib/interact-for-open-api-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import { ApiDefinitions } from "./get-api-definitions"

export interface ContextHelpers {
api: ApiDefinitions
is_interactive: boolean
}

0 comments on commit 2e4fc6a

Please sign in to comment.