X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=gruntmaster-problem;h=7e979cdc05164e6c8c4788efb6d19756e7ada04b;hb=ca77adce9ec73cdbb45cf3fe35fc04191b0f2b3d;hp=5d18b2b7f22223c63f26ec42c70f5ff9ae1398ad;hpb=aaa9eb7d81598848183239016890f3a851082154;p=gruntmaster-data.git diff --git a/gruntmaster-problem b/gruntmaster-problem index 5d18b2b..7e979cd 100755 --- a/gruntmaster-problem +++ b/gruntmaster-problem @@ -3,8 +3,10 @@ use v5.14; use Gruntmaster::Data; +use File::Temp qw/tempfile/; + use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ]; -use File::Slurp qw/read_file/; +use File::Slurp qw/read_file write_file/; use JSON qw/encode_json/; use Term::ANSIColor qw/RED RESET/; use Getopt::Long qw/:config require_order/; @@ -93,9 +95,9 @@ sub cmd_add{ sub cmd_set{ my $file; GetOptions ( 'file!' => \$file ); - my ($id, %values) = @_; + my ($id, %values) = @ARGV; %values = map { $_ => scalar read_file $values{$_} } keys %values if $file; - $db->problem($id)->update(\%values) + $db->problem($id)->update(\%values); } sub cmd_get{ @@ -103,13 +105,24 @@ sub cmd_get{ say $db->problem($id)->get_column($col) } +sub cmd_edit{ + my ($id, $col) = @_; + my ($fh, $file) = tempfile 'gruntmaster-problem-editXXXX', TMPDIR => 1, UNLINK => 1; + write_file $fh, $db->problem($id)->get_column($col); + close $fh; + my $editor = $ENV{EDITOR} // 'editor'; + system $editor, $file; + $db->problem($id)->update({$col => read_file $file}); +} + sub cmd_list{ local $, = "\n"; say map {$_->id} $db->problems->all } sub cmd_rm{ - $db->problem(shift)->delete + my ($id) = @_; + $db->problem($id)->delete; } sub cmd_show{ @@ -154,6 +167,7 @@ gruntmaster-problem - shell interface to Gruntmaster 6000 problems gruntmaster-problem show problem_id gruntmaster-problem set [--file] problem_id key value gruntmaster-problem get problem_id key + gruntmaster-problem edit problem_id key =head1 DESCRIPTION @@ -185,6 +199,10 @@ Sets the I configuration option of problem I to I. Get the value of the I configuration option of problem I +=item B I I + +Opens an editor with the value of the I configuration option. After the editor exits, the option is updated to the value of the file. + =item B --file I I I Sets the I configuration option of problem I to the contents of the file I.