Skip to content

Commit

Permalink
Improve CLI arguments and their evaluation.
Browse files Browse the repository at this point in the history
  • Loading branch information
nagmat84 committed Aug 15, 2021
1 parent 18680b7 commit 312a801
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions app/Console/Commands/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,20 @@ class Sync extends Command
/**
* The name and signature of the console command.
*
* The placeholder %s will be filled by the constructor with the default
* value from the user configuration.
*
* @var string
*/
protected $signature = 'lychee:sync {dir : directory to sync} {--album_id=0 : Album ID to import to} {--owner_id=0 : Owner ID of imported photos} {--resync_metadata : Re-sync metadata of existing files} {--delete_imported : Delete the original files} {--import_via_symlink= : Imports photos from via a symlink instead of copying the files} {--not_skip_duplicates : Don\'t Skip photos and albums if they already exist in the gallery}';
protected $signature =
'lychee:sync ' .
'{dir : directory to sync} ' .
'{--album_id=0 : Album ID to import to} ' .
'{--owner_id=0 : Owner ID of imported photos} ' .
'{--resync_metadata : Re-sync metadata of existing files} ' .
'{--delete_imported=%s : Delete the original files} ' .
'{--import_via_symlink=%s : Imports photos from via a symlink instead of copying the files} ' .
'{--skip_duplicates=%s : Don\'t Skip photos and albums if they already exist in the gallery}';

/**
* The console command description.
Expand All @@ -24,6 +35,18 @@ class Sync extends Command
*/
protected $description = 'Sync a directory to lychee';

public function __construct()
{
// Fill signature with default values from user configuration
$this->signature = sprintf(
$this->signature,
Configs::get_value('delete_imported', '0'),
Configs::get_value('import_via_symlink', '0'),
Configs::get_value('skip_duplicates', '0')
);
parent::__construct();
}

/**
* Execute the console command.
*
Expand All @@ -38,25 +61,17 @@ public function handle(Exec $exec)
// Enable CLI formatting of status
$exec->statusCLIFormatting = true;
$exec->memCheck = false;
$exec->delete_imported = $this->option('delete_imported');
if (!is_null($this->option('import_via_symlink'))) {
$exec->import_via_symlink = $this->option('import_via_symlink') === '1';
if ($exec->import_via_symlink && $exec->delete_imported) {
$this->error('--delete_imported and --import_via_symlink flags are conflicting.');
$exec->resync_metadata = $this->option('resync_metadata');
$exec->delete_imported = $this->option('delete_imported') === '1';
$exec->import_via_symlink = $this->option('import_via_symlink') === '1';
$exec->skip_duplicates = $this->option('skip_duplicates') === '1';

return 1;
}
} else {
$exec->import_via_symlink = (Configs::get_value('import_via_symlink', '0') === '1');
if ($exec->import_via_symlink && $exec->delete_imported) {
$this->error('--delete_imported flag and Config "import_via_symlink" setting are conflicting.');
$this->info(' Use --import_via_symlink=0 with --delete_imported to overwrite the Config.');
if ($exec->import_via_symlink && $exec->delete_imported) {
$this->error('The settings for import via symbolic links and deletion of imported files are conflicting');
$this->info(' Use --import_via_symlink={0|1} and --delete-imported={0|1} explicitly to apply a conflict-free setting');

return 1;
}
return 1;
}
$exec->skip_duplicates = !$this->option('skip_duplicates');
$exec->resync_metadata = $this->option('resync_metadata');

AccessControl::log_as_id($owner_id);

Expand Down

0 comments on commit 312a801

Please sign in to comment.