| Shipwright documentation | view source | Contained in the Shipwright distribution. |
sub alias { return ( ls => 'list', del => 'delete', up => 'update', init => 'create', initialize => 'create', ); }
sub prepare { my $self = shift; $ARGV[0] = 'help' unless @ARGV;
if ( $ARGV[0] =~ /--?h(elp)?/i ) {
$ARGV[0] = 'help';
}
elsif ( $ARGV[0] =~ /^(-v|--version|version)$/ ) {
print( "This is Shipwright, version $Shipwright::VERSION" . "\n" );
exit 0;
}
my $action = $ARGV[0];
my $cmd = $self->SUPER::prepare(@_);
unless ( ref $cmd eq 'Shipwright::Script::Help' ) {
$cmd->repository( $ENV{SHIPWRIGHT_SHIPYARD} )
if !$cmd->repository && $ENV{SHIPWRIGHT_SHIPYARD};
$cmd->repository( $ENV{SHIPWRIGHT_REPOSITORY} )
if !$cmd->repository && $ENV{SHIPWRIGHT_REPOSITORY};
if ( $cmd->repository ) {
require Shipwright::Backend;
my $backend = Shipwright::Backend->new(
repository => $cmd->repository,
no_sync_local_dir => 1,
);
# this $shipwright object will do nothing, except for init logging
my $shipwright = Shipwright->new(
repository => $cmd->repository,
log_level => $cmd->log_level,
log_file => $cmd->log_file,
);
confess_or_die 'invalid repository: '
. $cmd->repository
unless $backend->check_repository(
action => $action,
$action eq 'create' ? ( force => $cmd->force ) : ()
);
}
else {
confess_or_die "need repository arg\n";
}
}
return $cmd;
}
sub log { my $self = shift;
# init logging is done in prepare, no need to init here, just returns logger
return Log::Log4perl->get_logger( ref $self );
}
1;
__END__
Shipwright::Script - Base class and dispatcher for commands
sunnavy <sunnavy@bestpractical.com>
Copyright 2007-2011 Best Practical Solutions.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Shipwright documentation | view source | Contained in the Shipwright distribution. |