NAME

App::Cmd - write command line apps with less suffering

VERSION

version 0.001

$Id: /my/cs/projects/app-cmd/trunk/lib/App/Cmd.pm 22432 2006-06-13T01:56:37.727054Z rjbs  $

SYNOPSIS

in yourcmd:

use YourApp::Cmd;

Your::Cmd->new->run;

in YourApp/Cmd.pm:

package YourApp::Cmd;
use base qw(App::Cmd);
1;

in YourApp/Cmd/Command/blort.pm:

package YourApp::Cmd::Command::blort;
use strict; use warnings;

sub opt_spec {
  return (
    [ "blortex|X",  "use the blortex algorithm" ],
    [ "recheck|r",  "recheck all results"       ],
  );
}

sub validate_args {
  my ($self, $opt, $args) = @_;

  # no args allowed but options!
  die $self->usage->text if @$args;
}

sub run {
  my ($self, $opt, $args) = @_;

  my $result = $opt->{blortex} ? blortex() : blort();

  recheck($result) if $opt->{recheck};

  print $result;
}

and, finally, at the command line:

knight!rjbs$ yourcmd blort --recheck

All blorts successful.

DESCRIPTION

App::Cmd is intended to make it easy to write complex command-line applications without having to think about most of the annoying things usually involved.

For information on how to start using App::Cmd, see App::Cmd::Tutorial.

METHODS

new

my $cmd = App::Cmd->new(\%arg);

This method returns a new App::Cmd object. During initialization, command plugins will be loaded.

Valid arguments are:

no_commands_plugin - if true, the command list plugin is not added

If no_commands_plugin is not given, App::Cmd::Command::commands will be required, and it will be registered to handle all of its command names not handled by other plugins.

command_names

my @names = $cmd->command_names;

This returns the commands names which the App::Cmd object will handle.

command_plugins

my @plugins = $cmd->command_plugins;

This

plugin_for

my $plugin = $cmd->plugin_for($command);

This method requires and returns the plugin (module) for the given command. If no plugin implements the command, it returns false.

run

$cmd->run;

This method runs the application. If called the class, it will instantiate a new App::Cmd object to run.

It determines the requested command (generally by consuming the first command-line argument), finds the plugin to handle that command, parses the remaining arguments according to that plugin's rules, and runs the plugin.

TODO

Lots of stuff! This list isn't close to complete yet, I'm still adding to it.

  • improve the tutorial

  • publish and bring in Log::Speak (simple quiet/verbose output)

  • publish and use our internal enhanced describe_options

  • publish and use our improved simple input routines

  • publish and use our remaining little CLI tools

  • make it simple to write a command with no subcommands

AUTHOR AND COPYRIGHT

Copyright 2005-2006, (code (simply)). All rights reserved; App::Cmd and bundled code are free software, released under the same terms as perl itself.

App:Cmd was originally written as Rubric::CLI by Ricardo SIGNES in 2005. It was refactored extensively by Ricardo SIGNES and John Capiello and released as App::Cmd in 2006.