X-Git-Url: http://git.tpope.net/?p=tpope-extra.git;a=blobdiff_plain;f=perl%2Fblogcl;h=3d2afe84b5f46a32992393f4319d2705f44997b7;hp=acb626a54ac18fc9286d8385bbb814d57cce19e4;hb=HEAD;hpb=4b793ebf19dd77f12a2f4de0e6648558e4ccbb15 diff --git a/perl/blogcl b/perl/blogcl index acb626a..3d2afe8 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 @@ -279,7 +301,7 @@ Error checking is minimal. Copyright by Tim Pope. All rights reserved. -This program 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