X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FGetopt%2FParser%2FDescriptive.pm;fp=lib%2FMooseX%2FGetopt%2FParser%2FDescriptive.pm;h=c212eb18466bb32f95dcff7bd9c641ebcd41377b;hb=10ed52cb080cfbe757fdb2a4c7ceb463fba93e6c;hp=c60839cccac2f04459126cd49de1f7998aea92ea;hpb=d09046450c54b37640fed28a06a17b7d040ba81a;p=gitmo%2FMooseX-Getopt.git diff --git a/lib/MooseX/Getopt/Parser/Descriptive.pm b/lib/MooseX/Getopt/Parser/Descriptive.pm index c60839c..c212eb1 100644 --- a/lib/MooseX/Getopt/Parser/Descriptive.pm +++ b/lib/MooseX/Getopt/Parser/Descriptive.pm @@ -32,7 +32,9 @@ sub build_options { Moose->throw_error('First argument is not a MooseX::Getopt::Session') unless $getopt->isa('MooseX::Getopt::Session'); - my $options = {}; + my $options = $getopt->options; + my $new_options = {}; + my $usage; my (@opts, %cmd_flags_to_names); @@ -51,7 +53,7 @@ sub build_options { $doc = $attr->documentation if $attr->has_documentation; $doc = ' ' unless $doc; - my $is_required = !exists $getopt->params->{$name} + my $is_required = !exists $options->{$name} && $attr->is_required && !$attr->has_default && !$attr->has_builder; @@ -60,7 +62,7 @@ sub build_options { $opt_string => $doc, { ( $is_required ? ( required => $attr->is_required ) : () ), - } + }, ]; }; @@ -75,7 +77,7 @@ sub build_options { }; eval { - ($options, $usage) = Getopt::Long::Descriptive::describe_options( + ($new_options, $usage) = Getopt::Long::Descriptive::describe_options( $self->format, @opts, { getopt_conf => [ $self->config ] } ); }; @@ -87,13 +89,16 @@ sub build_options { }; # Convert cmd_flags back to names in options hashref - $options = { map { $cmd_flags_to_names{$_} => $options->{$_} } keys %$options }; + $new_options = { map { $cmd_flags_to_names{$_} => $new_options->{$_} } keys %$new_options }; + + # Include old options and usage object + $new_options = { usage => $usage, %$options, %$new_options }; - $getopt->options( $options ); + $getopt->options( $new_options ); die $warnings if $warnings; - return $options; + return $new_options; };