mirror of
https://github.com/pragma-/pbot.git
synced 2025-07-21 21:07:24 +02:00
applets/trans.pl: improve options parsing
This commit is contained in:
parent
9d29336cb2
commit
675a723d57
8
applets/trans.pl
vendored
8
applets/trans.pl
vendored
@ -15,6 +15,7 @@ if (not @ARGV) {
|
||||
my $args = quotemeta "@ARGV";
|
||||
$args =~ s/\\([ :-])/$1/g;
|
||||
$args =~ s/^\s+|\s+$//g;
|
||||
$args =~ s/\s+--\s+/ /g;
|
||||
|
||||
my $opts = '-j -no-ansi -no-autocorrect -no-browser -no-pager -no-play';
|
||||
$opts .= ' -b' unless $args =~ /^-/;
|
||||
@ -29,7 +30,7 @@ $opts .= ' -b' unless $args =~ /^-/;
|
||||
Getopt::Long::Configure('no_auto_abbrev', 'no_ignore_case');
|
||||
|
||||
my %h;
|
||||
my @allowed = qw/V version H help M man T reference R reference-english S list-engines list-languages list-languages-english list-codes list-all L linguist e engine b brief d dictionary identify show-original show-original-phonetics show-translation show-translation-phonetics show-prompt-message show-languages show-original-dictionary show-dictionary show-alternatives hl host s sl source from t tl target to/;
|
||||
my @allowed = qw/V version H help M man T reference R reference-english S list-engines list-languages list-languages-english list-codes list-all L=s linguist=s e=s engine=s b brief d dictionary identify show-original=s show-original-phonetics=s show-translation=s show-translation-phonetics=s show-prompt-message=s show-languages=s show-original-dictionary=s show-dictionary=s show-alternatives=s hl=s host=s s=s sl=s source=s from=s t=s tl=s target=s to=s/;
|
||||
my ($ret, $rest) = GetOptionsFromString($args, \%h, @allowed);
|
||||
|
||||
if ($opt_err) {
|
||||
@ -41,6 +42,11 @@ $opts .= ' -b' unless $args =~ /^-/;
|
||||
print "Error parsing options.\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
if (not @$rest) {
|
||||
print "Missing phrase to translate.\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
my $result = `trans $opts $args`;
|
||||
|
@ -25,7 +25,7 @@ use PBot::Imports;
|
||||
# These are set by the /misc/update_version script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 4876,
|
||||
BUILD_REVISION => 4877,
|
||||
BUILD_DATE => "2025-07-20",
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user