Delete function added
authorTim Pope <code@tpope.net>
Tue, 10 Aug 2004 19:42:14 +0000 (19:42 +0000)
committerTim Pope <code@tpope.net>
Tue, 10 Aug 2004 19:42:14 +0000 (19:42 +0000)
perl/blogcl

index acb626a54ac18fc9286d8385bbb814d57cce19e4..28d87a7a69f9c11570464c75e0292f230bd19312 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,11 +25,6 @@ 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($opts{url}));
     die "No username given.\n" unless(defined($opts{username}));
@@ -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