| 1 | #!/usr/bin/perl | ||
| 2 | |||
| 3 | package Mail::Summary::Tools::CLI::Command; | ||
| 4 | use base qw/App::Cmd::Command/; | ||
| 5 | |||
| 6 | use strict; | ||
| 7 | use warnings; | ||
| 8 | |||
| 9 | sub opt_spec { | ||
| 10 | my ( $self, $app ) = @_; | ||
| 11 | |||
| 12 | my @options = $self->options; | ||
| 13 | |||
| 14 | foreach my $option ( @options ) { | ||
| 15 | my $opts = $option->[2] ||= {}; | ||
| 16 | my ($name) = ($option->[0] =~ /^(\w+)/); | ||
| 17 | if ( defined( my $default = $self->option_config( $app, $name ) ) ) { | ||
| 18 | $opts->{default} = $default; # clobber the default one with the user's value | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | unshift @options, $self->extra_options; | ||
| 23 | |||
| 24 | return @options; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub validate_args { | ||
| 28 | my ( $self, $opt, $args ) = @_; | ||
| 29 | print $self->_usage_text and exit if $opt->{help}; | ||
| 30 | $self->validate( $opt, $args ); | ||
| 31 | } | ||
| 32 | |||
| 33 | sub extra_options { | ||
| 34 | my ( $self, $app ) = @_; | ||
| 35 | [ help => 'This help screen' ]; | ||
| 36 | } | ||
| 37 | |||
| 38 | sub option_config { | ||
| 39 | my ( $self, $app, $option ) = @_; | ||
| 40 | my ( $cmd ) = $self->command_names; | ||
| 41 | ( $app->config || $app->app->config )->option_value( $cmd => $option ); | ||
| 42 | } | ||
| 43 | |||
| 44 | sub diag { | ||
| 45 | my ( $self, @message ) = @_; | ||
| 46 | return unless $self->app->global_options->{verbose}; | ||
| 47 | my $message = "@message"; | ||
| 48 | chomp $message; | ||
| 49 | warn "$message\n"; | ||
| 50 | } | ||
| 51 | |||
| 52 | __PACKAGE__; | ||
| 53 | |||
| 54 | __END__ |