From 284bc48c8a172a872b63044a1cbe7f7d0eedaf8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 27 May 2024 13:41:33 +0000 Subject: [PATCH 1/4] Improve CLI aliases --- templates/cli/index.js.twig | 4 +-- templates/cli/lib/commands/generic.js.twig | 21 +++++++------ templates/cli/lib/commands/pull.js.twig | 9 ++++-- templates/cli/lib/commands/push.js.twig | 34 +++++++++++++--------- 4 files changed, 39 insertions(+), 29 deletions(-) diff --git a/templates/cli/index.js.twig b/templates/cli/index.js.twig index 2126485c6..1466a5b54 100644 --- a/templates/cli/index.js.twig +++ b/templates/cli/index.js.twig @@ -26,8 +26,8 @@ program sortSubcommands: true }) .version(version, "-v, --version") - .option("--verbose", "Show complete error log") - .option("--json", "Output in JSON format") + .option("-V, --verbose", "Show complete error log") + .option("-j, --json", "Output in JSON format") .on("option:json", () => { cliConfig.json = true; }) diff --git a/templates/cli/lib/commands/generic.js.twig b/templates/cli/lib/commands/generic.js.twig index a8d6f91b5..96dec830f 100644 --- a/templates/cli/lib/commands/generic.js.twig +++ b/templates/cli/lib/commands/generic.js.twig @@ -3,15 +3,14 @@ const { Command } = require("commander"); const Client = require("../client"); const { sdkForConsole } = require("../sdks"); const { globalConfig, localConfig } = require("../config"); -const { actionRunner, success, parseBool, commandDescriptions, error, parse, drawTable } = require("../parser"); +const { actionRunner, success, parseBool, commandDescriptions, error, parse, drawTable, cliConfig } = require("../parser"); {% if sdk.test != "true" %} const { questionsLogin, questionsListFactors, questionsMfaChallenge } = require("../questions"); const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account"); const whoami = new Command("whoami") .description(commandDescriptions['whoami']) - .option("-j, --json", "Output in JSON format") - .action(actionRunner(async ({ json }) => { + .action(actionRunner(async () => { if (globalConfig.getEndpoint() === '' || globalConfig.getCookie() === '') { error("No user is signed in. To sign in, run: appwrite login "); return; @@ -39,9 +38,9 @@ const whoami = new Command("whoami") 'MFA enabled': account.mfa ? 'Yes' : 'No' } ]; - if (json) { - console.log(data); + if(cliConfig.json) { + console.log(data); return; } @@ -129,12 +128,12 @@ const client = new Command("client") .configureHelp({ helpWidth: process.stdout.columns || 80 }) - .option("--selfSigned ", "Configure the CLI to use a self-signed certificate ( true or false )", parseBool) - .option("--endpoint ", "Set your Appwrite server endpoint") - .option("--projectId ", "Set your Appwrite project ID") - .option("--key ", "Set your Appwrite server's API key") - .option("--debug", "Print CLI debug information") - .option("--reset", "Reset the CLI configuration") + .option("-ss, --selfSigned ", "Configure the CLI to use a self-signed certificate ( true or false )", parseBool) + .option("-e, --endpoint ", "Set your Appwrite server endpoint") + .option("-p, --projectId ", "Set your Appwrite project ID") + .option("-k, --key ", "Set your Appwrite server's API key") + .option("-d, --debug", "Print CLI debug information") + .option("-r, --reset", "Reset the CLI configuration") .action(actionRunner(async ({ selfSigned, endpoint, projectId, key, debug, reset }, command) => { if (selfSigned == undefined && endpoint == undefined && projectId == undefined && key == undefined && debug == undefined && reset == undefined) { command.help() diff --git a/templates/cli/lib/commands/pull.js.twig b/templates/cli/lib/commands/pull.js.twig index 41c2ea9d1..22bdc3ae9 100644 --- a/templates/cli/lib/commands/pull.js.twig +++ b/templates/cli/lib/commands/pull.js.twig @@ -258,28 +258,33 @@ pull pull .command("function") + .alias("functions") .description("Pulling your {{ spec.title|caseUcfirst }} cloud function") .action(actionRunner(pullFunction)) pull .command("collection") + .command("collections") .description("Pulling your {{ spec.title|caseUcfirst }} collections") - .option(`--databaseId `, `Database ID`) - .option(`--all`, `Flag to pullialize all databases`) + .option(`-d, --databaseId `, `Database ID`) + .option(`-a, --all`, `Flag to pullialize all databases`) .action(actionRunner(pullCollection)) pull .command("bucket") + .command("buckets") .description("Pulling your Appwrite buckets") .action(actionRunner(pullBucket)) pull .command("team") + .command("teams") .description("Pulling your Appwrite teams") .action(actionRunner(pullTeam)) pull .command("topic") + .command("topics") .description("Initialise your Appwrite messaging topics") .action(actionRunner(pullMessagingTopic)) diff --git a/templates/cli/lib/commands/push.js.twig b/templates/cli/lib/commands/push.js.twig index 8e269cdd4..4eb801e12 100644 --- a/templates/cli/lib/commands/push.js.twig +++ b/templates/cli/lib/commands/push.js.twig @@ -1101,46 +1101,52 @@ const pushMessagingTopic = async ({ all, yes } = {}) => { } const push = new Command("push") + .alias("deploy") .description(commandDescriptions['push']) - .option(`--all`, `Flag to push all resources`) - .option(`--yes`, `Flag to confirm all warnings`) + .option(`-a, --all`, `Flag to push all resources`) + .option(`-y, --yes`, `Flag to confirm all warnings`) .action(actionRunner(pushResources)); push .command("function") + .alias("functions") .description("Push functions in the current directory.") - .option(`--functionId `, `Function ID`) - .option(`--all`, `Flag to push all functions`) - .option(`--yes`, `Flag to confirm all warnings`) - .option(`--async`, `Don't wait for functions deployments status`) + .option(`-f, --functionId `, `Function ID`) + .option(`-a, --all`, `Flag to push all functions`) + .option(`-y, --yes`, `Flag to confirm all warnings`) + .option(`-A, --async`, `Don't wait for functions deployments status`) .action(actionRunner(pushFunction)); push .command("collection") + .alias("collections") .description("Push collections in the current project.") - .option(`--all`, `Flag to push all collections`) - .option(`--yes`, `Flag to confirm all warnings`) + .option(`-a, --all`, `Flag to push all collections`) + .option(`-a, --yes`, `Flag to confirm all warnings`) .action(actionRunner(pushCollection)); push .command("bucket") + .alias("buckets") .description("Push buckets in the current project.") - .option(`--all`, `Flag to push all buckets`) - .option(`--yes`, `Flag to confirm all warnings`) + .option(`-a, --all`, `Flag to push all buckets`) + .option(`-y, --yes`, `Flag to confirm all warnings`) .action(actionRunner(pushBucket)); push .command("team") + .alias("teams") .description("Push teams in the current project.") - .option(`--all`, `Flag to push all teams`) - .option(`--yes`, `Flag to confirm all warnings`) + .option(`-a, --all`, `Flag to push all teams`) + .option(`-y, --yes`, `Flag to confirm all warnings`) .action(actionRunner(pushTeam)); push .command("topic") + .alias("topics") .description("Push messaging topics in the current project.") - .option(`--all`, `Flag to deploy all topics`) - .option(`--yes`, `Flag to confirm all warnings`) + .option(`-a, --all`, `Flag to deploy all topics`) + .option(`-y, --yes`, `Flag to confirm all warnings`) .action(actionRunner(pushMessagingTopic)); module.exports = { From 2ac1569ac703882aa33bb7406b2a627c80458fd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 14 Jun 2024 14:26:51 +0000 Subject: [PATCH 2/4] PR review changes --- templates/cli/lib/commands/pull.js.twig | 8 ++++---- templates/cli/lib/commands/push.js.twig | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/templates/cli/lib/commands/pull.js.twig b/templates/cli/lib/commands/pull.js.twig index 22bdc3ae9..1bc6214e6 100644 --- a/templates/cli/lib/commands/pull.js.twig +++ b/templates/cli/lib/commands/pull.js.twig @@ -264,7 +264,7 @@ pull pull .command("collection") - .command("collections") + .alias("collections") .description("Pulling your {{ spec.title|caseUcfirst }} collections") .option(`-d, --databaseId `, `Database ID`) .option(`-a, --all`, `Flag to pullialize all databases`) @@ -272,19 +272,19 @@ pull pull .command("bucket") - .command("buckets") + .alias("buckets") .description("Pulling your Appwrite buckets") .action(actionRunner(pullBucket)) pull .command("team") - .command("teams") + .alias("teams") .description("Pulling your Appwrite teams") .action(actionRunner(pullTeam)) pull .command("topic") - .command("topics") + .alias("topics") .description("Initialise your Appwrite messaging topics") .action(actionRunner(pullMessagingTopic)) diff --git a/templates/cli/lib/commands/push.js.twig b/templates/cli/lib/commands/push.js.twig index 4eb801e12..b94cea789 100644 --- a/templates/cli/lib/commands/push.js.twig +++ b/templates/cli/lib/commands/push.js.twig @@ -1101,7 +1101,6 @@ const pushMessagingTopic = async ({ all, yes } = {}) => { } const push = new Command("push") - .alias("deploy") .description(commandDescriptions['push']) .option(`-a, --all`, `Flag to push all resources`) .option(`-y, --yes`, `Flag to confirm all warnings`) From 90e4b9d332dfba51cfda01a5a41600252f1925d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 14 Jun 2024 14:29:55 +0000 Subject: [PATCH 3/4] Remove leftovers --- templates/cli/lib/commands/push.js.twig | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/templates/cli/lib/commands/push.js.twig b/templates/cli/lib/commands/push.js.twig index 416d54227..294c2b5b4 100644 --- a/templates/cli/lib/commands/push.js.twig +++ b/templates/cli/lib/commands/push.js.twig @@ -1335,8 +1335,6 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) => const push = new Command("push") .alias('deploy') .description(commandDescriptions['push']) - .option(`-a, --all`, `Flag to push all resources`) - .option(`-y, --yes`, `Flag to confirm all warnings`) .action(actionRunner(pushResources)); push @@ -1344,8 +1342,6 @@ push .alias("functions") .description("Push functions in the current directory.") .option(`-f, --functionId `, `Function ID`) - .option(`-a, --all`, `Flag to push all functions`) - .option(`-y, --yes`, `Flag to confirm all warnings`) .option(`-A, --async`, `Don't wait for functions deployments status`) .action(actionRunner(pushFunction)); @@ -1353,32 +1349,24 @@ push .command("collection") .alias("collections") .description("Push collections in the current project.") - .option(`-a, --all`, `Flag to push all collections`) - .option(`-a, --yes`, `Flag to confirm all warnings`) .action(actionRunner(pushCollection)); push .command("bucket") .alias("buckets") .description("Push buckets in the current project.") - .option(`-a, --all`, `Flag to push all buckets`) - .option(`-y, --yes`, `Flag to confirm all warnings`) .action(actionRunner(pushBucket)); push .command("team") .alias("teams") .description("Push teams in the current project.") - .option(`-a, --all`, `Flag to push all teams`) - .option(`-y, --yes`, `Flag to confirm all warnings`) .action(actionRunner(pushTeam)); push .command("topic") .alias("topics") .description("Push messaging topics in the current project.") - .option(`-a, --all`, `Flag to deploy all topics`) - .option(`-y, --yes`, `Flag to confirm all warnings`) .action(actionRunner(pushMessagingTopic)); module.exports = { From c1e497d7c2190493beb90d7c65d89a0d89e1129e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 14 Jun 2024 14:34:56 +0000 Subject: [PATCH 4/4] Fix after merge --- templates/cli/lib/commands/push.js.twig | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/templates/cli/lib/commands/push.js.twig b/templates/cli/lib/commands/push.js.twig index 294c2b5b4..a2672743f 100644 --- a/templates/cli/lib/commands/push.js.twig +++ b/templates/cli/lib/commands/push.js.twig @@ -1337,6 +1337,16 @@ const push = new Command("push") .description(commandDescriptions['push']) .action(actionRunner(pushResources)); +push + .command("all") + .description("Push all resource.") + .action(actionRunner(pushResources)); + +push + .command("project") + .description("Push project name, services and auth settings") + .action(actionRunner(pushProject)); + push .command("function") .alias("functions")