quip-cli
Version:
A Command Line Interface for the Quip Live Apps platform
129 lines (128 loc) • 5.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const command_1 = require("@oclif/command");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
const cli_api_1 = tslib_1.__importStar(require("../lib/cli-api"));
const config_1 = require("../lib/config");
const print_1 = require("../lib/print");
class Apps extends command_1.Command {
async run() {
const { args, flags } = this.parse(Apps);
const fetch = await cli_api_1.default(flags.config, flags.site);
const handleAppId = async (id) => {
const printAppInfo = async (id, version = null) => {
const appInfo = await cli_api_1.successOnly(fetch(`app/${id}` + (version !== null ? "" : `/${version}`)), flags.json);
if (appInfo) {
print_1.print(chalk_1.default `
{magenta ${appInfo.name} v${appInfo.version_name} (${appInfo.version_number})}
`);
print_1.prettyPrintObject(appInfo);
}
};
if (flags.version) {
return await printAppInfo(flags.version);
}
const versions = await cli_api_1.successOnly(fetch(`app/${id}/versions`), flags.json);
if (!versions) {
return;
}
print_1.print(chalk_1.default `
{magenta ${versions.name}}
`);
const { release, development } = versions;
const otherVersions = versions.versions
.filter((v) => v.version_number !== (release === null || release === void 0 ? void 0 : release.version_number) &&
v.version_number !== (development === null || development === void 0 ? void 0 : development.version_number))
.map((v) => (Object.assign(Object.assign({}, v), { icon: v.released ? "⚓️" : "" })));
const releasedVersions = [];
if (release) {
releasedVersions.push(Object.assign(Object.assign({}, release), { icon: "🚢" }));
}
if (development) {
releasedVersions.push(Object.assign(Object.assign({}, development), { icon: "🧪" }));
}
const response = await inquirer_1.default.prompt([
{
type: "list",
name: "version",
message: "Select a version (🚢: prod, 🧪: beta, ⚓️: previously released)",
choices: releasedVersions
.concat(otherVersions)
.map((v) => ({
name: chalk_1.default `{green ${v.version_name} (${v.version_number}) ${v.icon}}`,
value: v.version_number,
})),
},
]);
if (response && response.version) {
printAppInfo(id, response.version);
}
};
if (flags.id) {
handleAppId(flags.id);
}
else {
const apps = await cli_api_1.successOnly(fetch("apps"), flags.json);
if (apps) {
const choices = [
new inquirer_1.default.Separator(chalk_1.default `{green === Released ===}`),
...apps.released.map((app) => ({
name: chalk_1.default `{green ${app.id}: ${app.name}}`,
value: app.id,
})),
new inquirer_1.default.Separator(chalk_1.default `{yellow === Development ===}`),
...apps.development.map((app) => ({
name: chalk_1.default `{yellow ${app.id}: ${app.name}}`,
value: app.id,
})),
new inquirer_1.default.Separator(chalk_1.default `{red === Disabled ===}`),
...apps.disabled.map((app) => ({
name: chalk_1.default `{red ${app.id}: ${app.name}}`,
value: app.id,
})),
];
const response = await inquirer_1.default.prompt([
{
type: "list",
name: "id",
message: chalk_1.default `{magenta Select an Application}`,
choices,
},
]);
if (response && response.id) {
handleAppId(response.id);
}
}
}
}
}
exports.default = Apps;
Apps.description = "Browse, inspect, and manipulate your Apps";
Apps.flags = {
help: command_1.flags.help({ char: "h" }),
site: command_1.flags.string({
char: "s",
description: "use a specific quip site rather than the standard quip.com login",
default: config_1.DEFAULT_SITE,
}),
id: command_1.flags.string({
char: "i",
description: "show the details of an app ID",
}),
version: command_1.flags.string({
char: "v",
description: "which version to show the details for. Only useful with --id",
}),
json: command_1.flags.boolean({
char: "j",
description: "output responses in JSON",
}),
config: command_1.flags.string({
hidden: true,
description: "Use a custom config file (default ~/.quiprc)",
default: () => config_1.defaultConfigPath(),
}),
};
Apps.args = [];