Shipwright::Script - Base class and dispatcher for commands


Shipwright documentation  | view source Contained in the Shipwright distribution.

Index


alias =cut

sub alias { return ( ls => 'list', del => 'delete', up => 'update', init => 'create', initialize => 'create', ); }

global_options

prepare =cut

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;
}

log =cut

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__

NAME

Top

Shipwright::Script - Base class and dispatcher for commands

AUTHOR

Top

sunnavy <sunnavy@bestpractical.com>

LICENCE AND COPYRIGHT

Top


Shipwright documentation  | view source Contained in the Shipwright distribution.