fix usage line in MX::Getopt scripts
[gitmo/MooseX-Runnable.git] / bin / mx-run
CommitLineData
c527660e 1#!/usr/bin/env perl
2
3use strict;
4use warnings;
5
441297a7 6use MooseX::Runnable::Run; # incidentally, we don't actually use this...
7
8exit run();
9
10sub run {
11 my ($includes, $plugins, $app, $argv) = parse_argv();
12
13 unshift @INC, $_ for @$includes;
14 help() unless $app;
15
c4e3f06e 16 local $0 = "mx-run ... $app";
17
441297a7 18 return MooseX::Runnable::Invocation->new(
19 class => $app,
20 plugins => $plugins || [],
21 )->run(@$argv);
22}
23
24sub parse_argv {
25 # we need to parse "incrementally" so we can identify:
26 # - our args (-Ilib, and --help, -h, and -?)
27 # - plugins to load (+Plugin)
28 # - the class name
29 # - the class' args
30 # code that's better than this is welcome!
31
32 my (@include, @plugins, $app);
33
34 while( my $arg = shift @ARGV ){
35 if ($arg =~ /^-I([^-]+)/){ # XXX: handle -I"quoted string" ?
36 push @include, $1;
37 }
38 elsif ($arg =~ /^\+\+?([A-Za-z:_]+)$/){ # second + is for +Foo::Bar
39 push @plugins, $1;
40 }
41 elsif ($arg =~ /^--([^-]+)$/){
42 help();
43 }
44 else {
45 if($arg =~ /^([A-Za-z:_]+)$/){
46 $app = $arg;
47 last;
48 }
49 else {
50 help();
51 }
52 }
53 }
54
55 return \@include, \@plugins, $app, \@ARGV;
56}
57
58sub help {
59 print <<'END';
60
61This is mx-run, a utility for running MooseX::Runnable classes.
62usage: mx-run <mx-run options> Class::Name <options for Class::Name>
63mx-run options:
64
65 --help -? -h Print this message
66 +PluginName Load PluginName (see MooseX::Runnable::Invocation)
67 -I<path> Add <path> to @INC before loading Class::Name
68
69To get help for Class::Name, run:
70
71 mx-run Class::Name --help
72END
73
74 exit 1;
75}
c527660e 76
77__END__
78
79=head1 NAME
80
81mx-run - script to run MooseX::Runnable classes