App-MtAws
view release on metacpan or search on metacpan
lib/App/MtAws/ConfigDefinition.pm view on Meta::CPAN
error(message 'Please specify filename or stdin')
}
}
sub http_download_options
{
scope('file_downloads', optional('segment-size'))
}
sub download_options
{
mandatory('dir'), check_base_dir, http_download_options();
}
sub check_wait
{
if (present('wait')) {
mandatory('wait'), download_options
} else {
return;
}
}
sub existing_journal
{
my ($journal) = @_;
if (defined($journal) && present($journal) && !exists $App::MtAws::ConfigEngine::context->{override_validations}->{journal}) { # TODO: this is hack!
error('Journal file not found') unless -f binaryfilename value($journal);
}
$journal;
}
sub writable_journal
{
my ($journal) = @_;
if (defined($journal) && present($journal)) {
my $value = binaryfilename value($journal);
error('Journal file not writable') if (-e $value && (! -w $value or -d $value));
}
$journal;
}
sub empty_journal
{
my ($journal) = @_;
if (defined($journal) && present($journal)) {
error('Journal file not empty - please provide empty file no write new journal') unless ! -s binaryfilename value($journal);
}
$journal;
}
sub check_https
{
if (present('protocol') and value('protocol') eq 'https') {
if (LWP::UserAgent->is_protocol_supported("https")) {
# to get LWP version, use LWP->VERSION instead of LWP::UserAgent->VERSION
error('LWP::UserAgent 6.x required to use HTTPS') unless LWP->VERSION() ge '6';
require LWP::Protocol::https;
error('LWP::Protocol::https 6.x required to use HTTPS') unless LWP::Protocol::https->VERSION && LWP::Protocol::https->VERSION ge '6';
} else {
error('IO::Socket::SSL or LWP::Protocol::https is not installed');
}
}
return;
}
sub check_max_size
{
if (present('check-max-file-size')) {
if (value('check-max-file-size') > 10_000 * value('partsize')) {
seen('check-max-file-size'), error(message('partsize_vs_maxsize',
"With current partsize %d partsizevalue%MiB and maximum allowed file size %d maxsizevalue%MiB, upload might exceed 10 000 parts. ".
"Increase %option partsize% or decrease %option maxsize%"),
partsize => 'partsize', maxsize => 'check-max-file-size', partsizevalue => value('partsize'), maxsizevalue => value('check-max-file-size'));
} else {
seen('check-max-file-size')
}
} else {
return;
}
}
sub detect_opts
{
seen('detect'), do { # TODO: movify configengine to somehow simplify this
explicit('detect') && (!present('replace-modified')) ?
error("option_for_command_can_be_used_only_with", a => 'detect', b => 'replace-modified', c => 'sync') :
();
};
}
sub sync_opts
{
my @sync_opts = qw/new replace-modified delete-removed/;
optional(@sync_opts);
if (present('new') || present('replace-modified') || present('delete-removed')) {
@sync_opts
} else {
impose('new', 1); # TODO: can cause problems in the future
}
}
sub get_config
{
my (%args) = @_;
my $c = App::MtAws::ConfigEngine->new(ConfigOption => 'config', CmdEncoding => 'terminal-encoding', ConfigEncoding => 'config-encoding', %args);
$c->{preinitialize} = sub {
set_filename_encoding $c->{options}{'filenames-encoding'}{value};
};
$c->define(sub {
message 'no_command', 'Please specify command', allow_redefine=>1;
message 'already_specified_in_alias', '%option b% specified, while %option a% already defined', allow_redefine => 1;
message 'unexpected_argument', "Extra argument in command line: %a%", allow_redefine => 1;
message 'mandatory', "Please specify %option a%", allow_redefine => 1;
message 'cannot_read_config', 'Cannot read config file "%config%"';
message 'deprecated_option', '%option% deprecated, use %main% instead';
( run in 1.011 second using v1.01-cache-2.11-cpan-39bf76dae61 )