Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add [Back] option #76

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -105,6 +105,10 @@ export const interactForOpenApiObject = async (
},
]
: []),
{
title: `[Back]`,
value: "back",
},
],
})

Expand All @@ -117,6 +121,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
Loading