Rewrite config to be seperate from path
This commit is contained in:
@ -6,7 +6,7 @@ require_once __DIR__ . '/../functions.php';
|
|||||||
require_once __DIR__ . '/../snips.php';
|
require_once __DIR__ . '/../snips.php';
|
||||||
require_once __DIR__ . '/../config.php';
|
require_once __DIR__ . '/../config.php';
|
||||||
|
|
||||||
$config = new config('snips');
|
$config = new homeConfig('snips');
|
||||||
$argvParser = new argvParser(['f' => 'File', 'a' => 'Api key', 's' => 'Shortcut'], ['c' => 'Command', 'id' => 'Snip id']);
|
$argvParser = new argvParser(['f' => 'File', 'a' => 'Api key', 's' => 'Shortcut'], ['c' => 'Command', 'id' => 'Snip id']);
|
||||||
$parsed = $argvParser->parseArgv($argv);
|
$parsed = $argvParser->parseArgv($argv);
|
||||||
if ($parsed === false) {
|
if ($parsed === false) {
|
||||||
|
@ -2,12 +2,27 @@
|
|||||||
|
|
||||||
require_once __DIR__ . '/functions.php';
|
require_once __DIR__ . '/functions.php';
|
||||||
|
|
||||||
readonly class config
|
readonly class homeConfig extends configReader
|
||||||
{
|
{
|
||||||
private const CONFIG_BASE_PATH = '.config';
|
private const CONFIG_BASE_PATH = '.config';
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private string $name
|
string $name
|
||||||
|
)
|
||||||
|
{
|
||||||
|
parent::__construct(path(
|
||||||
|
getenv('HOME'),
|
||||||
|
self::CONFIG_BASE_PATH,
|
||||||
|
$name
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly class configReader
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private string $path,
|
||||||
|
private string $fileName = 'config.php',
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$this->init();
|
$this->init();
|
||||||
@ -30,17 +45,13 @@ readonly class config
|
|||||||
{
|
{
|
||||||
return path(
|
return path(
|
||||||
$this->getConfigPath(),
|
$this->getConfigPath(),
|
||||||
'config.php'
|
$this->fileName
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getConfigPath(): string
|
private function getConfigPath(): string
|
||||||
{
|
{
|
||||||
return path(
|
return $this->path;
|
||||||
getenv('HOME'),
|
|
||||||
self::CONFIG_BASE_PATH,
|
|
||||||
$this->name
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function init(): void
|
private function init(): void
|
||||||
|
Reference in New Issue
Block a user