| SweetPea-Cli documentation | Contained in the SweetPea-Cli distribution. |
SweetPea::Cli - Rapid Application Development for SweetPea Packages
Version 0.08
... from the command-line
sweetpea
or
perl -MSweetPea::Cli -e shell
SweetPea::Cli::Documentation
Al Newkirk, <al.newkirk at awnstudio.com>
Please report any bugs or feature requests to bug-SweetPea-Cli at rt.cpan.org, or through
the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SweetPea-Cli. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
You can find documentation for this module with the perldoc command.
perldoc SweetPea::Cli
You can also look for information at:
Al Newkirk <al.newkirk@awnstudio.com>
Copyright 2009 Al Newkirk, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| SweetPea-Cli documentation | Contained in the SweetPea-Cli distribution. |
package SweetPea::Cli; use 5.006; use warnings; use strict; use App::Rad; use SweetPea::Application 0.022; use SweetPea::Cli::Util; use SweetPea::Cli::Make; use SweetPea::Cli::Data; use SweetPea::Cli::Help; use SweetPea::Cli::Tool; use SweetPea::Cli::Mvc; BEGIN { use Exporter(); use vars qw( @ISA @EXPORT @EXPORT_OK ); @ISA = qw( Exporter ); @EXPORT = qw(shell); }
our $VERSION = '0.08';
sub shell { App::Rad->shell({ title => [<DATA>], prompt => 'sweetpea:', autocomp => 1, abbrev => 1, ignorecase => 0, history => 1, # or 'path/to/histfile.txt' }); } sub main::setup { my $c = shift; $c->stash->{commands} = $c->{_commands}; my $m = [ { name => 'help', code => sub { my $c = shift; my $u = SweetPea::Cli::Util->new; my $h = SweetPea::Cli::Help->new; # display help document for a specific function if (defined $c->argv->[0]) { if (defined $c->{_commands}->{$c->argv->[0]}) { return $h->display($c->argv->[0], $c); } } return $u->template('menus/commands.tt', $c); }, help => 'display available commands.' }, { name => 'menu', code => sub { my $c = shift; my $u = SweetPea::Cli::Util->new; return $u->template('menus/master.tt', $c); }, help => 'display main menu.' }, ]; $c->register( $_->{name}, $_->{code}, $_->{help} ) foreach @{$m}; # register make commands foreach my $cmd ( @{SweetPea::Cli::Make->new($c)->{commands}} ) { my $n = $c->register($cmd->{name}, $cmd->{code}, $cmd->{help}); $c->{_commands}->{$n}->{args} = $cmd->{args}; } # register data commands foreach my $cmd ( @{SweetPea::Cli::Data->new($c)->{commands}} ) { my $n = $c->register($cmd->{name}, $cmd->{code}, $cmd->{help}); $c->{_commands}->{$n}->{args} = $cmd->{args}; } # register toolbox commands #foreach my $cmd ( @{SweetPea::Cli::Tool->new($c)->{commands}} ) { # my $n = $c->register($cmd->{name}, $cmd->{code}, $cmd->{help}); # $c->{_commands}->{$n}->{args} = $cmd->{args}; #} # register MVC commands foreach my $cmd ( @{SweetPea::Cli::Mvc->new($c)->{commands}} ) { my $n = $c->register($cmd->{name}, $cmd->{code}, $cmd->{help}); $c->{_commands}->{$n}->{args} = $cmd->{args}; } $c->{'_functions'}->{'invalid'} = sub { my $c = shift; my $u = SweetPea::Cli::Util->new; return $u->template('misc/error_string.tt', $c); }; } sub main::pre_process { my $c = shift; } #sub App::Rad::error { # my $c = shift; # my $e = shift; # # if ( $c->{state} eq "shell" ) { # my $u = SweetPea::Cli::Util->new; # $e =~ s/(^[\r\n]+|[\r\n]+$)//g; # $c->stash->{errors} = ["$e\n","\n"]; # return $u->template('misc/error_string.tt', $c); # } # else { # Carp::croak "$e----\n"; # } #}
1; # End of SweetPea::Cli __DATA__ Welcome to the SweetPea interactive development interface. *** Please type menu; to get started! ***