Skip to content

feat(cli): Adding console for get & list methods #849

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 132 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
0357a8a
feat(cli): Adding console for get methods
byawitz May 21, 2024
d9fa0bb
feat(cli): Multiple accounts in CLI
byawitz May 21, 2024
2b5a168
feat(cli): Console flow add an open flag
byawitz May 22, 2024
6eeef88
Merge branch 'refs/heads/feat-cli-whoami-command' into feat-multiple-…
byawitz May 22, 2024
fd78fad
feat(cli): Hooking migration before any command
byawitz May 22, 2024
9387d95
feat(cli): Interactive multiple account changing
byawitz May 22, 2024
d250003
feat(cli): Adding json option to list accounts
byawitz May 22, 2024
144e043
feat(cli): Interactive multiple user logout
byawitz May 22, 2024
9a61aef
fix(cli): Changing migrate to regular function
byawitz May 22, 2024
0cf5edd
fix(cli): Login question
byawitz May 22, 2024
7c07523
fix(cli): Extracting migrate
byawitz May 22, 2024
58df0ee
fix(cli): Renaming the migrate function name
byawitz May 22, 2024
8c77004
fix(cli): Excluding migrate from tests
byawitz May 22, 2024
c1e5c41
fix(cli): Adding migrate to tests
byawitz May 22, 2024
ea494b7
fix(cli): Adapting the `client` command and bug when getting key.
byawitz May 22, 2024
094e8dd
feat(cli): Non destructive db, starting
byawitz May 22, 2024
4d14115
feat(cli): Adding report flag
byawitz May 23, 2024
25d7032
refactor(cli): Refactoring sudo and make it globally available
byawitz May 23, 2024
ed76075
refactor(cli): Parallel DB and Collections creation, attribute in ser…
byawitz May 23, 2024
f9a9c9a
feat(cli): Non destructive database and collection update
byawitz May 23, 2024
349161f
feat(cli): Adding more data to Github issue link
byawitz May 24, 2024
8c7b894
refactor(cli): Multiple account login refactoring
byawitz May 24, 2024
338c14d
feat(cli): Comparing non changeable attributes and showing all changes
byawitz May 24, 2024
e5573b6
fix(cli): removing cli version from `steps-to-reproduce`
byawitz May 24, 2024
8738085
Merge branch 'refs/heads/feat-report-error' into feat-cli-sudo
byawitz May 24, 2024
738a9f6
feat(cli): Give `paginate` the option to accept more queries
byawitz May 24, 2024
9096fae
refactor(cli): renaming to `--id` and adding verification
byawitz May 24, 2024
c82609d
refactor(cli): Moving --all logic into questions
byawitz May 24, 2024
cce2c3a
refactor(cli): Moving --force logic into questions
byawitz May 24, 2024
32452ff
refactor(cli): Review fixing
byawitz May 28, 2024
ffdc1cc
refactor(cli): Review fixing
byawitz May 28, 2024
60b73a2
refactor(cli): Review fixing
byawitz May 28, 2024
1f562c5
Merge branch 'refs/heads/feat-cli-g2' into feat-non-destructive-db-ac…
byawitz May 28, 2024
ea9f2fb
refactor(cli): Review fixing
byawitz May 28, 2024
bb80ece
refactor(cli): Review fixing
byawitz May 28, 2024
e97c08e
Merge branch 'refs/heads/feat-cli-g2' into feat-non-destructive-db-ac…
byawitz May 28, 2024
a34f5de
feat(cli): Added option for twig functions and
byawitz May 28, 2024
d66b6ae
feat(cli): Added twig `methodHaveConsolePreview` function
byawitz May 28, 2024
0081b07
feat(cli): Expanding console flow to list and various get commands
byawitz May 28, 2024
0b7a25a
Merge branch 'feat-cli-g2' into feat-multiple-accounts-and-instances
Meldiron May 29, 2024
ceda8a6
Merge branch 'feat-cli-g2' into feat-report-error
Meldiron May 29, 2024
69c5d66
Merge branch 'feat-cli-g2' into feat-cli-sudo
Meldiron May 29, 2024
34dac24
Merge branch 'feat-cli-g2' into feat-non-destructive-db-actions
Meldiron May 29, 2024
43e6fc9
Merge branch 'feat-create-resources' into feat-console-flow
Meldiron May 29, 2024
8b4df13
fix(cli): Leading slash for project endpoints
byawitz May 29, 2024
9e2e51b
Merge branch 'refs/heads/feat-cli-g2' into feat-non-destructive-db-ac…
byawitz May 29, 2024
11de1cc
Merge branch 'refs/heads/feat-cli-g2' into feat-report-error
byawitz May 29, 2024
5a0111e
Merge branch 'refs/heads/feat-cli-g2' into feat-cli-sudo
byawitz May 29, 2024
6ce7b0a
Merge remote-tracking branch 'origin/feat-cli-sudo' into feat-cli-sudo
byawitz May 29, 2024
ff9bfb4
Merge branch 'refs/heads/feat-report-error' into feat-cli-sudo
byawitz May 29, 2024
ab9e297
Merge branch 'refs/heads/feat-cli-g2' into feat-multiple-accounts-and…
byawitz May 29, 2024
7051e44
Merge branch 'refs/heads/feat-create-resources' into feat-console-flow
byawitz May 29, 2024
8e639d1
fix(cli): Pull and update project available services, auth security s…
byawitz May 29, 2024
224c3fd
chore(cli): Updating project commands descriptions
byawitz May 29, 2024
02be0f0
feat(cli): Updating push to include the project
byawitz May 29, 2024
9ac316d
feat(cli): Updating push to include the project
byawitz May 29, 2024
e089e9c
feat(cli): Pull all resources
byawitz May 29, 2024
f7e92bc
Merge remote-tracking branch 'refs/remotes/origin/feat-console-flow' …
byawitz May 29, 2024
3d36787
Merge branch 'refs/heads/feat-pull-project-settings' into feat-push-p…
byawitz May 29, 2024
94b8dd4
Merge branch 'refs/heads/feat-pull-project-settings' into feat-report…
byawitz May 29, 2024
8eac05a
Merge branch 'refs/heads/feat-report-error' into feat-cli-sudo
byawitz May 29, 2024
d0cc1c2
feat(cli): Adapting pull to cliConfig
byawitz May 29, 2024
b7f6f56
Merge branch 'refs/heads/feat-cli-sudo' into feat-non-destructive-db-…
byawitz May 29, 2024
0c1bc45
chore(cli): Adapting pull request
byawitz May 29, 2024
cf2ce7d
Merge branch 'refs/heads/feat-non-destructive-db-actions' into feat-m…
byawitz May 29, 2024
705647d
chore(cli): Adding headless login
byawitz May 29, 2024
2962472
Merge branch 'refs/heads/feat-multiple-accounts-and-instances' into f…
byawitz May 29, 2024
87e88c3
chore(cli): Adapting pull request
byawitz May 29, 2024
063ac9e
refactor(cli): Texts and removing unnecessary options
byawitz May 30, 2024
cc0f854
refactor(cli): Texts and Adding stacktrace
byawitz May 30, 2024
5cd9f93
refactor(cli): removing implemented feature
byawitz May 30, 2024
db6ebfe
refactor(cli): refactoring to one function
byawitz May 30, 2024
0135a4f
refactor(cli): removing unneeded async
byawitz May 30, 2024
dcea1df
feat(cli): Skipping unavailable push resources
byawitz May 30, 2024
f78b368
Merge pull request #865 from appwrite/feat-push-pull-all
christyjacob4 May 30, 2024
2e8f560
feat(cli): Showing deployed function URL
byawitz May 30, 2024
b35b4bb
Merge pull request #866 from appwrite/feat-function-deployment-url
christyjacob4 May 30, 2024
a2d49e7
Update templates/cli/lib/parser.js.twig
christyjacob4 May 31, 2024
acdb9fc
Merge pull request #854 from appwrite/feat-non-destructive-db-actions
christyjacob4 May 31, 2024
a6f08c8
Apply suggestions from code review
christyjacob4 May 31, 2024
ebc1464
Merge pull request #864 from appwrite/feat-pull-project-settings
christyjacob4 May 31, 2024
68b026b
refactor(cli): Internal client instead of a generic fetch
byawitz May 31, 2024
3d2646a
Merge remote-tracking branch 'origin/feat-report-error' into feat-rep…
byawitz May 31, 2024
e4483bb
Merge branch 'refs/heads/feat-report-error' into feat-cli-sudo
byawitz May 31, 2024
7efedaf
refactor(cli): Adding pagination and reorder questions
byawitz May 31, 2024
930685c
feat(cli): headless project setup
byawitz May 31, 2024
5bba9cd
feat(cli): creating project if not exist
byawitz May 31, 2024
3621c3c
refactor(cli): reorder questions
byawitz May 31, 2024
64c364e
Merge branch 'refs/heads/feat-multiple-accounts-and-instances' into f…
byawitz May 31, 2024
d36a623
wip
byawitz Jun 3, 2024
406ef22
feat: Init project only ID
byawitz Jun 7, 2024
fb8e08a
feat: Init to local only & database creation
byawitz Jun 7, 2024
9717830
refactor: Improve command line to use `rawArgs`
byawitz Jun 7, 2024
2fd8f2b
feat: Added list search
byawitz Jun 7, 2024
0b817a7
feat: Added Register
byawitz Jun 7, 2024
acef728
feat: Tip for detailed error
byawitz Jun 7, 2024
990557a
feat: clearer function summary
byawitz Jun 7, 2024
33a5680
feat: Adding error when enable to open with default browser
byawitz Jun 7, 2024
471fc85
feat: Adding endpoint to whoami
byawitz Jun 7, 2024
f24abb6
feat: Adding self-hosted to project init
byawitz Jun 7, 2024
85167e9
feat: Removing unusable accounts
byawitz Jun 7, 2024
069f70c
feat: Ask when deleting, and explanations
byawitz Jun 7, 2024
6d8b6f2
refactor: Make sure `min` and `max` are numbers
byawitz Jun 7, 2024
f64000e
refactor: Asking unanswered questions
byawitz Jun 7, 2024
1251bff
Merge pull request #852 from appwrite/feat-report-error
christyjacob4 Jun 10, 2024
81ded63
Merge pull request #853 from appwrite/feat-cli-sudo
christyjacob4 Jun 10, 2024
c393058
Merge pull request #871 from appwrite/feat-search-list
christyjacob4 Jun 10, 2024
06b2a4b
Merge pull request #870 from appwrite/feat-improve-report
christyjacob4 Jun 10, 2024
034d08e
Update templates/cli/lib/questions.js.twig
christyjacob4 Jun 11, 2024
49488a6
Merge pull request #875 from appwrite/feat-collection-push-improvements
christyjacob4 Jun 11, 2024
469594c
Merge branch 'refs/heads/feat-arg-project-init' into feat-general-imp…
byawitz Jun 11, 2024
8420eb0
fix: reviews
byawitz Jun 11, 2024
cc78c01
Merge remote-tracking branch 'origin/feat-general-improvements' into …
byawitz Jun 11, 2024
4ae99d5
fix: reviews
byawitz Jun 11, 2024
b5ca8bf
fix: reviews
byawitz Jun 11, 2024
aabddae
fix: texts
byawitz Jun 11, 2024
dea75b4
refactor: Removing login from init
byawitz Jun 11, 2024
5fe0bd2
refactor: Removing self-hosted from login
byawitz Jun 11, 2024
2db03b5
Merge pull request #874 from appwrite/feat-general-improvements
christyjacob4 Jun 11, 2024
9116fc0
feat: Fetching function templates from API
byawitz Jun 11, 2024
7ed643e
Update templates/cli/lib/commands/init.js.twig
christyjacob4 Jun 11, 2024
57984ba
Merge pull request #877 from appwrite/feat-function-init-improvments
christyjacob4 Jun 11, 2024
0cf2882
refactor: Removing `--open` option
byawitz Jun 11, 2024
fcb2ddc
Merge pull request #868 from appwrite/feat-arg-project-init
christyjacob4 Jun 11, 2024
3b04fe8
Merge branch 'refs/heads/feat-console-flow' into feat-multiple-accoun…
byawitz Jun 11, 2024
3e054b0
Merge remote-tracking branch 'origin/feat-multiple-accounts-and-insta…
byawitz Jun 11, 2024
309d764
refactor: reviews
byawitz Jun 11, 2024
4641f61
refactor: removing redundant exports and questions.
byawitz Jun 11, 2024
0860867
refactor: renaming login to sessions
byawitz Jun 11, 2024
11fe1ff
Merge pull request #851 from appwrite/feat-multiple-accounts-and-inst…
christyjacob4 Jun 11, 2024
0e8c129
refactor: reviews
byawitz Jun 11, 2024
169bb86
refactor: reviews
byawitz Jun 11, 2024
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
9 changes: 9 additions & 0 deletions src/SDK/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ public function getFilters(): array
return [];
}

/**
* Language specific functions.
* @return array
*/
public function getFunctions(): array
{
return [];
}

protected function toPascalCase(string $value): string
{
return \ucfirst($this->toCamelCase($value));
Expand Down
72 changes: 72 additions & 0 deletions src/SDK/Language/CLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,66 @@

namespace Appwrite\SDK\Language;

use Twig\TwigFunction;

class CLI extends Node
{
/**
* List of functions to ignore for console preview.
* @var array
*/
private $consoleIgnoreFunctions = [
'listidentities',
'listmfafactors',
'getprefs',
'getsession',
'getattribute',
'listdocumentlogs',
'getindex',
'listcollectionlogs',
'getcollectionusage',
'listlogs',
'listruntimes',
'getusage',
'getusage',
'listvariables',
'getvariable',
'listproviderlogs',
'listsubscriberlogs',
'getsubscriber',
'listtopiclogs',
'getemailtemplate',
'getsmstemplate',
'getfiledownload',
'getfilepreview',
'getfileview',
'getusage',
'listlogs',
'getprefs',
'getusage',
'listlogs',
'getmembership',
'listmemberships',
'listmfafactors',
'getmfarecoverycodes',
'getprefs',
'listtargets',
'gettarget',
];

/**
* List of SDK services to ignore for console preview.
* @var array
*/
private $consoleIgnoreServices = [
'health',
'migrations',
'locale',
'avatars',
'project',
'proxy',
'vcs'
];
/**
* @var array
*/
Expand Down Expand Up @@ -290,4 +348,18 @@ public function getParamExample(array $param): string

return $output;
}

/**
* Language specific filters.
* @return array
*/
public function getFunctions(): array
{
return [
/** Return true if the entered service->method is enabled for a console preview link */
new TwigFunction('hasConsolePreview', fn($method, $service) => preg_match('/^([Gg]et|[Ll]ist)/', $method)
&& !in_array(strtolower($method), $this->consoleIgnoreFunctions)
&& !in_array($service, $this->consoleIgnoreServices)),
];
}
}
7 changes: 7 additions & 0 deletions src/SDK/SDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ public function __construct(Language $language, Spec $spec)
'debug' => true
]);

/**
* Add language-specific functions
*/
foreach ($this->language->getFunctions() as $function) {
$this->twig->addFunction($function);
}

/**
* Add language specific filters
*/
Expand Down
11 changes: 11 additions & 0 deletions templates/cli/base/requests/api.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@
fs.writeFileSync(destination, response);
{%~ endif %}
if (parseOutput) {
{%~ if hasConsolePreview(method.name,service.name) %}
if(console) {
showConsoleLink('{{service.name}}', '{{ method.name }}'
{%- for parameter in method.parameters.path -%}{%- set param = (parameter.name | caseCamel | escapeKeyword) -%}{%- if param ends with 'Id' -%}, {{ param }} {%- endif -%}{%- endfor -%}
);
} else {
parse(response)
success()
}
{%~ else %}
parse(response)
success()
{%~ endif %}
}

return response;
23 changes: 23 additions & 0 deletions templates/cli/index.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ const chalk = require("chalk");
const { version } = require("./package.json");
const { commandDescriptions, cliConfig } = require("./lib/parser");
const { client } = require("./lib/commands/generic");
const inquirer = require("inquirer");
{% if sdk.test != "true" %}
const { login, logout, whoami } = require("./lib/commands/generic");
const { init } = require("./lib/commands/init");
const { pull } = require("./lib/commands/pull");
const { push } = require("./lib/commands/push");
{% else %}
const { migrate } = require("./lib/commands/generic");
{% endif %}
{% for service in spec.services %}
const { {{ service.name | caseLower }} } = require("./lib/commands/{{ service.name | caseLower }}");
{% endfor %}

inquirer.registerPrompt('search-list', require('inquirer-search-list'));

program
.description(commandDescriptions['main'])
.configureHelp({
Expand All @@ -29,12 +34,30 @@ program
.version(version, "-v, --version")
.option("--verbose", "Show complete error log")
.option("--json", "Output in JSON format")
.hook('preAction', migrate)
.option("-f,--force", "Flag to confirm all warnings")
.option("-a,--all", "Flag to push all resources")
.option("--id [id...]", "Flag to pass list of ids for a giving action")
.option("--report", "Enable reporting in case of CLI errors")
.on("option:json", () => {
cliConfig.json = true;
})
.on("option:verbose", () => {
cliConfig.verbose = true;
})
.on("option:report", function() {
cliConfig.report = true;
cliConfig.reportData = { data: this };
})
.on("option:force", () => {
cliConfig.force = true;
})
.on("option:all", () => {
cliConfig.all = true;
})
.on("option:id", function() {
cliConfig.ids = this.opts().id;
})
.showSuggestionAfterError()
{% if sdk.test != "true" %}
.addCommand(whoami)
Expand Down
11 changes: 10 additions & 1 deletion templates/cli/lib/client.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ const { fetch, FormData, Agent } = require("undici");
const JSONbig = require("json-bigint")({ storeAsString: false });
const {{spec.title | caseUcfirst}}Exception = require("./exception.js");
const { globalConfig } = require("./config.js");
const chalk = require("chalk");

class Client {
CHUNK_SIZE = 5*1024*1024; // 5MB

constructor() {
this.endpoint = '{{spec.endpoint}}';
this.headers = {
Expand Down Expand Up @@ -144,6 +145,14 @@ class Client {
} catch (error) {
throw new {{spec.title | caseUcfirst}}Exception(text, response.status, "", text);
}

if (path !== '/account' && json.code === 401 && json.type === 'user_more_factors_required') {
console.log(`${chalk.cyan.bold("ℹ Info")} ${chalk.cyan("Unusable account found, removing...")}`);

const current = globalConfig.getCurrentSession();
globalConfig.setCurrentSession('');
globalConfig.removeSession(current);
}
throw new {{spec.title | caseUcfirst}}Exception(json.message, json.code, json.type, json);
}

Expand Down
6 changes: 5 additions & 1 deletion templates/cli/lib/commands/command.js.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const tar = require("tar");
const ignore = require("ignore");
const { promisify } = require('util');
const libClient = require('../client.js');
const { getAllFiles } = require('../utils.js');
const { getAllFiles, showConsoleLink } = require('../utils.js');
const { Command } = require('commander');
const { sdkForProject, sdkForConsole } = require('../sdks')
const { parse, actionRunner, parseInteger, parseBool, commandDescriptions, success, log } = require('../parser')
Expand Down Expand Up @@ -70,6 +70,7 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({
{%- if 'multipart/form-data' in method.consumes -%},onProgress = () => {}{%- endif -%}

{%- if method.type == 'location' -%}, destination{%- endif -%}
{% if hasConsolePreview(method.name,service.name) %}, console{%- endif -%}
}) => {
{%~ endblock %}
let client = !sdk ? await {% if service.name == "projects" %}sdkForConsole(){% else %}sdkForProject(){% endif %} :
Expand All @@ -94,6 +95,9 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({
{% if method.type == 'location' %}
.requiredOption(`--destination <path>`, `output file path.`)
{% endif %}
{% if hasConsolePreview(method.name,service.name) %}
.option(`--console`, `Get the resource console url`)
{% endif %}
{% endautoescape %}
.action(actionRunner({{ service.name | caseLower }}{{ method.name | caseUcfirst }}))

Expand Down
Loading
Loading