aboutsummaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2015-03-29 01:11:30 +0100
committerGuilhem Moulin <guilhem@fripost.org>2015-03-29 06:23:11 +0200
commit00bb3148842bb8e82aca39d6dd40eec46daadbaa (patch)
tree10483eac2c0d3c5732fa76a857b5662730ab66b6 /cli
parent80179b6680422abab87a2d06cb34166d46d9a2ff (diff)
Add a 'rm' command.
Diffstat (limited to 'cli')
-rwxr-xr-xcli/icevault27
-rw-r--r--cli/icevault.16
2 files changed, 33 insertions, 0 deletions
diff --git a/cli/icevault b/cli/icevault
index fdc1b74..be7902f 100755
--- a/cli/icevault
+++ b/cli/icevault
@@ -721,6 +721,7 @@ my @USAGE = (
ls => "[-0, --zero] [-r, --recursive] [scheme://[hostname/[identity]] ...]",
mv => "[-f, --force] scheme://hostname/identity1 scheme://hostname/identity2",
reencrypt => "[scheme://[hostname/[identity]] ...]",
+ rm => "[-f, --force] [-r, --recursive] scheme://[hostname/[identity]] ...",
);
if ($ARGV[0] eq '--help' or $ARGV[0] eq '-?') {
@@ -1216,6 +1217,32 @@ elsif ($COMMAND eq 'cp' or $COMMAND eq 'mv') {
commit(($COMMAND eq 'cp' ? 'copy' : 'move')." $source to $target", @filenames);
}
+elsif ($COMMAND eq 'rm') {
+ getopts( 'force|f' => "-f, --force \tNever prompt"
+ , 'recursive|r' => "-r, --recursive\tList identities recursively"
+ );
+
+ my @matches = list(@ARGV);
+ my @deleted;
+ foreach my $m (@matches) {
+ error "Use C<%s> for recursive deletion", '-r' unless
+ $m->{id} =~ /\A[A-Za-z0-9-]+:\/\/[^\P{Graph}:\/]+(?::\d+)?\/[^\P{Print}\/]+\z/;
+
+ if ($CONFIG{force} or promptYN "Really delete C<%s>?", 0, $m->{id}) {
+ unlink $m->{filename} or warning "Can't unlink C<%s>: %s", $m->{filename}, $!;
+ push @deleted, $m;
+ }
+ }
+ exit 1 unless @deleted; # nothing to do
+ commit( "Remove ".$deleted[0]->{id}.(scalar @deleted > 1 ? ' ...' : ''), map {$_->{filename}} @deleted );
+
+ foreach (@deleted) {
+ # try to delete empty parent directories
+ my $filename = $_->{filename} =~ s/\/[^\/]+$//r;
+ rmdir $filename and rmdir $filename =~ s/\/[^\/]+$//r;
+ }
+}
+
else {
print STDERR "Usage: $NAME [COMMAND] [OPTION ...] [ARG ...]\n";
error "Unknown command C<%s>. Try C<%s> for more information.", $COMMAND, "$NAME --help";
diff --git a/cli/icevault.1 b/cli/icevault.1
index 2e40af3..299e591 100644
--- a/cli/icevault.1
+++ b/cli/icevault.1
@@ -152,6 +152,12 @@ reencrypt the entire store. If \fIidentity\fR (resp.
\fIidentity\fR/\fIhostname\fR) is omitted, reencrypt all identities
found under \fIscheme\fR://\fIhostname\fR/ (resp. \fIscheme\fR://).
+.TP
+.B rm\fR [\fB-f\fR, \fB--force\fR] [\fB-r\fR, \fB--recursive\fR] [\fIscheme\fR://[\fIhostname\fR/[\fIidentity\fR]] ...]
+Delete the given identity prefix(es). Croak if \fIidentity\fR is
+omitted, unless \fB-r\fR is set. If \fB-f\fR is set, don't prompt before
+each deletion.
+
.SH GLOBAL OPTIONS
.TP