.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "MooseX::App 3pm" .TH MooseX::App 3pm "2021-01-04" "perl v5.32.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" MooseX::App \- Write user\-friendly command line apps with even less suffering .SH "SYNOPSIS" .IX Header "SYNOPSIS" In your base class: .PP .Vb 2 \& package MyApp; \& use MooseX::App qw(Color); \& \& option \*(Aqglobal_option\*(Aq => ( \& is => \*(Aqrw\*(Aq, \& isa => \*(AqBool\*(Aq, \& documentation => q[Enable this to do fancy stuff], \& ); # Global option \& \& has \*(Aqprivate\*(Aq => ( \& is => \*(Aqrw\*(Aq, \& ); # not exposed .Ve .PP Write multiple command classes (If you have only a single command class you should use MooseX::App::Simple instead). Packackes in the namespace may be deeply nested. .PP .Vb 3 \& package MyApp::SomeCommand; \& use MooseX::App::Command; # important (also imports Moose) \& extends qw(MyApp); # optional, only if you want to use global options from base class \& \& # Positional parameter \& parameter \*(Aqsome_parameter\*(Aq => ( \& is => \*(Aqrw\*(Aq, \& isa => \*(AqStr\*(Aq, \& required => 1, \& documentation => q[Some parameter that you need to supply], \& ); \& \& option \*(Aqsome_option\*(Aq => ( \& is => \*(Aqrw\*(Aq, \& isa => \*(AqInt\*(Aq, \& required => 1, \& documentation => q[Very important option!], \& ); # Option \& \& sub run { \& my ($self) = @_; \& # Do something \& } .Ve .PP And then you need a simple wrapper script (called eg. myapp): .PP .Vb 3 \& #!/usr/bin/env perl \& use MyApp; \& MyApp\->new_with_command\->run; .Ve .PP On the command line: .PP .Vb 4 \& bash$ myapp help \& usage: \& myapp [long options...] \& myapp help \& \& global options: \& \-\-global_option Enable this to do fancy stuff [Flag] \& \-\-help \-\-usage \-? Prints this usage information. [Flag] \& \& available commands: \& some_command Description of some command \& another_command Description of another command \& help Prints this usage information .Ve .PP or .PP .Vb 5 \& bash$ myapp some_command \-\-help \& usage: \& myapp some_command [long options...] \& myapp help \& myapp some_command \-\-help \& \& parameters: \& some_parameter Some parameter that you need to supply [Required] \& \& options: \& \-\-global_option Enable this to do fancy stuff [Flag] \& \-\-some_option Very important option! [Int,Required] \& \-\-help \-\-usage \-? Prints this usage information. [Flag] .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" MooseX-App is a highly customisable helper to write user-friendly command line applications without having to worry about most of the annoying things usually involved. Just take any existing Moose class, add a single line (\f(CW\*(C`use MooseX\-App qw(PluginA PluginB ...);\*(C'\fR) and create one class for each command in an underlying namespace. Options and positional parameters can be defined as simple Moose accessors using the \f(CW\*(C`option\*(C'\fR and \&\f(CW\*(C`parameter\*(C'\fR keywords respectively. .PP MooseX-App will then .IP "\(bu" 4 Find, load and initialise the command classes (see MooseX::App::Simple for single class/command applications) .IP "\(bu" 4 Create automated help and documentation from modules \s-1POD\s0 as well as attributes metadata and type constraints .IP "\(bu" 4 Read, encode and validate the command line options and positional parameters entered by the user from \f(CW@ARGV\fR and \f(CW%ENV\fR (and possibly prompt the user for additional parameters see MooseX::App::Plugin::Term) .IP "\(bu" 4 Provide helpful error messages if user input cannot be validated (either missing or wrong attributes or Moose type constraints not satisfied) or if the user requests help. .PP Commandline options are defined using the 'option' keyword which accepts the same attributes as Moose' 'has' keyword. .PP .Vb 4 \& option \*(Aqsome_option\*(Aq => ( \& is => \*(Aqrw\*(Aq, \& isa => \*(AqStr\*(Aq, \& ); .Ve .PP This is equivalent to .PP .Vb 6 \& has \*(Aqsome_option\*(Aq => ( \& is => \*(Aqrw\*(Aq, \& isa => \*(AqStr\*(Aq, \& traits => [\*(AqAppOption\*(Aq], # Load extra metaclass \& cmd_type => \*(Aqoption\*(Aq, # Set attribute type \& ); .Ve .PP Single letter options are treated as flags and may be combined with eachother. However such options must have a Boolean type constraint. .PP .Vb 5 \& option \*(Aqverbose\*(Aq => ( \& is => \*(Aqrw\*(Aq, \& isa => \*(AqBool\*(Aq, \& cmd_flag => \*(Aqv\*(Aq, \& ); .Ve .PP Positional parameters are defined with the 'parameter' keyword .PP .Vb 4 \& parameter \*(Aqsome_option\*(Aq => ( \& is => \*(Aqrw\*(Aq, \& isa => \*(AqStr\*(Aq, \& ); .Ve .PP This is equivalent to .PP .Vb 6 \& has \*(Aqsome_option\*(Aq => ( \& is => \*(Aqrw\*(Aq, \& isa => \*(AqStr\*(Aq, \& traits => [\*(AqAppOption\*(Aq], \& cmd_type => \*(Aqparameter\*(Aq, \& ); .Ve .PP All keywords are imported by Moosex::App (in the app base class) and MooseX::App::Command (in the command class) or MooseX::App::Simple (single class application). .PP Furthermore, all options and parameters can also be supplied via \f(CW%ENV\fR .PP .Vb 5 \& option \*(Aqsome_option\*(Aq => ( \& is => \*(Aqrw\*(Aq, \& isa => \*(AqStr\*(Aq, \& cmd_env => \*(AqSOME_OPTION\*(Aq, # sets the env key \& ); .Ve .PP Moose type constraints help MooseX::App to construct helpful error messages and parse \f(CW@ARGV\fR in a meaningful way. The following type constraints are supported: .IP "\(bu" 4 ArrayRef: Specify multiple values ('\-\-opt value1 \-\-opt value2', also see app_permute and cmd_split) .IP "\(bu" 4 HashRef: Specify multiple key value pairs ('\-\-opt key=value \-\-opt key2=value2', also see app_permute) .IP "\(bu" 4 Enum: Display all possibilities .IP "\(bu" 4 Bool: Flags that do not require values .IP "\(bu" 4 Int, Num: Used for proper error messages .PP Read the Tutorial for getting started with a simple MooseX::App command line application. .SH "METHODS" .IX Header "METHODS" .SS "new_with_command" .IX Subsection "new_with_command" .Vb 1 \& my $myapp_command = MyApp\->new_with_command(); .Ve .PP This constructor reads the command line arguments and tries to create a command class instance. If it fails it returns a MooseX::App::Message::Envelope object holding an error message. .PP You can pass a hash of default/fallback params to new_with_command .PP .Vb 1 \& my $obj = MyApp\->new_with_command(%default); .Ve .PP Optionally you can pass a custom \s-1ARGV\s0 to this constructor .PP .Vb 1 \& my $obj = MyApp\->new_with_command( ARGV => \e@myARGV ); .Ve .PP However, if you do so you must take care of propper \f(CW@ARGV\fR encoding yourself. .SS "initialize_command_class" .IX Subsection "initialize_command_class" .Vb 1 \& my $obj = MyApp\->initialize_command_class($command_name,%default); .Ve .PP Helper method to instantiate the command class for the given command. .SH "GLOBAL OPTIONS" .IX Header "GLOBAL OPTIONS" These options may be used to alter the default behaviour of MooseX-App. .SS "app_base" .IX Subsection "app_base" .Vb 1 \& app_base \*(Aqmy_script\*(Aq; # Defaults to $0 .Ve .PP Usually MooseX::App will take the name of the calling wrapper script to construct the program name in various help messages. This name can be changed via the app_base function. .SS "app_fuzzy" .IX Subsection "app_fuzzy" .Vb 3 \& app_fuzzy 1; # default \& OR \& app_fuzzy 0; .Ve .PP Enables fuzzy matching of commands and attributes. Is turned on by default. .SS "app_strict" .IX Subsection "app_strict" .Vb 3 \& app_strict 0; # default \& OR \& app_strict 1; .Ve .PP If strict is enabled the program will terminate with an error message if superfluous/unknown positional parameters are supplied. If disabled all extra parameters will be copied to the extra_argv attribute. Unknown options (with leading dashes) will always yield an error message. .PP The command_strict config in the command classes allows one to set this option individually for each command in the respective command class. .SS "app_prefer_commandline" .IX Subsection "app_prefer_commandline" .Vb 3 \& app_prefer_commandline 0; # default \& or \& app_prefer_commandline 1; .Ve .PP Specifies if parameters/options supplied via \f(CW@ARGV\fR,%ENV should take precedence over arguments passed directly to new_with_command. .SS "app_namespace" .IX Subsection "app_namespace" .Vb 3 \& app_namespace \*(AqMyApp::Commands\*(Aq, \*(AqYourApp::MoreCommands\*(Aq; \& OR \& app_namespace(); .Ve .PP Usually MooseX::App will take the package name of the base class as the namespace for commands. This namespace can be changed and you can add multiple extra namespaces. .PP If app_namespace is called with no arguments then autoloading of command classes will be disabled entirely. .SS "app_exclude" .IX Subsection "app_exclude" .Vb 1 \& app_exclude \*(AqMyApp::Commands::Roles\*(Aq,\*(AqMyApp::Commands::Utils\*(Aq; .Ve .PP A sub namespace included via app_namespace (or the default behaviour) can be excluded using app_exclude. .SS "app_command_name" .IX Subsection "app_command_name" .Vb 5 \& app_command_name { \& my ($package_short,$package_full) = @_; \& # munge package name; \& return $command_name; \& }; .Ve .PP This coderef can be used to control how autoloaded package names should be translated to command names. If this command returns nothing the respective command class will be skipped and not loaded. .SS "app_command_register" .IX Subsection "app_command_register" .Vb 3 \& app_command_register \& do => \*(AqMyApp::Commands::DoSomething\*(Aq, \& undo => \*(AqMyApp::Commands::UndoSomething\*(Aq; .Ve .PP This keyword can be used to register additional commands. Especially useful in conjunction with app_namespace and disabled autoloading. .SS "app_description" .IX Subsection "app_description" .Vb 1 \& app_description qq[Description text]; .Ve .PP Set the app description text. If not set this information will be taken from the Pod \s-1DESCRIPTION\s0 or \s-1OVERVIEW\s0 sections. (see command_description to set usage per command) .SS "app_usage" .IX Subsection "app_usage" .Vb 1 \& app_usage qq[myapp \-\-option ...]; .Ve .PP Set a custom usage text. If not set this will be taken from the Pod \s-1SYNOPSIS\s0 or \s-1USAGE\s0 section. If both sections are not available, the usage information will be autogenerated. (see command_usage to set usage per command) .SS "app_permute" .IX Subsection "app_permute" .Vb 3 \& app_permute 0; # default \& OR \& app_permute 1; .Ve .PP Allows one to specify multiple values with one key. So instead of writing \&\f(CW\*(C`\-\-list element1 \-\-list element2 \-\-list element3\*(C'\fR one might write \&\f(CW\*(C`\-\-list element1 element2 element3\*(C'\fR for ArrayRef elements. HashRef elements may be expressed as <\-\-hash key=value key2=value2>. .SH "GLOBAL ATTRIBUTES" .IX Header "GLOBAL ATTRIBUTES" All MooseX::App classes will have two extra attributes .SS "extra_argv" .IX Subsection "extra_argv" Carries all parameters from \f(CW@ARGV\fR that were not consumed (only if app_strict is turned off, otherwise superfluous parameters will raise an exception). .SS "help_flag" .IX Subsection "help_flag" Help flag that is set when help was requested. .SH "ATTRIBUTE OPTIONS" .IX Header "ATTRIBUTE OPTIONS" Options and parameters accept extra attributes for customisation: .IP "\(bu" 4 cmd_tags \- Extra tags (as used by the help) .IP "\(bu" 4 cmd_flag \- Override option/parameter name .IP "\(bu" 4 cmd_aliases \- Additional option/parameter name aliases .IP "\(bu" 4 cmd_split \- Split values into ArrayRefs on this token .IP "\(bu" 4 cmd_position \- Specify option/parameter order in help .IP "\(bu" 4 cmd_env \- Read options/parameters from \f(CW%ENV\fR .IP "\(bu" 4 cmd_count \- Value of option equals to number of occurrences in \f(CW@ARGV\fR .IP "\(bu" 4 cmd_negate \- Adds an option to negate boolean flags .PP Refer to MooseX::App::Meta::Role::Attribute::Option for detailed documentation. .SH "METADATA" .IX Header "METADATA" MooseX::App will use your class metadata and \s-1POD\s0 to construct the commands and helpful error\- or usage-messages. These bits of information are utilised and should be provided if possible: .IP "\(bu" 4 Package names .IP "\(bu" 4 required options for Moose attributes .IP "\(bu" 4 documentation options for Moose attributes .IP "\(bu" 4 Moose type constraints (Bool, ArrayRef, HashRef, Int, Num, and Enum) .IP "\(bu" 4 Documentation set via app_description, app_usage, command_short_description, command_long_description and command_usage .IP "\(bu" 4 \&\s-1POD\s0 (\s-1NAME, ABSTRACT, DESCRIPTION, USAGE, SYNOPSIS, OVERVIEW, COPYRIGHT, LICENSE, COPYRIGHT AND LICENSE, AUTHOR\s0 and \s-1AUTHORS\s0 sections) .IP "\(bu" 4 Dzil \s-1ABSTRACT\s0 tag if no \s-1POD\s0 is available yet .SH "PLUGINS" .IX Header "PLUGINS" The behaviour of MooseX-App can be customised with plugins. To load a plugin just pass a list of plugin names after the \f(CW\*(C`use MooseX\-App\*(C'\fR statement. (Attention: order sometimes matters) .PP .Vb 1 \& use MooseX::App qw(PluginA PluginB); .Ve .PP Currently the following plugins are shipped with MooseX::App .IP "\(bu" 4 MooseX::App::Plugin::BashCompletion .Sp Adds a command that generates a bash completion script for your application. See third party MooseX::App::Plugin::ZshCompletion for Z shell completion. .IP "\(bu" 4 MooseX::App::Plugin::Color .Sp Colorful output for your MooseX::App applications. .IP "\(bu" 4 MooseX::App::Plugin::Config .Sp Config files for MooseX::App applications. .IP "\(bu" 4 MooseX::App::Plugin::ConfigHome .Sp Try to find config files in users home directory. .IP "\(bu" 4 MooseX::App::Plugin::Term .Sp Prompt user for options and parameters that were not provided via options or params. Prompt offers basic editing capabilities and non-persistent history. .IP "\(bu" 4 MooseX::App::Plugin::Typo .Sp Handle typos in command names and provide suggestions. .IP "\(bu" 4 MooseX::App::Plugin::Version .Sp Adds a command to display the version and license of your application. .IP "\(bu" 4 MooseX::App::Plugin::Man .Sp Display full manpage of application and commands. .IP "\(bu" 4 MooseX::App::Plugin::MutexGroup .Sp Allow for mutally exclusive options. .IP "\(bu" 4 MooseX::App::Plugin::Depends .Sp Adds dependent options. .PP Refer to Writing MooseX-App Plugins for documentation on how to create your own plugins. .SH "CAVEATS & KNOWN BUGS" .IX Header "CAVEATS & KNOWN BUGS" Startup time may be an issue \- escpecially if you load many plugins. If you do not require the functionality of plugins and ability for fine grained customisation (or Moose for that matter) then you should probably use MooX::Options or MooX::Cmd. .PP In some cases \- especially when using non-standard class inheritance \- you may end up with command classes lacking the help attribute. In this case you need to include the following line in your base class or command classes. .PP .Vb 1 \& with qw(MooseX::App::Role::Common); .Ve .PP When manually registering command classes (eg. via app_command_register) in multiple base classes with different sets of plugins (why would you ever want to do that?), then meta attributes may lack some attribute metaclasses. In this case you need to load the missing attribute traits explicitly: .PP .Vb 4 \& option \*(Aqargument\*(Aq => ( \& depends => \*(Aqotherargument\*(Aq, \& trait => [\*(AqMooseX::App::Plugin::Depends::Meta::Attribute\*(Aq], # load trait \& ); .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Read the Tutorial for getting started with a simple MooseX::App command line application. .PP For alternatives you can check out .PP MooseX::App::Cmd, MooseX::Getopt, MooX::Options, MooX::Cmdand App::Cmd .SH "SUPPORT" .IX Header "SUPPORT" Please report any bugs or feature requests via . I will be notified, and then you'll automatically be notified of progress on your report as I make changes. .SH "AUTHOR" .IX Header "AUTHOR" .Vb 3 \& Maroš Kollár \& CPAN ID: MAROS \& maros [at] k\-1.com \& \& http://www.k\-1.com .Ve .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" Special thanks to all contributors. .PP In no particular order: Andrew Jones, George Hartzell, Steve Nolte, Michael G, Thomas Klausner, Yanick Champoux, Edward Baudrez, David Golden, J.R. Mash, Thilo Fester, Gregor Herrmann, Sergey Romanov, Sawyer X, Roman F., Hunter McMillen, Maik Hentsche, Alexander Stoddard, Marc Logghe, Tina Müller, Lisa Hare, Jose Luis Martinez .PP You are more than welcome to contribute to MooseX-App. Please have a look at the list of open wishlist issues for ideas. .SH "COPYRIGHT" .IX Header "COPYRIGHT" MooseX::App is Copyright (c) 2012\-17 Maroš Kollár. .PP This library is free software and may be distributed under the same terms as perl itself. The full text of the licence can be found in the \s-1LICENCE\s0 file included with this module.