public
Description:
Homepage:
Clone URL: git://github.com/robertkrimen/Getopt-Chain.git
Getopt-Chain / README
100644 169 lines (112 sloc) 4.761 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
NAME
    Getopt::Chain - Command-line processing like svn and git
 
VERSION
    Version 0.016
 
SYNPOSIS
        package My::Command;
 
        use Getopt::Chain::Declare;
 
        start [qw/ verbose|v /]; # These are "global"
                                 # my-command --verbose initialize ...
 
        # my-command ? initialize ... --> my-command help initialize ...
        rewrite qr/^\?(.*)/ => sub { "help ".($1||'') };
 
        # NOTE: Rewriting applies to the command sequence, NOT options
 
        # my-command about ... --> my-command help about
        rewrite [ ['about', 'copying'] ] => sub { "help $1" };
 
        # my-command initialize --dir=...
        on initialize => [qw/ dir|d=s /], sub {
            my $context = shift;
 
            my $dir = $context->option( 'dir' )
 
            # Do initialize stuff with $dir
        };
 
        # my-command help
        on help => undef, sub {
            my $context = shift;
 
            # Do help stuff ...
            # First argument is undef because help
            # doesn't take any options
        };
 
        under help => sub {
 
            # my-command help create
            # my-command help initialize
            on [ [ qw/create initialize/ ] ] => undef, sub {
                my $context = shift;
 
                # Do help for create/initialize
                # Both: "help create" and "help initialize" go here
            };
 
            # my-command help about
            on 'about' => undef, sub {
                my $context = shift;
 
                # Help for about...
            };
 
            # my-command help copying
            on 'copying' => undef, sub {
                my $context = shift;
 
                # Help for copying...
            };
 
            # my-command help ...
            on qr/^(\S+)$/ => undef, sub {
               my $context = shift;
               my $topic = $1;
 
               # Catch-all for anything not fitting into the above...
 
               warn "I don't know about \"$topic\"\n"
            };
        };
 
        # ... elsewhere ...
 
        My::Command->new->run( [ @arguments ] )
        My::Command->new->run # Just run with @ARGV
 
DESCRIPTION
    Getopt::Chain can be used to provide svn(1)- and git(1)-style option and
    command processing. Any option specification covered by Getopt::Long is
    fair game.
 
    This is a new version of Getopt::Chain that uses Path::Dispatcher
 
    CAVEAT 1: This is pretty beta, so the sugar/interface above WILL be
    tweaked
 
    CAVEAT 2: Unfortunately, Getopt::Long slurps up the entire arguments
    array at once. Usually, this isn't a problem (as Getopt::Chain uses
    pass_through). However, if a subcommand has an option with the same name
    or alias as an option for a parent, then that option won't be available
    for the subcommand. For example:
 
        ./script --verbose --revision 36 edit --revision 48 --file xyzzy.c
        # Getopt::Chain will not associate the second --revision with "edit"
 
    So, for now, try to use distinct option names/aliases :)
 
    DEBUG: You can get some extra information about what Getopt::Chain is
    doing by setting the environment variable "GOC_TRACE" to 1
 
LEGACY
    The old-style, non Path::Dispatcher version is still available at
    Getopt::Chain::v005
 
SEE ALSO
    Getopt::Long
 
    App::Cmd
 
    MooseX::App::Cmd
 
ACKNOWLEDGEMENTS
    Sartak for Path::Dispatcher
 
    obra for inspiration on the CLI (via Prophet & Sd:
    <http://syncwith.us/>)
 
AUTHOR
    Robert Krimen, "<rkrimen at cpan.org>"
 
SOURCE
    You can contribute or fork this project via GitHub:
 
    <http://github.com/robertkrimen/Getopt-Chain/tree/master>
 
        git clone git://github.com/robertkrimen/Getopt-Chain.git Getopt-Chain
 
BUGS
    Please report any bugs or feature requests to "bug-Getopt-Chain at
    rt.cpan.org", or through the web interface at
    <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Getopt-Chain>. I will be
    notified, and then you'll automatically be notified of progress on your
    bug as I make changes.
 
SUPPORT
    You can find documentation for this module with the perldoc command.
 
        perldoc Getopt::Chain
 
    You can also look for information at:
 
    * RT: CPAN's request tracker
 
        <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Getopt-Chain>
 
    * AnnoCPAN: Annotated CPAN documentation
 
        <http://annocpan.org/dist/Getopt-Chain>
 
    * CPAN Ratings
 
        <http://cpanratings.perl.org/d/Getopt-Chain>
 
    * Search CPAN
 
        <http://search.cpan.org/dist/Getopt-Chain>
 
COPYRIGHT & LICENSE
    Copyright 2008 Robert Krimen, all rights reserved.
 
    This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.