1 # This module is part of debbugs, and is released under the terms of
2 # the GPL version 3, or any later version (at your option). See the
3 # file README and COPYING for more information.
4 # Copyright 2017 by Don Armstrong <don@donarmstrong.com>.
6 package Debbugs::Command;
10 Debbugs::Command -- Handle multiple subcommand-style commands
27 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT);
28 use base qw(Exporter);
32 $DEBUG = 0 unless defined $DEBUG;
35 %EXPORT_TAGS = (commands => [qw(handle_main_arguments),
36 qw(handle_subcommand_arguments)
40 Exporter::export_ok_tags(keys %EXPORT_TAGS);
41 $EXPORT_TAGS{all} = [@EXPORT_OK];
45 use Getopt::Long qw(:config no_ignore_case);
47 =head1 Command processing (:commands)
49 Functions which parse arguments for commands (exportable with
54 =item handle_main_arguments(
58 sub handle_main_arguments {
59 my ($options,@args) = @_;
60 Getopt::Long::Configure('pass_through');
61 GetOptions($options,@args);
62 Getopt::Long::Configure('default');
68 sub handle_subcommand_arguments {
69 my ($argv,$args,$subopt) = @_;
71 Getopt::Long::GetOptionsFromArray($argv,
76 for my $arg (keys %{$args}) {
77 next unless $args->{$arg};
78 my $r_arg = $arg; # real argument name
79 $r_arg =~ s/[=\|].+//g;
80 if (not defined $subopt->{$r_arg}) {
81 push @usage_errors, "You must give a $r_arg option";
84 pod2usage(join("\n",@usage_errors)) if @usage_errors;
94 # indent-tabs-mode: nil
95 # cperl-indent-level: 4