]> iEval git - gruntmaster-data.git/blobdiff - lib/Gruntmaster/App/Command/Set.pm
Replace gruntmaster-* scripts with App::Cmd-based gm
[gruntmaster-data.git] / lib / Gruntmaster / App / Command / Set.pm
diff --git a/lib/Gruntmaster/App/Command/Set.pm b/lib/Gruntmaster/App/Command/Set.pm
new file mode 100644 (file)
index 0000000..b3754dd
--- /dev/null
@@ -0,0 +1,35 @@
+package Gruntmaster::App::Command::Set;
+
+use 5.014000;
+use warnings;
+
+our $VERSION = '5999.000_004';
+
+use Gruntmaster::App '-command';
+use Gruntmaster::Data;
+
+use File::Slurp qw/read_file/;
+
+sub opt_spec {
+       ['file!', 'Use the contents of a file as value'],
+}
+
+sub usage_desc { "%c [-cjpu] set id column value [column value ...]\n%c [-cjpu] set --file id column filename [column filename ...]" }
+
+sub validate_args {
+       my ($self, $opt, $args) = @_;
+       my @args = @$args;
+       $self->usage_error('No table selected') unless $self->app->table;
+       $self->usage_error('Not enough arguments provided') if @args < 3;
+       $self->usage_error('The number of arguments must be odd') unless @args % 2;
+}
+
+sub execute {
+       my ($self, $opt, $args) = @_;
+       my ($id, %values) = @$args;
+       %values = map { $_ => scalar read_file $values{$_} } keys %values if $opt->{file};
+       db->update($self->app->table, \%values, {id => $id});
+}
+
+1;
+__END__
This page took 0.015369 seconds and 4 git commands to generate.