Tim 90751f5bec Implement stow config file and folder unwrapping
Move includes to their own folder, config.php will otherwise be included
and cleans up nicely
2025-05-19 00:26:52 +02:00

39 lines
1.1 KiB
PHP
Executable File

#!/usr/bin/env php
<?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', 'w' => 'Unwrap folders'],
['stow-directory' => 'The directory to stow']
);
$parsed = $argvParser->parseArgv($argv);
if ($parsed === false) {
line('Usage: ' . __FILE__ . ' ' . $argvParser->getOptionsHelp());
exit(1);
}
$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);
$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, $unwrap);
$stow->run($stowPath, $targetPath);
exit(0);