Implement stow config file and folder unwrapping

Move includes to their own folder, config.php will otherwise be included
and cleans up nicely
This commit is contained in:
Tim
2025-05-19 00:26:52 +02:00
parent b7e5ee3b0e
commit 90751f5bec
8 changed files with 31 additions and 24 deletions

View File

@ -1,10 +1,10 @@
#!/usr/bin/env php
<?php
require_once __DIR__ . '/../argvParser.php';
require_once __DIR__ . '/../functions.php';
require_once __DIR__ . '/../snips.php';
require_once __DIR__ . '/../config.php';
require_once __DIR__ . '/../includes/argvParser.php';
require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../includes/snips.php';
require_once __DIR__ . '/../includes/config.php';
$config = new homeConfig('snips');
$argvParser = new argvParser(['f' => 'File', 'a' => 'Api key', 's' => 'Shortcut'], ['c' => 'Command', 'id' => 'Snip id']);
@ -17,13 +17,10 @@ if ($parsed === false) {
$command = $parsed->get('c');
$id = $parsed->get('id');
$file = $parsed->get('f');
$apiKey = $parsed->get('k');
$apiKey = $parsed->get('k', $config->get('apiKey'));
$getShortcut = $parsed->get('s');
$content = $parsed->getRest();
if (empty($apiKey)) {
$apiKey = $config->get('apiKey');
}
if (empty($apiKey)) {
line('Input api key:');
$apiKey = trim(fgets(STDIN));

View File

@ -1,12 +1,13 @@
#!/usr/bin/env php
<?php
require_once __DIR__ . '/../argvParser.php';
require_once __DIR__ . '/../functions.php';
require_once __DIR__ . '/../stow.php';
require_once __DIR__ . '/../includes/argvParser.php';
require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../includes/stow.php';
require_once __DIR__ . '/../includes/config.php';
$argvParser = new ArgvParser(
['u' => 'Unstow files', 'b' => 'Backup existing files', 'f' => 'Force overwrite'],
['u' => 'Unstow files', 'b' => 'Backup existing files', 'f' => 'Force overwrite', 'w' => 'Unwrap folders'],
['stow-directory' => 'The directory to stow']
);
$parsed = $argvParser->parseArgv($argv);
@ -19,17 +20,20 @@ $cwd = getcwd();
$action = $parsed->get('u') ? stow::ACTION_UNSTOW : stow::ACTION_STOW;
$backup = $parsed->get('b');
$force = $parsed->get('f');
$unwrap = $parsed->get('w');
$stowName = $parsed->get('stow-directory');
$stowPath = path($cwd, $stowName);
$targetPath = dirname($stowPath, 2);
$config = new config($stowPath);
$targetPath = $config->get('targetPath', dirname($stowPath, 2));
if (!is_dir($stowPath)) {
line("Directory '$stowName' does not exist");
exit(1);
}
$stow = new stow($action, $backup, $force);
$stow = new stow($action, $backup, $force, $unwrap);
$stow->run($stowPath, $targetPath);
exit(0);