Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 28, 2012
@theory Remove ouput methods from Command.
Delegate them to the sqitch object.
cac8de4
@theory No need to create command to call help.
Just call it right on the sqitch object, instead.
d2e9bae
Showing with 39 additions and 90 deletions.
  1. +10 −7 lib/App/Sqitch.pm
  2. +29 −83 lib/App/Sqitch/Command.pm
View
17 lib/App/Sqitch.pm
@@ -392,7 +392,7 @@ configuration files.
$sqitch->trace('About to fuzzle the wuzzle.');
Send trace information to C<STDOUT> if the verbosity level is 3 or higher.
-Trace messages will have C<TRACE: > prefixed to every line. If it's lower than
+Trace messages will have C<trace: > prefixed to every line. If it's lower than
3, nothing will be output.
=head3 C<debug>
@@ -400,7 +400,7 @@ Trace messages will have C<TRACE: > prefixed to every line. If it's lower than
$sqitch->debug('Found snuggle in the crib.');
Send debug information to C<STDOUT> if the verbosity level is 2 or higher.
-Debug messages will have C<DEBUG: > prefixed to every line. If it's lower than
+Debug messages will have C<debug: > prefixed to every line. If it's lower than
2, nothing will be output.
=head3 C<info>
@@ -431,8 +431,9 @@ C<sqitch config --get core.editor>.
$sqitch->warn('Could not find nerble; using nobble instead.');
-Send a warning messages to C<STDERR>. Use if something unexpected happened but
-you can recover from it.
+Send a warning messages to C<STDERR>. Warnings will have C<warning: > prefixed
+to every line. Use if something unexpected happened but you can recover from
+it.
=head3 C<unfound>
@@ -445,15 +446,17 @@ such as when something requested was not found.
$sqitch->fail('File or directory "foo" not found.');
-Send a failure message to C<STDERR> and exit with status code 2. Use if
-something unexpected happened and you cannot recover from it.
+Send a failure message to C<STDERR> and exit with status code 2. Failures will
+have C<fatal: > prefixed to every line. Use if something unexpected happened
+and you cannot recover from it.
=head3 C<help>
$sqitch->help('"foo" is not a valid command.');
Sends messages to C<STDERR> and exists with an additional message to "See
-sqitch --help". Use if the user has misused the app.
+sqitch --help". Help messages will have C<sqitch: > prefixed to every line.
+Use if the user has misused the app.
=head3 C<bail>
View
112 lib/App/Sqitch/Command.pm
@@ -11,7 +11,24 @@ use Moose;
our $VERSION = '0.12';
-has sqitch => (is => 'ro', isa => 'App::Sqitch', required => 1);
+has sqitch => (
+ is => 'ro',
+ isa => 'App::Sqitch',
+ required => 1,
+ handles => [qw(
+ verbosity
+ trace
+ debug
+ info
+ comment
+ emit
+ warn
+ unfound
+ fail
+ help
+ bail
+ )],
+);
sub command {
my $class = ref $_[0] || shift;
@@ -36,9 +53,7 @@ sub load {
die $_ unless /^Can't locate/;
# Suggest help if it's not a valid command.
- __PACKAGE__->new({ sqitch => $p->{sqitch} })->help(
- qq{"$p->{command}" is not a valid command.}
- );
+ $p->{sqitch}->help(qq{"$p->{command}" is not a valid command.});
};
# Merge the command-line options and configuration parameters
@@ -67,10 +82,6 @@ sub configure {
);
}
-sub verbosity {
- shift->sqitch->verbosity;
-}
-
sub options {
return;
}
@@ -113,13 +124,6 @@ sub _pod2usage {
);
}
-sub _prepend {
- my $prefix = shift;
- my $msg = join '', map { $_ // '' } @_;
- $msg =~ s/^/$prefix /gms;
- return $msg;
-}
-
sub execute {
my $self = shift;
croak(
@@ -145,53 +149,6 @@ sub do_system {
return !$status;
}
-sub trace {
- my $self = shift;
- say _prepend 'trace:', @_ if $self->verbosity > 2
-}
-
-sub debug {
- my $self = shift;
- say _prepend 'debug:', @_ if $self->verbosity > 1
-}
-
-sub info {
- my $self = shift;
- say @_ if $self->verbosity;
-}
-
-sub comment {
- my $self = shift;
- say _prepend '#', @_ if $self->verbosity;
-}
-
-sub emit {
- shift;
- say @_;
-}
-
-sub warn {
- my $self = shift;
- say STDERR _prepend 'warning:', @_;
-}
-
-sub unfound {
- exit 1;
-}
-
-sub fail {
- my $self = shift;
- say STDERR _prepend 'fatal:', @_;
- exit 2;
-}
-
-sub help {
- my $self = shift;
- my $bn = _bn;
- say STDERR _prepend("$bn:", @_), " See $bn --help";
- exit 1;
-}
-
sub usage {
my $self = shift;
require Pod::Find;
@@ -202,18 +159,6 @@ sub usage {
);
}
-sub bail {
- my ($self, $code) = (shift, shift);
- if (@_) {
- if ($code) {
- say STDERR @_;
- } else {
- say STDOUT @_;
- }
- }
- exit $code;
-}
-
__PACKAGE__->meta->make_immutable;
no Moose;
@@ -370,10 +315,8 @@ Returns the verbosity level.
=head3 C<trace>
- $cmd->trace('About to fuzzle the wuzzle.');
-
Send trace information to C<STDOUT> if the verbosity level is 3 or higher.
-Trace messages will have C<TRACE: > prefixed to every line. If it's lower than
+Trace messages will have C<trace: > prefixed to every line. If it's lower than
3, nothing will be output.
=head3 C<debug>
@@ -381,7 +324,7 @@ Trace messages will have C<TRACE: > prefixed to every line. If it's lower than
$cmd->debug('Found snuggle in the crib.');
Send debug information to C<STDOUT> if the verbosity level is 2 or higher.
-Debug messages will have C<DEBUG: > prefixed to every line. If it's lower than
+Debug messages will have C<debug: > prefixed to every line. If it's lower than
2, nothing will be output.
=head3 C<info>
@@ -412,8 +355,9 @@ C<sqitch config --get core.editor>.
$cmd->warn('Could not find nerble; using nobble instead.');
-Send a warning messages to C<STDERR>. Use if something unexpected happened but
-you can recover from it.
+Send a warning messages to C<STDERR>. Warnings will have C<warning: > prefixed
+to every line. Use if something unexpected happened but you can recover from
+it.
=head3 C<unfound>
@@ -426,8 +370,9 @@ such as when something requested was not found.
$cmd->fail('File or directory "foo" not found.');
-Send a failure message to C<STDERR> and exit with status code 2. Use if
-something unexpected happened and you cannot recover from it.
+Send a failure message to C<STDERR> and exit with status code 2. Failures will
+have C<fatal: > prefixed to every line. Use if something unexpected happened
+and you cannot recover from it.
=head3 C<usage>
@@ -442,7 +387,8 @@ or "Options". Any or all of those will be shown.
$cmd->help('"foo" is not a valid command.');
Sends messages to C<STDERR> and exists with an additional message to "See
-sqitch --help". Use if the user has misused the app.
+sqitch --help". Help messages will have C<sqitch: > prefixed to every line.
+Use if the user has misused the app.
=head3 C<bail>

No commit comments for this range

Something went wrong with that request. Please try again.