Skip to content

Fix: Improve CLI aliases #858

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

Merged
merged 5 commits into from
Jun 14, 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
4 changes: 2 additions & 2 deletions templates/cli/index.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,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")
.hook('preAction', migrate)
.option("-f,--force", "Flag to confirm all warnings")
.option("-a,--all", "Flag to push all resources")
Expand Down
21 changes: 10 additions & 11 deletions templates/cli/lib/commands/generic.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { Command } = require("commander");
const Client = require("../client");
const { sdkForConsole } = require("../sdks");
const { globalConfig, localConfig } = require("../config");
const { actionRunner, success, parseBool, commandDescriptions, error, parse, log, drawTable } = require("../parser");
const { actionRunner, success, parseBool, commandDescriptions, error, parse, log, drawTable, cliConfig } = require("../parser");
const ID = require("../id");
{% if sdk.test != "true" %}
const { questionsLogin, questionsLogout, questionsListFactors, questionsMfaChallenge } = require("../questions");
Expand Down Expand Up @@ -90,8 +90,7 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => {

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;
Expand Down Expand Up @@ -120,9 +119,9 @@ const whoami = new Command("whoami")
'Endpoint': globalConfig.getEndpoint()
}
];
if (json) {
console.log(data);

if(cliConfig.json) {
console.log(data);
return;
}

Expand Down Expand Up @@ -204,12 +203,12 @@ const client = new Command("client")
.configureHelp({
helpWidth: process.stdout.columns || 80
})
.option("--selfSigned <value>", "Configure the CLI to use a self-signed certificate ( true or false )", parseBool)
.option("--endpoint <endpoint>", "Set your Appwrite server endpoint")
.option("--projectId <projectId>", "Set your Appwrite project ID")
.option("--key <key>", "Set your Appwrite server's API key")
.option("--debug", "Print CLI debug information")
.option("--reset", "Reset the CLI configuration")
.option("-ss, --selfSigned <value>", "Configure the CLI to use a self-signed certificate ( true or false )", parseBool)
.option("-e, --endpoint <endpoint>", "Set your Appwrite server endpoint")
.option("-p, --projectId <projectId>", "Set your Appwrite project ID")
.option("-k, --key <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()
Expand Down
27 changes: 16 additions & 11 deletions templates/cli/lib/commands/pull.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -199,28 +199,33 @@ pull
.action(actionRunner(pullProject));

pull
.command("functions")
.description(`Pull your {{ spec.title|caseUcfirst }} functions`)
.action(actionRunner(pullFunctions));
.command("function")
.alias("functions")
.description("Pulling your {{ spec.title|caseUcfirst }} cloud function")
.action(actionRunner(pullFunction))

pull
.command("collections")
.description("Pull your {{ spec.title|caseUcfirst }} collections")
.command("collection")
.alias("collections")
.description("Pulling your {{ spec.title|caseUcfirst }} collections")
.action(actionRunner(pullCollection))

pull
.command("buckets")
.description("Pull your {{ spec.title|caseUcfirst }} buckets")
.command("bucket")
.alias("buckets")
.description("Pulling your Appwrite buckets")
.action(actionRunner(pullBucket))

pull
.command("teams")
.description("Pull your {{ spec.title|caseUcfirst }} teams")
.command("team")
.alias("teams")
.description("Pulling your Appwrite teams")
.action(actionRunner(pullTeam))

pull
.command("topics")
.description("Pull your {{ spec.title|caseUcfirst }} messaging topics")
.command("topic")
.alias("topics")
.description("Initialise your Appwrite messaging topics")
.action(actionRunner(pullMessagingTopic))

module.exports = {
Expand Down
20 changes: 13 additions & 7 deletions templates/cli/lib/commands/push.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,7 @@ const pushMessagingTopic = async ({ returnOnZero } = { returnOnZero: false }) =>
const push = new Command("push")
.alias('deploy')
.description(commandDescriptions['push'])
.action(actionRunner(pushResources));

push
.command("all")
Expand All @@ -1347,29 +1348,34 @@ push
.action(actionRunner(pushProject));

push
.command("functions")
.command("function")
.alias("functions")
.description("Push functions in the current directory.")
.option(`--functionId <functionId>`, `Function ID`)
.option(`--async`, `Don't wait for functions deployments status`)
.option(`-f, --functionId <functionId>`, `Function ID`)
.option(`-A, --async`, `Don't wait for functions deployments status`)
.action(actionRunner(pushFunction));

push
.command("collections")
.command("collection")
.alias("collections")
.description("Push collections in the current project.")
.action(actionRunner(pushCollection));

push
.command("buckets")
.command("bucket")
.alias("buckets")
.description("Push buckets in the current project.")
.action(actionRunner(pushBucket));

push
.command("teams")
.command("team")
.alias("teams")
.description("Push teams in the current project.")
.action(actionRunner(pushTeam));

push
.command("topics")
.command("topic")
.alias("topics")
.description("Push messaging topics in the current project.")
.action(actionRunner(pushMessagingTopic));

Expand Down
Loading