Skip to content

Commit

Permalink
Merge branch 'main' into list-sites-command
Browse files Browse the repository at this point in the history
  • Loading branch information
A5hleyRich committed Nov 16, 2021
2 parents 7cb8bee + 23be4d8 commit 22c920e
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.idea
/.vscode
/.vagrant
/tests/.spinupwp
.phpunit.result.cache
.php-cs-fixer.cache
composer.lock
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,29 @@ To get started, require the package globally via [Composer](https://getcomposer.
```bash
composer global require deliciousbrains/spinupwp-cli
```
In addition, you should make sure the `~/.composer/vendor/bin` directory is in your system's "PATH".

## Usage
Installing the SpinupWP CLI provides access to the `spinupwp` command.
```bash
spinupwp <command>
````
You will need to generate an API token to interact with the SpinupWP CLI. After you have generated an API token, you should configure your default profile:
```bash
spinupwp configure
````
You can configure multiple profiles, which is useful if you're a member of multiple teams:
```bash
spinupwp configure --profile=hellfishmedia
```
To run a command using a specific profile, pass the profile option:
```bash
spinupwp servers:list --profile=hellfishmedia
```
If no profile is supplied, your default profile will be used (if configured).
## Upgrade
To update the SpinupWP CLI to the latest version, run:
```bash
composer global update
```
23 changes: 8 additions & 15 deletions app/Helpers/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

class Configuration
{
/**
* @var array
*/
protected $config;
protected string $path;

public function __construct()
protected array $config;

public function __construct(string $path)
{
$this->path = $path;
$this->config = $this->readConfig();
}

Expand Down Expand Up @@ -74,17 +74,10 @@ protected function readConfig(): array

public function configFilePath(): string
{
return $this->getConfigPath() . 'config.json';
}

protected function getConfigPath(): string
{
$userHome = config('app.config_path') . '/.spinupwp/';

if (!file_exists($userHome)) {
mkdir($userHome);
if (!file_exists($this->path)) {
mkdir($this->path);
}

return $userHome;
return $this->path . 'config.json';
}
}
10 changes: 9 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public function register()
{
$this->app->singleton(SpinupWp::class, fn ($app) => new SpinupWp());

$this->app->singleton(Configuration::class, fn ($app) => new Configuration());
$this->app->singleton(Configuration::class, function () {
$path = isset($_ENV['APP_ENV']) && $_ENV['APP_ENV'] === 'testing'
? base_path('tests')
: ($_SERVER['HOME'] ?? $_SERVER['USERPROFILE']);

$path .= '/.spinupwp/';

return new Configuration($path);
});
}
}
Binary file modified builds/spinupwp
Binary file not shown.
4 changes: 1 addition & 3 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
|
*/

'version' => app('git.version'),
'version' => '0.1.1',

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -62,6 +62,4 @@
'table',
],

'config_path' => $_SERVER['HOME'] ?? $_SERVER['USERPROFILE'],

];
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@
<directory suffix=".php">./app</directory>
</include>
</coverage>
<php>
<env name="APP_ENV" value="testing"/>
</php>
</phpunit>
3 changes: 1 addition & 2 deletions tests/Feature/Commands/ConfigureCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use App\Helpers\Configuration;

beforeEach(function () {
setConfigPath();
deleteTestConfigFile();
});

Expand All @@ -16,5 +15,5 @@
->expectsQuestion('Default output format (json/table)', 'json')
->expectsOutput('SpinupWP CLI configured successfully');

expect((new Configuration)->get('api_token'))->toEqual('my-spinupwp-api-token');
expect((resolve(Configuration::class))->get('api_token'))->toEqual('my-spinupwp-api-token');
});
12 changes: 2 additions & 10 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,9 @@
|
*/

function setConfigPath()
{
$mockPath = storage_path();
Config::set('app.config_path', $mockPath);
}

function setTestConfigFile()
{
setConfigPath();
$config = new Configuration();
$config = resolve(Configuration::class);
file_put_contents($config->configFilePath(), json_encode([
'default' => [
'api_token' => 'myapikey123',
Expand All @@ -71,8 +64,7 @@ function setTestConfigFile()

function deleteTestConfigFile($test = '')
{
setConfigPath();
$configFile = (new Configuration)->configFilePath();
$configFile = (resolve(Configuration::class))->configFilePath();
if (!file_exists($configFile)) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Helpers/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
});

test('isConfigured method', function () {
$config = new Configuration();
$config = resolve(Configuration::class);
$isConfigured = $config->isConfigured();
expect($isConfigured)->toBeFalse();
setTestConfigFile();
Expand All @@ -17,12 +17,12 @@

test('get method', function () {
setTestConfigFile();
$config = new Configuration();
$config = resolve(Configuration::class);
expect($config->get('api_token'))->toEqual('myapikey123');
});

test('set method', function () {
$config = new Configuration();
$config = resolve(Configuration::class);

// first time
$config->set('api_token', 'mynewapitoken');
Expand Down

0 comments on commit 22c920e

Please sign in to comment.