* MooseX::Getopt: _get_options_from_configfile renamed to get_options_from_configfile.
[gitmo/MooseX-Getopt.git] / lib / MooseX / Getopt / Parser / Descriptive.pm
index c60839c..c212eb1 100644 (file)
@@ -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;
 };