pass parsed arg object to Invocation when using mx-run
[gitmo/MooseX-Runnable.git] / bin / mx-run
CommitLineData
c527660e 1#!/usr/bin/env perl
2
3use strict;
4use warnings;
5
2503822b 6use MooseX::Runnable::Util::ArgParser;
040d22bb 7use MooseX::Runnable::Invocation::MxRun;
441297a7 8
9exit run();
10
11sub run {
2503822b 12 my $args = MooseX::Runnable::Util::ArgParser->new(
13 argv => \@ARGV,
14 );
441297a7 15
2503822b 16 help() if $args->is_help;
441297a7 17
2503822b 18 # set @INC from -I...
19 unshift @INC, $_->stringify for $args->include_paths;
20
21 # load -M... modules
22 do { eval "require $_"; die $@ if $@ }
23 for $args->modules;
24
25 my $app = $args->class_name;
c4e3f06e 26 local $0 = "mx-run ... $app";
27
040d22bb 28 return MooseX::Runnable::Invocation::MxRun->new(
29 class => $app,
30 plugins => $args->plugins,
31 parsed_args => $args,
2503822b 32 )->run($args->app_args);
441297a7 33}
34
35sub help {
36 print <<'END';
37
38This is mx-run, a utility for running MooseX::Runnable classes.
2503822b 39
40usage: mx-run <mx-run options> -- Class::Name <options for Class::Name>
41
441297a7 42mx-run options:
43
44 --help -? -h Print this message
2503822b 45 -I<path> Add <path> to @INC before loading modules
6a06028a 46 -M<module> use <module> immediately
47 +PluginName Load PluginName (see MooseX::Runnable::Invocation)
48
2503822b 49Note that as soon as +PluginName is seen, all following -[IM] options
50are ignored by mx-run, and are instead processed by PluginName. So
51put them at the very beginning.
52
53In the simplest cases, where you use only -I or -M (no plugins), you
54may omit the -- before the class name.
441297a7 55
56To get help for Class::Name, run:
57
58 mx-run Class::Name --help
2503822b 59
60Syntax examples:
61
62 mx-run -Ilib Class::Name # Local Class::Name
5d5f8fa1 63 mx-run -Ilib -MCarp::Always +Debug -- Class::Name # Debugging
2503822b 64
441297a7 65END
66
67 exit 1;
68}
c527660e 69
70__END__
71
72=head1 NAME
73
74mx-run - script to run MooseX::Runnable classes