first cut at generation to file code
[scpubgit/App-SCS.git] / lib / App / SCS / Role / Plugin.pm
index c134fc3..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';
@@ -19,4 +20,21 @@ sub provides_pages { () }
 
 sub register { return }
 
+sub run_cli {
+  my ($self, $env) = @_;
+  my ($command, @argv) = @{$env->{argv}};
+  return unless $command;
+  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;
+}
+
 1;