| 1 | package Enbld::App; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Getopt::Long; | ||
| 7 | |||
| 8 | sub new { | ||
| 9 | my $class = shift; | ||
| 10 | |||
| 11 | my $self = { | ||
| 12 | cmd => 'usage', | ||
| 13 | argv => [], | ||
| 14 | }; | ||
| 15 | |||
| 16 | return bless $self, $class; | ||
| 17 | } | ||
| 18 | |||
| 19 | sub parse_options { | ||
| 20 | my $self = shift; | ||
| 21 | |||
| 22 | local @ARGV; | ||
| 23 | push @ARGV, @_; | ||
| 24 | |||
| 25 | my $make_test; | ||
| 26 | my $force; | ||
| 27 | my $current; | ||
| 28 | |||
| 29 | Getopt::Long::Configure( "bundling" ); | ||
| 30 | Getopt::Long::GetOptions( | ||
| 31 | 'v|version' => sub { $self->{cmd} = 'version' }, | ||
| 32 | 'h|help' => sub { $self->{cmd} = 'help' }, | ||
| 33 | 't|test' => sub { $make_test++ }, | ||
| 34 | 'f|force' => sub { $force++ }, | ||
| 35 | 'c|current' => sub { $current++ }, | ||
| 36 | ); | ||
| 37 | |||
| 38 | if ( @ARGV ) { | ||
| 39 | $self->{cmd} = shift @ARGV; | ||
| 40 | $self->{argv} = \@ARGV; | ||
| 41 | } | ||
| 42 | |||
| 43 | require Enbld::Feature; | ||
| 44 | Enbld::Feature->initialize( | ||
| 45 | make_test => $make_test, | ||
| 46 | force => $force, | ||
| 47 | current => $current, | ||
| 48 | ); | ||
| 49 | |||
| 50 | return $self; | ||
| 51 | } | ||
| 52 | |||
| 53 | sub envbuild { | ||
| 54 | my $self = shift; | ||
| 55 | |||
| 56 | require Enbld::Message; | ||
| 57 | Enbld::Message->set_verbose; | ||
| 58 | |||
| 59 | require Enbld::Command; | ||
| 60 | my $cmd = Enbld::Command->new( | ||
| 61 | cmd => $self->{cmd}, | ||
| 62 | argv => $self->{argv}, | ||
| 63 | ); | ||
| 64 | |||
| 65 | $cmd->do; | ||
| 66 | } | ||
| 67 | |||
| 68 | 1; |