Make a licensing decision: it's all AGPLv3+.
[odin-cgi] / bin / pastebin.userv
index c45d4e6..2e493fc 100755 (executable)
@@ -1,4 +1,27 @@
 #! /usr/bin/perl
+###
+### Pastebin userv interface for Odin
+###
+### (c) 2015 Mark Wooding
+###
+
+###----- Licensing notice ---------------------------------------------------
+###
+### This file is part of the `odin.gg' service, `odin-cgi'.
+###
+### `odin-cgi' is free software; you can redistribute it and/or modify
+### it under the terms of the GNU Affero General Public License as
+### published by the Free Software Foundation; either version 3 of the
+### License, or (at your option) any later version.
+###
+### `odin-cgi' is distributed in the hope that it will be useful,
+### but WITHOUT ANY WARRANTY; without even the implied warranty of
+### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+### GNU Affero General Public License for more details.
+###
+### You should have received a copy of the GNU Affero General Public
+### License along with `odin-cgi'; if not, see
+### <http://www.gnu.org/licenses/>.
 
 use lib "lib";
 
@@ -32,11 +55,21 @@ Commands available:
        del TAG ...
        get TAG
        help
+       langs
        list
        new [-l LANG] [-t TITLE]
        rekey TAG
        update [-c] [-l LANG] [-t TITLE] TAG
 EOF
+} elsif ($op eq "langs") {
+  @ARGV == 0 or Odin::fail "usage: list";
+  my $db = Odin::open_db;
+  for my $r (@{$db->selectall_arrayref
+               ("SELECT lang, descr FROM odin_pastebin_lang
+                 ORDER BY lang", undef)}) {
+    my ($lang, $descr) = @$r;
+    Odin::print_columns $lang => 16, $descr => 0;
+  }
 } elsif ($op eq "list") {
   @ARGV == 0 or Odin::fail "usage: list";
   my $db = Odin::open_db;
@@ -60,13 +93,6 @@ EOF
   $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; }
-  $p{content} = read_content;
-  @{$db->selectall_arrayref
-    ("SELECT lang FROM odin_pastebin_lang WHERE lang = ?", undef, $p{lang})}
-    or Odin::fail "unknown language `$p{lang}'";
   my ($tag, $edit) = Odin::new_pastebin %p;
   print "$Odin::PASTEBIN/$tag $edit\n";
 } elsif ($op eq "get") {
@@ -97,8 +123,9 @@ EOF
     else { $op->unk; }
   }
   @ARGV = $op->rest;
-  $op->bad if @ARGV;
-  $op->ok or Odin::fail "usage: new [-l LANG] [-t TITLE]";
+  $op->bad if @ARGV != 1;
+  $op->ok or Odin::fail "usage: update [-c] [-l LANG] [-t TITLE] TAG";
+  my $tag = shift @ARGV;
   $p{content} = read_content if $contentp;
   Odin::update_pastebin $tag, undef, %p or Odin::fail "nothing changed";
 } else {