Skip to content

Commit

Permalink
feat: add [Back] option (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikewuu authored Jan 25, 2024
1 parent 3c214e7 commit 814930b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,29 @@ async function cli(args: ParsedArgs) {
commandParams.accepted_providers.split(",")
}

// Hit 'back' on a top-level command path, so we start again
const lastCommandPath = selectedCommand.slice(-1)[0]
if (lastCommandPath === "[Back]") {
return await cli({
...args,
_: [],
})
}

const params = await interactForCommandParams(
{ command: selectedCommand, params: commandParams },
ctx
)

if (params === "[Back]") {
const previousCommands = [...selectedCommand]
previousCommands.pop()
return await cli({
...args,
_: previousCommands,
})
}

const seam = await getSeam()

const apiPath = `/${selectedCommand.join("/").replace(/-/g, "_")}`
Expand Down
6 changes: 6 additions & 0 deletions lib/interact-for-command-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export async function interactForCommandSelection(
["select", "server"],
])

// Add dynamic 'back' command for sub-commands to allow returning
// to previous level.
if (commandPath.length > 0) {
commands.push([...commandPath, "[Back]"])
}

const possibleCommands = uniqBy(
commandPath.length === 0
? commands
Expand Down
12 changes: 12 additions & 0 deletions lib/interact-for-open-api-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export const interactForOpenApiObject = async (
},
]
: []),
{
title: `[Back]`,
value: "back",
},
],
})

Expand All @@ -118,6 +122,14 @@ export const interactForOpenApiObject = async (
return args.params
}

if (paramToEdit === "back") {
if (args.subPropertyPath) {
return args.params
}

return "[Back]"
}

const prop = properties[paramToEdit]

if (paramToEdit === "device_id") {
Expand Down

0 comments on commit 814930b

Please sign in to comment.