This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libcatmandu-perl.

commit f73a29b11200437e17027ad92771a3c182f25ce7
Author: Nicolas Steenlant <nicolas.steenl...@ugent.be>
Date:   Tue Jan 12 10:35:27 2016 +0100

    drop cmd
---
 lib/Catmandu/Cmd/delete.pm |  5 ++++-
 lib/Catmandu/Cmd/drop.pm   | 49 ++++++++++++++++++++++++++++++++++++++++++++++
 lib/Catmandu/Store.pm      | 10 ----------
 lib/Catmandu/Store/Hash.pm |  6 ++++--
 4 files changed, 57 insertions(+), 13 deletions(-)

diff --git a/lib/Catmandu/Cmd/delete.pm b/lib/Catmandu/Cmd/delete.pm
index 536788a..1d745e7 100644
--- a/lib/Catmandu/Cmd/delete.pm
+++ b/lib/Catmandu/Cmd/delete.pm
@@ -12,6 +12,7 @@ sub command_opt_spec {
     (
         [ "cql-query|q=s", "" ],
         [ "query=s", "" ],
+        [ "id=s@", "" ],
     );
 }
 
@@ -22,7 +23,9 @@ sub command {
 
     my $from_bag = delete $from_opts->{bag};
     my $from = Catmandu->store($from_args->[0], $from_opts)->bag($from_bag);
-    if ($opts->query // $opts->cql_query) {
+    if ($opts->id) {
+        $from->delete($_) for @{$opts->id};
+    } elsif ($opts->query // $opts->cql_query) {
         $from->delete_by_query(
             cql_query => $opts->cql_query,
             query     => $opts->query,
diff --git a/lib/Catmandu/Cmd/drop.pm b/lib/Catmandu/Cmd/drop.pm
new file mode 100644
index 0000000..92dfb03
--- /dev/null
+++ b/lib/Catmandu/Cmd/drop.pm
@@ -0,0 +1,49 @@
+package Catmandu::Cmd::drop;
+
+use Catmandu::Sane;
+
+our $VERSION = '0.9505';
+
+use parent 'Catmandu::Cmd';
+use Catmandu;
+use namespace::clean;
+
+sub command_opt_spec {
+    (
+        [ "bag=s", "drop a bag" ],
+    );
+}
+
+sub command {
+    my ($self, $opts, $args) = @_;
+
+    my ($from_args, $from_opts) = $self->_parse_options($args);
+
+    my $from = Catmandu->store($from_args->[0], $from_opts);
+    if ($opts->bag) {
+        $from->bag($opts->bag)->drop;
+    } else {
+        $from->drop;
+    }
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Catmandu::Cmd::drop - drop a store or one of it's bags
+
+=head1 EXAMPLES
+
+  catmandu drop <STORE> <OPTIONS>
+
+  # drop the whole store
+  catmandu drop ElasticSearch --index-name items
+  # drop a single bag
+  catmandu drop ElasticSearch --index-name items --bag thingies
+
+=cut
diff --git a/lib/Catmandu/Store.pm b/lib/Catmandu/Store.pm
index f21adf9..1d4d0f9 100644
--- a/lib/Catmandu/Store.pm
+++ b/lib/Catmandu/Store.pm
@@ -69,12 +69,6 @@ has bags => (
     }
 }
 
-sub drop_bags {
-    my ($self) = @_;
-    $_->drop for values %{$self->bags};
-    return;
-}
-
 1;
 
 __END__
@@ -142,10 +136,6 @@ Create or retieve a bag with name $name. Returns a 
L<Catmandu::Bag>.
 
 Delete the store and all it's bags.
 
-=head2 drop_bags
-
-Delete all bags, but not the store.
-
 =head2 log
 
 Return the current logger. Can be used when creating your own Stores.
diff --git a/lib/Catmandu/Store/Hash.pm b/lib/Catmandu/Store/Hash.pm
index 378f566..dfe73ef 100644
--- a/lib/Catmandu/Store/Hash.pm
+++ b/lib/Catmandu/Store/Hash.pm
@@ -15,14 +15,16 @@ has _hashes   => (is => 'ro' , lazy => 1, init_arg => 
undef, default => sub { +{
 has init_data => (is => 'ro');
 
 sub BUILD {
-    my $self = $_[0];
+    my ($self) = @_;
     if (my $data = $self->init_data) {
         $self->bag->add($_) for @$data;
     }
 }
 
 sub drop {
-    $_[0]->drop_bags;
+    my ($self) = @_;
+    $_->drop for values %{$self->bags};
+    return;
 }
 
 1;

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libcatmandu-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to