From 3462e909af35011e5486cc84e32e16adc4d66bbc Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Tue, 10 Aug 2004 19:42:14 +0000 Subject: [PATCH] Delete function added --- perl/blogcl | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/perl/blogcl b/perl/blogcl index acb626a..28d87a7 100755 --- a/perl/blogcl +++ b/perl/blogcl @@ -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 S<[ B<--title>|B<-t> "Title" ]> S<[ B<--category>|B<-c> category[,...] ]> S<[ B<--file>|B<-f> F ]> 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 | B postid | B postid | B [count] | B } +B S<[ B<--title>|B<-t> "Title" ]> S<[ B<--category>|B<-c> category[,...] ]> S<[ B<--file>|B<-f> F ]> 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 | B postid | B postid | B postid | B [count] | B } =head1 DESCRIPTION @@ -202,6 +219,11 @@ post's postid, use B. Shows the contents of the post specified by the postid given on the command-line. +=item B + +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 recents posts and their postids. An optional integer specifies the number -- 2.30.2