-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(templates): split template into os-template and custom-template (#…
…72)
- Loading branch information
Showing
11 changed files
with
1,235 additions
and
1,085 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { client } from "./client.ts"; | ||
|
||
export const templates = { | ||
create: client("/templates").post, | ||
get: client("/templates/{id}").get, | ||
list: client("/templates").get, | ||
delete: client("/templates/{id}").delete, | ||
export const customTemplates = { | ||
create: client("/custom-templates").post, | ||
get: client("/custom-templates/{id}").get, | ||
list: client("/custom-templates").get, | ||
delete: client("/custom-templates/{id}").delete, | ||
}; | ||
|
||
export const osTemplates = { | ||
list: client("/os-templates").get, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { command, flag, flags } from "../../../zcli.ts"; | ||
import { asserts } from "../../../lib/asserts.ts"; | ||
import { dataTable } from "../../../lib/data-table.ts"; | ||
import { loading } from "../../../lib/loading.ts"; | ||
import * as psFlags from "../../../flags.ts"; | ||
import { pickJson } from "../../../lib/pick-json.ts"; | ||
import { osTemplates } from "../../../api/templates.ts"; | ||
import { defaultFields } from "../mod.ts"; | ||
|
||
/** | ||
* This variable is automatically generated by `zcli add`. Do not remove this | ||
* or change its name unless you're no longer using `zcli add`. | ||
*/ | ||
const subCommands: ReturnType<typeof command>[] = []; | ||
|
||
export const list = command("list", { | ||
short: "List OS templates.", | ||
long: ({ root }) => ` | ||
List OS templates. | ||
Pick a subset of fields to display: | ||
\`\`\` | ||
${root.name} os-template list -F name | ||
\`\`\` | ||
`, | ||
commands: subCommands, | ||
flags: psFlags.paginator.merge(flags({ | ||
"name": flag({ | ||
aliases: ["n"], | ||
short: "Filter by name.", | ||
}).ostring(), | ||
})), | ||
// We use command metadata in the `persistentPreRun` function to check if a | ||
// command requires an API key. If it does, we'll check to see if one is | ||
// set. If not, we'll throw an error. | ||
meta: { | ||
requireApiKey: true, | ||
}, | ||
}).run( | ||
async function* ({ flags }) { | ||
const result = await loading( | ||
osTemplates.list({ | ||
limit: flags.limit, | ||
after: flags.after, | ||
orderBy: "name", | ||
order: flags.asc ? "asc" : undefined, | ||
name: flags.name, | ||
}), | ||
{ enabled: !flags.json }, | ||
); | ||
|
||
asserts(result.ok, result); | ||
|
||
if (!flags.json) { | ||
for await ( | ||
const line of dataTable( | ||
result.data.items, | ||
flags.fields ?? defaultFields, | ||
) | ||
) { | ||
yield line; | ||
} | ||
} else { | ||
yield pickJson(result.data, flags.fields); | ||
} | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { command } from "../../zcli.ts"; | ||
import { list } from "./list/mod.ts"; | ||
import { env } from "../../env.ts"; | ||
|
||
export const defaultFields = [ | ||
"id", | ||
"name", | ||
"operatingSystemLabel", | ||
"defaultSizeGb", | ||
]; | ||
|
||
/** | ||
* This variable is automatically generated by `zcli add`. Do not remove this | ||
* or change its name unless you're no longer using `zcli add`. | ||
*/ | ||
const subCommands: ReturnType<typeof command>[] = [ | ||
list, | ||
]; | ||
|
||
export const osTemplate = command("os-template", { | ||
short: "List OS templates", | ||
long: ` | ||
List OS templates. OS templates are pre-configured virtual machines that | ||
you can use to create a new machine. | ||
For more information, see ${new URL( | ||
"/compute/os-templates", | ||
env.get("PAPERSPACE_DOCS_URL"), | ||
)}. | ||
`, | ||
commands: subCommands, | ||
}).run(function* ({ ctx }) { | ||
for (const line of osTemplate.help(ctx)) { | ||
yield line; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters