Grammar error
[tpope-extra.git] / perl / blogcl
index 71403b8e3f116ae1caa694b39ed1aebeaa5f0e6c..3d2afe84b5f46a32992393f4319d2705f44997b7 100755 (executable)
@@ -2,6 +2,8 @@
 # $Id$
 # -*- perl -*- vim: ft=perl sw=4 sts=4
 
+# For documentation, run perldoc blogcl
+
 use strict;
 use Net::MovableType;
 use Getopt::Long;
@@ -23,15 +25,10 @@ Getopt::Long::Configure ("bundling", "auto_help");
 die "Invalid arguments\n" unless
 GetOptions (\%opts, 'username|l=s', 'password|p=s', 'url|u=s', 'blogid|b=i', 'title|t=s', 'category|c=s', 'file|f=s');
 
-if ($ARGV[0] eq "help") {
-    Getopt::Long::HelpMessage();
-    exit(0);
-}
-
 sub init_mt {
-    die "No url given.\n" unless(defined("$url"));
-    die "No username given.\n" unless(defined("$username"));
-    die "No passowrd given.\n" unless(defined("$password"));
+    die "No url given.\n" unless(defined($opts{url}));
+    die "No username given.\n" unless(defined($opts{username}));
+    die "No passowrd given.\n" unless(defined($opts{password}));
     $mt = new Net::MovableType($opts{'url'}) || die "$!";
     $mt->username($opts{'username'});
     $mt->password($opts{'password'});
@@ -60,6 +57,23 @@ sub print_categories {
     print join("\n",map {$_->{categoryName}} @{$mt->getCategoryList()}), "\n";
 }
 
+sub delete_post {
+    my $postid=shift;
+    my $post = $mt->getPost($postid) or die "$!";
+    my $categories = $mt->getPostCategories($postid) or die "$!";
+    if(defined($opts{file})) {
+       if($opts{file} eq "-") {
+           print STDOUT $post->{description}, "\n";
+       } else {
+           open FH, ">".$opts{file} or die "$!";
+           print $opts{file}, "\n";
+           print FH $post->{description}, "\n";
+           close FH;
+       }
+    }
+    $mt->deletePost($postid,1);
+}
+
 sub show_post {
     my $postid=shift;
     my $post = $mt->getPost($postid) or die "$!";
@@ -165,6 +179,9 @@ if ($ARGV[0] eq "help") {
 } elsif ($ARGV[0] eq "show" && $ARGV[1] =~ /^\d+$/) {
     init_mt();
     show_post($ARGV[1])
+} elsif ($ARGV[0] eq "delete" && $ARGV[1] =~ /^\d+$/) {
+    init_mt();
+    delete_post($ARGV[1])
 } else {
     Getopt::Long::HelpMessage();
     exit(1);
@@ -176,7 +193,7 @@ blogcl - Blog from the command-line
 
 =head1 SYNOPSIS
 
-B<blogcl> S<[ B<--title>|B<-t> "Title" ]> S<[ B<--category>|B<-c> category[,...] ]> S<[ B<--file>|B<-f> F<file> ]> S<[ B<--username>|B<-l> username ]> S<[ B<--password>|B<-p> password ]> S<[ B<--url>|B<-u> url ]> S<[ B<--blogid>|B<-b> blogid ]> { B<new> | B<edit> postid | B<show> postid | B<list> [count] | B<categories> }
+B<blogcl> S<[ B<--title>|B<-t> "Title" ]> S<[ B<--category>|B<-c> category[,...] ]> S<[ B<--file>|B<-f> F<file> ]> S<[ B<--username>|B<-l> username ]> S<[ B<--password>|B<-p> password ]> S<[ B<--url>|B<-u> url ]> S<[ B<--blogid>|B<-b> blogid ]> { B<new> | B<edit> postid | B<show> postid | B<delete> postid | B<list> [count] | B<categories> }
 
 =head1 DESCRIPTION
 
@@ -202,6 +219,11 @@ post's postid, use B<list>.
 Shows the contents of the post specified by the postid given on the
 command-line.
 
+=item B<delete>
+
+Deletes a post.  Specify a B<--file> option to back up the contents (but not
+the title or category) of the post.
+
 =item B<list>
 
 List recents posts and their postids.  An optional integer specifies the number
@@ -279,7 +301,7 @@ Error checking is minimal.
 
 Copyright by Tim Pope. All rights reserved.
 
-This library is a free software; you may redistribute it and/or modify it under
+This program is free software; you may redistribute it and/or modify it under
 the same terms as perl itself.
 
 =head1 AUTHORS