use DBI;
use Encode;
use Encode::Locale;
-use Getopt::Std;
use POSIX;
my $BAD = 0;
$t, $tag, $lang, encode locale => $title;
}
} elsif ($op eq "new") {
- my %o;
- getopts "l:t:", \%o and @ARGV == 0
- or Odin::fail "usage: new [-l LANG] [-t TITLE]";
- my %p = (title => decode(locale => $o{t}), lang => $o{l} // "txt",
- content => read_content);
+ my $op = Odin::OptParse->new(@ARGV);
+ my $p = (title => undef, lang => "txt");
+ while (my $o = $op->get) {
+ if ($o eq "l") { $p{lang} = $op->arg; }
+ elsif ($o eq "t") { $p{title} = decode locale => $op->arg; }
+ else { $op->unk; }
+ }
+ @ARGV = $op->rest;
+ $op->bad if @ARGV;
+ $op->ok or Odin::fail "usage: new [-l LANG] [-t TITLE]";
+ $p{content} = read_content;
my $db = Odin::open_db;
my $c = "";
while (read STDIN, my $buf, 8192) { $c .= $buf; }
@ARGV or Odin::fail "usage: del TAG ...";
Odin::delete_pastebin map { $_, undef } @ARGV;
} elsif ($op eq "update") {
- my %o;
- getopts "cl:t:", \%o and @ARGV == 1
- or Odin::fail "usage: update [-c] [-l LANG] [-t TITLE] TAG";
- my ($tag) = @ARGV;
- my %p = (title => decode(locale => $o{t}), lang => $o{l});
- if ($o{c}) { $p{content} = read_content; }
+ my $op = Odin::OptParse->new(@ARGV);
+ my %p = ();
+ my $contentp = 0;
+ while (my $o = $op->get) {
+ if ($o eq "c") { $contentp = 1; }
+ elsif ($o eq "l") { $p{lang} = $op->arg; }
+ elsif ($o eq "t") { $p{title} = decode locale => $op->arg; }
+ else { $op->unk; }
+ }
+ @ARGV = $op->rest;
+ $op->bad if @ARGV;
+ $op->ok or Odin::fail "usage: new [-l LANG] [-t TITLE]";
+ $p{content} = read_content if $contentp;
Odin::update_pastebin $tag, undef, %p or Odin::fail "nothing changed";
} else {
Odin::fail "unknown operation `$op'";