Skip to content

Commit 0ac5298

Browse files
committed
feat: added non interactive mode to appwrite init
1 parent 332d875 commit 0ac5298

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

templates/cli/app/services/init.php.twig

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require_once './vendor/autoload.php';
66
77
use Exception;
88
use Utopia\CLI\CLI;
9+
use Utopia\Validator\Mock;
910
use Utopia\CLI\Console;
1011
1112
const USER_PREFERENCES_FILE = __DIR__."/../../.preferences/.prefs.json";
@@ -143,10 +144,20 @@ $cli = new CLI();
143144
144145
$cli
145146
->task('init')
146-
->action(function() {
147-
/* Load user defaults from a json file if available
148-
Else Prompt the user to enter the details
147+
->param('endpoint', '', new Mock(), 'Your Appwrite endpoint', true)
148+
{% for header in spec.global.headers %}
149+
->param('{{ header.key | lower }}', '', new Mock(), '{{ header.description }}', true)
150+
{% endfor %}
151+
->action(function( $endpoint, {% for header in spec.global.headers %} ${{ header.key | lower }}{% if not loop.last %},{% endif %}{% endfor %} ) {
152+
/* Check if enviroment variables exist
153+
* Else prompt the user
149154
*/
155+
156+
putenv("endpoint=$endpoint");
157+
{% for header in spec.global.headers %}
158+
putenv("{{ header.name }}=${{ header.key | lower }}");
159+
{% endfor %}
160+
150161
if (!loadEnvVariables()) {
151162
promptUser();
152163
}

templates/cli/bin/init.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22

3-
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/Services/init.php init
3+
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/Services/init.php init $@

0 commit comments

Comments
 (0)