X-Git-Url: http://git.ieval.ro/?p=gruntmaster-data.git;a=blobdiff_plain;f=lib%2FGruntmaster%2FApp%2FCommand%2FEdit.pm;fp=lib%2FGruntmaster%2FApp%2FCommand%2FEdit.pm;h=24785ab01996e300122fef193fbc39d719938655;hp=0000000000000000000000000000000000000000;hb=5e26317ea435eaa5dd8d8fa7ccef5fd0e883b998;hpb=7e8f5f0e842c52b928fd7d8ac97da45bf9f7fc83 diff --git a/lib/Gruntmaster/App/Command/Edit.pm b/lib/Gruntmaster/App/Command/Edit.pm new file mode 100644 index 0000000..24785ab --- /dev/null +++ b/lib/Gruntmaster/App/Command/Edit.pm @@ -0,0 +1,77 @@ +package Gruntmaster::App::Command::Edit; + +use 5.014000; +use warnings; + +our $VERSION = '5999.000_015'; + +use File::Temp qw/tempfile/; +use File::Slurp qw/read_file write_file/; +use Gruntmaster::App '-command'; +use Gruntmaster::Data; + +sub usage_desc { '%c [-cjpu] edit id column' } + +sub validate_args { + my ($self, $opt, $args) = @_; + my @args = @$args; + $self->usage_error('No table selected') unless $self->app->table; + $self->usage_error('Wrong number of arguments') if @args != 2; +} + +sub execute { + my ($self, $opt, $args) = @_; + my ($obj, $col) = @$args; + my ($fh, $file) = tempfile 'gruntmaster-problem-editXXXX', TMPDIR => 1, UNLINK => 1; + write_file $fh, db->select($self->app->table, $col, {id => $obj})->flat; + close $fh; + my $editor = $ENV{EDITOR} // 'editor'; + system $editor, $file; + db->update($self->app->table, {$col => scalar read_file $file}, {id => $obj}); +} + +1; +__END__ + +=encoding utf-8 + +=head1 NAME + +Gruntmaster::App::Command::Edit - edit a property of an object + +=head1 SYNOPSIS + + gm -u edit MGV name + gm -p edit aplusb level + gm -c edit test_ct description + gm -j edit 100 result_text + +=head1 DESCRIPTION + +The get command takes two arguments: an object id and a property name, +and opens an editor with the value of that property. Upon exiting the +editor, the property is set to the contents of the file. + +=head1 ENVIRONMENT + +The editor is taken from the EDITOR environment variable. If this +variable is unset, the program F is executed instead. + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Marius Gavrilescu, Emarius@ieval.roE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2014-2015 by Marius Gavrilescu + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.20.1 or, +at your option, any later version of Perl 5 you may have available. + + +=cut