first cut at generation to file code
[scpubgit/App-SCS.git] / lib / App / SCS / Role / Plugin.pm
index c842e12..7569dcd 100644 (file)
@@ -1,5 +1,6 @@
 package App::SCS::Role::Plugin;
 
+use Getopt::Long qw(GetOptionsFromArray);
 use Moo::Role;
 
 with 'App::SCS::Role::WithConfig';
@@ -23,8 +24,16 @@ sub run_cli {
   my ($self, $env) = @_;
   my ($command, @argv) = @{$env->{argv}};
   return unless $command;
-  return unless $self->can(my $meth = "run_command_${command}");
-  $self->$meth({ argv => \@argv, %$env });
+  return unless my $code = $self->can(my $meth = "run_command_${command}");
+  my $run_env = { %$env };
+  if (my $proto = prototype $code) {
+    my @spec = split ';', $proto;
+    my %opt;
+    GetOptionsFromArray(\@argv, \%opt, @spec);
+    $run_env->{options} = \%opt;
+  }
+  $run_env->{argv} = \@argv;
+  $self->$meth($run_env);
   return 1;
 }