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

Fix: Improve CLI aliases #858

Merged
merged 5 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -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;
})
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,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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -129,12 +128,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
9 changes: 7 additions & 2 deletions templates/cli/lib/commands/pull.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Meldiron marked this conversation as resolved.
Show resolved Hide resolved
.description("Pulling your {{ spec.title|caseUcfirst }} collections")
.option(`--databaseId <databaseId>`, `Database ID`)
.option(`--all`, `Flag to pullialize all databases`)
.option(`-d, --databaseId <databaseId>`, `Database ID`)
.option(`-a, --all`, `Flag to pullialize all databases`)
.action(actionRunner(pullCollection))

pull
.command("bucket")
.command("buckets")
Meldiron marked this conversation as resolved.
Show resolved Hide resolved
.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")
Meldiron marked this conversation as resolved.
Show resolved Hide resolved
.description("Initialise your Appwrite messaging topics")
.action(actionRunner(pullMessagingTopic))

Expand Down
34 changes: 20 additions & 14 deletions templates/cli/lib/commands/push.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -1101,46 +1101,52 @@ const pushMessagingTopic = async ({ all, yes } = {}) => {
}

const push = new Command("push")
.alias("deploy")
Meldiron marked this conversation as resolved.
Show resolved Hide resolved
.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 <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 <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 = {
Expand Down