Skip to content

Commit 2e4fc6a

Browse files
authored
feat: auto-submit on -y flag (#124)
1 parent a5de0c5 commit 2e4fc6a

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

cli.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,14 @@ async function cli(args: ParsedArgs) {
115115

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

118+
/**
119+
* Whether or not to auto-select first option
120+
*/
121+
const is_interactive = args.y !== true
122+
118123
const ctx: ContextHelpers = {
119124
api,
125+
is_interactive,
120126
}
121127

122128
for (const k in args) {

lib/interact-for-open-api-object.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ export const interactForOpenApiObject = async (
4646

4747
const haveAllRequiredParams = required.every((k) => args.params[k])
4848

49+
const should_auto_submit =
50+
!ctx.is_interactive && haveAllRequiredParams && !args.isSubProperty
51+
if (should_auto_submit) {
52+
return args.params
53+
}
54+
4955
const propSortScore = (prop: string) => {
5056
if (required.includes(prop)) return 100 - ergonomicPropOrder.indexOf(prop)
5157
if (args.params[prop] !== undefined)

lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import { ApiDefinitions } from "./get-api-definitions"
22

33
export interface ContextHelpers {
44
api: ApiDefinitions
5+
is_interactive: boolean
56
}

0 commit comments

Comments
 (0)