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
3 changes: 2 additions & 1 deletion templates/cli/app/services/client.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ $cli


{% for header in spec.global.headers %}
{%if header.key != 'JWT' %}
$cli
->task('set{{ header.key }}')
->param('{{ header.key | lower }}', '', new Wildcard(), '{{ header.description }}', false)
Expand All @@ -75,7 +76,7 @@ $cli
Console::success('✅ Preferences saved successfully');
}
});

{% endif %}
{% endfor %}

$cli
Expand Down
16 changes: 10 additions & 6 deletions templates/cli/app/services/init.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const PREFERENCE_ENDPOINT = "endpoint";
$preferences = [
PREFERENCE_ENDPOINT => '',
{% for header in spec.global.headers %}
{% if header.key != 'Mode' %}
{% if header.key != 'Mode' and header.key != 'JWT' %}
'{{header.name}}' => '',
{% endif %}
{% endfor %}
Expand All @@ -40,7 +40,7 @@ function loadEnvVariables(): bool
setPreference(PREFERENCE_ENDPOINT, $endpoint);

{% for header in spec.global.headers %}
{% if header.key != 'Mode' %}
{% if header.key != 'Mode' and header.key != 'JWT' %}
${{ header.key | caseCamel }} = getenv('{{ header.name}}') ?: '';
setPreference('{{ header.name }}', ${{ header.key | caseCamel }});

Expand Down Expand Up @@ -68,7 +68,7 @@ function loadEnvVariables(): bool
function isPreferenceLoaded() : bool {
if(empty(getPreference(PREFERENCE_ENDPOINT))) return false;
{% for header in spec.global.headers %}
{% if header.key != 'Mode' %}
{% if header.key != 'Mode' and header.key != 'JWT' %}
if(empty(getPreference('{{header.name}}'))) return false;
{% endif %}
{% endfor %}
Expand Down Expand Up @@ -167,20 +167,24 @@ $cli->

$cli
->task('init')
->label('description', "The init command is used to initialise your CLI\n")
->label('description', "The init command is used to initialize your CLI\n")
->param('endpoint', '', new Wildcard(), 'Your {{ spec.title | caseUcfirst }} endpoint', true)
{% for header in spec.global.headers %}
{% if header.key != 'JWT' %}
->param('{{ header.key | lower }}', '', new Wildcard(), '{{ header.description }}', true)
{% endif %}
{% endfor %}
->action(function( $endpoint, {% for header in spec.global.headers %} ${{ header.key | lower }}{% if not loop.last %},{% endif %}{% endfor %} ) {
->action(function( $endpoint,{% for header in spec.global.headers %}{% if header.key != 'JWT' %} ${{ header.key | lower }}{% if not loop.last %},{% endif %}{% endif %}{% endfor %} ) {
/*
* Check if enviroment variables exist
* Check if environment variables exist
* Else prompt the user
*/

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

if (!loadEnvVariables()) {
Expand Down
3 changes: 1 addition & 2 deletions templates/cli/install.sh.twig
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ install() {
fi
printSuccess

echo '
#!/bin/bash
echo '#!/bin/bash

allowList=(help init client{% for service in spec.services %} {{ service.name }}{% endfor %})

Expand Down
12 changes: 5 additions & 7 deletions templates/cli/src/Client.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Client
self::PREFERENCE_ENDPOINT => '',
self::PREFERENCE_SELF_SIGNED => '',
{% for header in spec.global.headers %}
{% if header.key != 'Mode' %}
{% if header.key != 'Mode' and header.key != 'JWT' %}
'{{header.name}}' => '',
{% endif %}
{% endfor %}
Expand All @@ -61,7 +61,7 @@ class Client
}
$this
{% for header in spec.global.headers %}
{% if header.key != 'Mode' %}
{% if header.key != 'Mode' and header.key != 'JWT' %}
->set{{header.key | caseUcfirst}}($this->preferences['{{header.name}}'])
{% endif %}
{% endfor %}
Expand Down Expand Up @@ -140,15 +140,15 @@ class Client
private function isPreferenceLoaded() : bool {
if(empty($this->getPreference(self::PREFERENCE_ENDPOINT))) return false;
{% for header in spec.global.headers %}
{% if header.key != 'Mode' %}
{% if header.key != 'Mode' and header.key != 'JWT' %}
if(empty($this->getPreference('{{header.name}}'))) return false;
{% endif %}
{% endfor %}
return true;
}


{% for header in spec.global.headers %}
{% if header.key != 'JWT' %}
/**
* Set {{header.key | caseUcfirst}}
*
Expand All @@ -163,13 +163,11 @@ class Client
public function set{{header.key | caseUcfirst}}($value)
{
$this->addHeader('{{header.name}}', $value);

return $this;
}

{% endif %}
{% endfor %}


/**
* @param $key
* @param $value
Expand Down