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";
37 new [-l LANG] [-t TITLE]
39 update [-c] [-l LANG] [-t TITLE] TAG
41 } elsif ($op eq "langs") {
42 @ARGV == 0 or Odin::fail "usage: list";
43 my $db = Odin::open_db;
44 for my $r (@{$db->selectall_arrayref
45 ("SELECT lang, descr FROM odin_pastebin_lang
46 ORDER BY lang", undef)}) {
47 my ($lang, $descr) = @$r;
48 Odin::print_columns $lang => 16, $descr => 0;
50 } elsif ($op eq "list") {
51 @ARGV == 0 or Odin::fail "usage: list";
52 my $db = Odin::open_db;
53 for my $r (@{$db->selectall_arrayref
54 ("SELECT tag, stamp, lang, title
55 FROM odin_pastebin WHERE owner = ?
56 ORDER BY stamp", undef, $Odin::WHO)}) {
57 my ($tag, $stamp, $lang, $title) = @$r;
58 Odin::print_columns Odin::fmt_time $stamp => 25,
59 $tag => 12, $lang => 16, (encode locale => $title) => 0;
61 } elsif ($op eq "new") {
62 my $op = Odin::OptParse->new(@ARGV);
63 my $p = (title => undef, lang => "txt");
64 while (my $o = $op->get) {
65 if ($o eq "l") { $p{lang} = $op->arg; }
66 elsif ($o eq "t") { $p{title} = decode locale => $op->arg; }
71 $op->ok or Odin::fail "usage: new [-l LANG] [-t TITLE]";
72 $p{content} = read_content;
73 my ($tag, $edit) = Odin::new_pastebin %p;
74 print "$Odin::PASTEBIN/$tag $edit\n";
75 } elsif ($op eq "get") {
76 @ARGV == 1 or Odin::fail "usage: get TAG";
78 Odin::get_pastebin Odin::open_db, $tag, my %p;
79 print encode locale => $p{content};
80 } elsif ($op eq "claim") {
81 @ARGV == 2 or Odin::fail "usage: claim TAG EDITKEY";
82 my ($tag, $key) = @ARGV;
83 Odin::claim_pastebin $tag, $key;
84 } elsif ($op eq "rekey") {
85 @ARGV == 1 or Odin::fail "usage: rekey TAG";
87 my $key = Odin::rekey_pastebin $tag;
89 } elsif ($op eq "del") {
90 @ARGV or Odin::fail "usage: del TAG ...";
91 Odin::delete_pastebin map { $_, undef } @ARGV;
92 } elsif ($op eq "update") {
93 my $op = Odin::OptParse->new(@ARGV);
96 while (my $o = $op->get) {
97 if ($o eq "c") { $contentp = 1; }
98 elsif ($o eq "l") { $p{lang} = $op->arg; }
99 elsif ($o eq "t") { $p{title} = decode locale => $op->arg; }
103 $op->bad if @ARGV != 1;
104 $op->ok or Odin::fail "usage: update [-c] [-l LANG] [-t TITLE] TAG";
105 my $tag = shift @ARGV;
106 $p{content} = read_content if $contentp;
107 Odin::update_pastebin $tag, undef, %p or Odin::fail "nothing changed";
109 Odin::fail "unknown operation `$op'";