15 print STDERR "$Odin::PROG: $m\n";
22 while (read STDIN, my $buf, 8192) { $c .= $buf; }
23 return Odin::tidy_pastebin_content decode locale => $c;
26 my $op = shift(@ARGV) // "help";
36 new [-l LANG] [-t TITLE]
38 update [-c] [-l LANG] [-t TITLE] TAG
40 } elsif ($op eq "list") {
41 @ARGV == 0 or Odin::fail "usage: list";
42 my $db = Odin::open_db;
43 for my $r (@{$db->selectall_arrayref
44 ("SELECT tag, stamp, lang, title
45 FROM odin_pastebin WHERE owner = ?
46 ORDER BY stamp", undef, $Odin::WHO)}) {
47 my ($tag, $stamp, $lang, $title) = @$r;
48 Odin::print_columns Odin::fmt_time $stamp => 25,
49 $tag => 12, $lang => 16, (encode locale => $title) => 0;
51 } elsif ($op eq "new") {
52 my $op = Odin::OptParse->new(@ARGV);
53 my $p = (title => undef, lang => "txt");
54 while (my $o = $op->get) {
55 if ($o eq "l") { $p{lang} = $op->arg; }
56 elsif ($o eq "t") { $p{title} = decode locale => $op->arg; }
61 $op->ok or Odin::fail "usage: new [-l LANG] [-t TITLE]";
62 $p{content} = read_content;
63 @{$db->selectall_arrayref
64 ("SELECT lang FROM odin_pastebin_lang WHERE lang = ?", undef, $p{lang})}
65 or Odin::fail "unknown language `$p{lang}'";
66 my ($tag, $edit) = Odin::new_pastebin %p;
67 print "$Odin::PASTEBIN/$tag $edit\n";
68 } elsif ($op eq "get") {
69 @ARGV == 1 or Odin::fail "usage: get TAG";
71 Odin::get_pastebin Odin::open_db, $tag, my %p;
72 print encode locale => $p{content};
73 } elsif ($op eq "claim") {
74 @ARGV == 2 or Odin::fail "usage: claim TAG EDITKEY";
75 my ($tag, $key) = @ARGV;
76 Odin::claim_pastebin $tag, $key;
77 } elsif ($op eq "rekey") {
78 @ARGV == 1 or Odin::fail "usage: rekey TAG";
80 my $key = Odin::rekey_pastebin $tag;
82 } elsif ($op eq "del") {
83 @ARGV or Odin::fail "usage: del TAG ...";
84 Odin::delete_pastebin map { $_, undef } @ARGV;
85 } elsif ($op eq "update") {
86 my $op = Odin::OptParse->new(@ARGV);
89 while (my $o = $op->get) {
90 if ($o eq "c") { $contentp = 1; }
91 elsif ($o eq "l") { $p{lang} = $op->arg; }
92 elsif ($o eq "t") { $p{title} = decode locale => $op->arg; }
96 $op->bad if @ARGV != 1;
97 $op->ok or Odin::fail "usage: update [-c] [-l LANG] [-t TITLE] TAG";
98 my $tag = shift @ARGV;
99 $p{content} = read_content if $contentp;
100 Odin::update_pastebin $tag, undef, %p or Odin::fail "nothing changed";
102 Odin::fail "unknown operation `$op'";