37 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) {
lexit('Usage: ' . __FILE__ . ' ' . $argvParser->getOptionsHelp(), 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)) {
lexit("Directory '$stowName' does not exist", 1);
}
$stow = new stow($action, $backup, $force, $unwrap);
$stow->run($stowPath, $targetPath);
lexit('Done successfully');