Skip to content
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
17 changes: 14 additions & 3 deletions templates/cli/app/services/init.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require_once './vendor/autoload.php';

use Exception;
use Utopia\CLI\CLI;
use Utopia\Validator\Mock;
use Utopia\CLI\Console;

const USER_PREFERENCES_FILE = __DIR__."/../../.preferences/.prefs.json";
Expand Down Expand Up @@ -143,10 +144,20 @@ $cli = new CLI();

$cli
->task('init')
->action(function() {
/* Load user defaults from a json file if available
Else Prompt the user to enter the details
->param('endpoint', '', new Mock(), 'Your Appwrite endpoint', true)
{% for header in spec.global.headers %}
->param('{{ header.key | lower }}', '', new Mock(), '{{ header.description }}', true)
{% endfor %}
->action(function( $endpoint, {% for header in spec.global.headers %} ${{ header.key | lower }}{% if not loop.last %},{% endif %}{% endfor %} ) {
/* Check if enviroment variables exist
* Else prompt the user
*/

putenv("endpoint=$endpoint");
{% for header in spec.global.headers %}
putenv("{{ header.name }}=${{ header.key | lower }}");
{% endfor %}

if (!loadEnvVariables()) {
promptUser();
}
Expand Down
2 changes: 1 addition & 1 deletion templates/cli/bin/init.twig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

php /usr/local/code/app/{{ spec.title | caseUcfirst}}/Services/init.php init
php /usr/local/code/app/{{ spec.title | caseUcfirst}}/Services/init.php init $@
14 changes: 14 additions & 0 deletions templates/cli/src/Client.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ class Client
return true;
}

/**
* Function to write user preferences to
* the JSON file
*
* @param string $filename
* @return int
*/
function savePreferences(string $filename = self::USER_PREFERENCES_FILE): int
{
$jsondata = json_encode($this->preferences, JSON_PRETTY_PRINT);
$result = file_put_contents($filename, $jsondata);
return $result;
}

/**
* Check if all the preferences have been successfully loaded.
*
Expand Down