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);
$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;
$opt_string => $doc,
{
( $is_required ? ( required => $attr->is_required ) : () ),
- }
+ },
];
};
};
eval {
- ($options, $usage) = Getopt::Long::Descriptive::describe_options(
+ ($new_options, $usage) = Getopt::Long::Descriptive::describe_options(
$self->format, @opts, { getopt_conf => [ $self->config ] }
);
};
};
# 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;
};