Skip to content
Snippets Groups Projects
Commit 9c6f4182 authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- minor, disabled unused CLI options

- add validation and conversion of some CLI options
parent 0779294c
Branches
Tags
No related merge requests found
...@@ -5,6 +5,7 @@ use warnings; ...@@ -5,6 +5,7 @@ use warnings;
use feature qw(say); use feature qw(say);
use SLUB::LZA::TA::Archivematica::Elasticsearch; use SLUB::LZA::TA::Archivematica::Elasticsearch;
use Data::Printer; use Data::Printer;
use Date::Calc qw(Date_to_Time);
# VERSION # VERSION
...@@ -21,12 +22,10 @@ Examples: ...@@ -21,12 +22,10 @@ Examples:
* Is this dc identifier in archive? * Is this dc identifier in archive?
'$0 count -d SLUB:LZA:Kitodo:kitodo:422766' '$0 count -d SLUB:LZA:Kitodo:kitodo:422766'
* How many AIPs were modified in 2021-05-31? * How many AIPs were created in 2021-05-31?
'$0 count -m 2021-05-31' '$0 count -m 2021-05-31'
* How many AIPs have at least one invalid file?
'$0 count --with-invalid-files'
* How many AIPs with mkv-files are in archive? * How many AIPs with mkv-files are in archive?
'$0 count --with-format=fmt/569' '$0 count --with-format fmt/569'
DESCR DESCR
sub description { sub description {
...@@ -39,22 +38,45 @@ sub opt_spec { ...@@ -39,22 +38,45 @@ sub opt_spec {
["debug" => "enable user agent debug output"], ["debug" => "enable user agent debug output"],
["datemode" => hidden => {one_of => [ ["datemode" => hidden => {one_of => [
["creationdate|c=s" => "search based on creationdate string"], ["creationdate|c=s" => "search based on creationdate string"],
["modificationdate|m=s" => "search based on modificationdate string"] #["modificationdate|m=s" => "search based on modificationdate string"]
] } ], ] } ],
["lzaid|l=s", "count AIPs by given LZA id"], ["lzaid|l=s", "count AIPs by given LZA id"],
["descriptive|d=s" => "count based on string search in descriptive metadata"], ["descriptive|d=s" => "count based on string search in descriptive metadata"],
["source|s=s" => "count based on string search in source metadata"], #["source|s=s" => "count based on string search in source metadata"],
["aip|a=s" => "count AIPs by given AIP id"], ["aip|a=s" => "count AIPs by given AIP id"],
["format" => hidden => {one_of => [ ["format" => hidden => {one_of => [
["pronom-id=s" => "with pronom format id"], ["pronom-id|p=s" => "with pronom format id"],
#["without-format=s" => "without pronom format id"], #["without-format=s" => "without pronom format id"],
] } ], ] } ],
[],
[ 'help|h', 'print usage message and exit', { shortcircuit => 1 } ],
[ 'target-version|V' => 'get current elasticsearch version', { shortcircuit => 1 } ],
[ 'version|v', 'print version information', { shortcircuit => 1 } ],
); );
} }
sub validate_args { sub validate_args {
my ($self, $opt, $args) = @_; my ($self, $opt, $args) = @_;
# no args allowed but options! # no args allowed but options!
$self->usage_error("No args allowed") if @$args; $self->usage_error("No args allowed") if @$args;
if (exists $opt->{creationdate}) {
if ($opt->{creationdate} =~ m/^(\d{4})-(\d{2})-(\d{2})$/ ) {
my $epoch = Date_to_Time($1, $2, $3, 0, 0, 0);
$opt->{creationdate_epoch} = $epoch;
} else {
$self->usage_error("--creationdate expects date in format yyyy-mm-dd")
}
}
if (exists $opt->{pronom_id}) {
$self->usage_error("--pronom-id expects string which is conform to PUID structure as described in https://www.nationalarchives.gov.uk/aboutapps/pronom/puid.htm")
unless ($opt->{pronom_id} =~ m/^(x-)?fmt\/[a-z0-9]+$/ );
}
if (exists $opt->{lzaid}) {
my $rx_up = qr{[A-Za-z0-9_-]+}; # archive name & internal workflow
my $rx_lw = qr{[a-z0-9_-]+}; # external workflow & external id
$self->usage_error("--lzaid expects string which is conform to SLUBArchiv internal scheme")
unless ($opt->{lzaid} =~ m/^$rx_up:$rx_up:$rx_up:$rx_lw:$rx_lw$/);
}
1; 1;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment