Skip to content

Commit

Permalink
Merge branch 'v6.29.3' into 'master'
Browse files Browse the repository at this point in the history
added configFile option to all commands

See merge request transip/restapi-cli-client!175
  • Loading branch information
Mohammad Niknab committed Feb 9, 2023
2 parents e02924c + 3244b82 commit 960a6bd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
CHANGELOG
=========
6.29.3
-----
* Added configFile option to all commands.

6.29.2
-----
* Fixed getEntries in certain conditions on mailLists.
Expand Down
12 changes: 12 additions & 0 deletions src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,22 @@ public function __construct(string $name = null)
Field::FORMAT__DESC,
'json'
);

// adds --configFile option to all commands
$this->addOption(
Field::CONFIG_FILE,
null,
InputOption::VALUE_OPTIONAL,
Field::CONFIG_FILE__DESC,
Settings::getDefaultConfigFilePath()
);
}

protected function initialize(InputInterface $input, OutputInterface $output): void
{
$configFile = $input->getOption(Field::CONFIG_FILE);
Settings::setConfigFilePath($configFile);

if (!($this instanceof Setup)) {
$isDemoMode = $input->getOption('demo');

Expand Down
3 changes: 3 additions & 0 deletions src/Command/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,7 @@ class Field

public const INCLUDE = 'include';
public const INCLUDE__DESC = 'Data to include in the response';

public const CONFIG_FILE = 'configFile';
public const CONFIG_FILE__DESC = 'The config file path';
}
26 changes: 20 additions & 6 deletions src/Settings/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

class Settings
{
private const CONFIG_DIR_NAME = '.config/transip-api';
private const CONFIG_FILE_NAME = 'cli-config.json';
private const DEFAULT_CONFIG_DIR_NAME = '.config/transip-api';
private const DEFAULT_CONFIG_FILE_NAME = 'cli-config.json';

public const TRANSIP_API_ENDPOINT = 'https://api.transip.nl/v6';

public const TRANSIP_CLI_VERSION = '6.29.2';
public const TRANSIP_CLI_VERSION = '6.29.3';

/**
* @var string
Expand Down Expand Up @@ -49,6 +49,11 @@ class Settings
*/
private static $instance;

/**
* @var string
*/
private static $configFilePath;

private function initialise(): void
{
$configFilePath = self::getConfigFilePath();
Expand Down Expand Up @@ -122,13 +127,12 @@ public function getShowConfigFilePermissionWarning(): string

public static function getConfigDir(): string
{
$homeDirectory = Path::getHomeDirectory();
return Path::join($homeDirectory, self::CONFIG_DIR_NAME);
return Path::getDirectory(self::getConfigFilePath());
}

public static function getConfigFilePath(): string
{
return Path::join(self::getConfigDir(), self::CONFIG_FILE_NAME);
return self::$configFilePath;
}

public function ensureConfigFileIsReadOnly(FormatterHelper $formatter, OutputInterface $output): void
Expand Down Expand Up @@ -163,4 +167,14 @@ public function ensureConfigFileIsReadOnly(FormatterHelper $formatter, OutputInt
$output->writeln($warning);
$output->writeln('');
}

public static function setConfigFilePath(string $configFile): void
{
self::$configFilePath = $configFile;
}

public static function getDefaultConfigFilePath(): string
{
return Path::join(Path::getHomeDirectory(), self::DEFAULT_CONFIG_DIR_NAME, self::DEFAULT_CONFIG_FILE_NAME);
}
}

0 comments on commit 960a6bd

Please sign in to comment.