• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

bin/H29-Nov-2018-63

lib/ARGV/H03-May-2022-27984

t/H29-Nov-2018-132112

ChangesH A D29-Nov-2018553 1716

LICENSEH A D29-Nov-201817.9 KiB380292

MANIFESTH A D29-Nov-2018261 1817

META.jsonH A D29-Nov-20181.2 KiB5149

META.ymlH A D29-Nov-2018715 2625

MakefileH A D29-Nov-2018358 129

Makefile.PLH A D29-Nov-20181.1 KiB5442

README.mdH A D29-Nov-20184.5 KiB176106

cpanfileH A D29-Nov-2018119 86

dist.iniH A D29-Nov-2018686 3927

README.md

1# NAME
2
3ARGV::Struct - Parse complex data structures passed in ARGV
4
5# SYNOPSIS
6
7    use ARGV::Struct;
8    my $struct = ARGV::Struct->new->parse;
9
10# DESCRIPTION
11
12Have you ever felt that you need something different than Getopt?
13
14Are you tired of shoehorning Getopt style arguments into your commandline scripts?
15
16Are you trying to express complex datastructures via command line?
17
18then ARGV::Struct is for you!
19
20It's designed so the users of your command line utilities won't hate you when things
21get complex.
22
23# THE PAIN
24
25I've had to use some command-line utilities that had to do creative stuff to transmit
26deeply nested arguments, or datastructure-like information. Here are some strategies that
27I've found over time:
28
29## Complex arguments codified as JSON
30
31JSON is horrible for the command line because you have to escape the quotes. It's a nightmare.
32
33    command --complex_arg "{\"key1\":\"value1\",\"key2\":\"value2\"}"
34
35## Arguments encoded via some custom scheme
36
37These schemes fail when you have to make values complex (lists, or other key/values)
38
39    command --complex_arg key1,value1:key2,value2
40
41## Repeating Getopt arguments
42
43Getopt friendly, but too verbose
44
45    command --key key1 --value value1 --key key1 --value value 2
46
47# THE DESIGN
48
49The design of this module is aimed at "playing well with the shell". The main purpose is
50to let the user transmit complex data structures, while staying compact enough for command line
51use.
52
53## Key/Value sets (objects)
54
55On the command line, the user can transmit sets of key/value pairs within curly brackets
56
57    command { K_V_PAIR1 K_V_PAIR2 }
58
59The shell is expected to do some work for us, so key/value pairs are separated by spaces
60
61Each key/value pair is expressed as
62
63    Key: Value
64
65The colon between Keys and values is optional, so
66
67    Key Value
68
69is the same as above
70
71If the value contains spaces, the user can surround the pair with the shell metacharacters
72
73    command { Key: " Value " }
74
75Values can also be objects:
76
77    command { Key: { Nested Key } }
78
79or lists
80
81    command { Key: [ 1 2 3 ] }
82
83If you want a key with a colon at the end, just repeat the colon:
84
85    Key:: Value
86
87## Lists
88
89    command [ VALUE1 VALUE2 ]
90
91Each value can be a simple scalar value, or an object or list
92
93    command [ { Name X } { Name Y } ]
94    command [ [ 1 2 3 ] [ 4 5 6 ] [ 7 8 9 ] ]
95    command [ "First Value" "Second Value" ]
96
97Values are never separated by commas to keep the syntax compact.
98The shell is expected to split the different elements into tokens, so
99the user is expected to use shell quotes to keep values together
100
101# METHODS
102
103## new(\[argv => ArrayRef\])
104
105Return an instance of the parser. If argv is not specified, @ARGV will be
106used.
107
108## parse
109
110return the parsed data structure
111
112# STATUS
113
114This module is quite experimental. I developed it while developing Paws (a
115Perl AWS SDK). It has a commandline utility that needs to recollect all the
116Attributes and Values for method calls, and lots of times, they get complex.
117Since trying to pass params with Getopt was getting ugly as hell, I decided
118that it would be better to do things in a different way, and eventually
119thought it could be an independent module.
120
121I'm publishing this module to get the idea out to the public so it can be worked
122on.
123
124Please bash the guts out of it. Break it and shake it till it falls apart.
125
126Contribute bugs and patches. All input is welcome.
127
128To help with the bashing, when you install this dist, you get a command line util
129called argvstruct. It will basically print a Data::Dumper of the structure generated
130by it's arguments
131
132    user@host:~$ argvstruct { Hello Guys How [ Are You { Doing Today } ] }
133    $VAR1 = {
134            'Hello' => 'Guys',
135            'How' => [
136                       'Are',
137                       'You',
138                       {
139                         'Doing' => 'Today'
140                       }
141                     ]
142          };
143
144#
145
146# TODO
147
148Try to combine with Getopt/MooseX::Getopt, so some parameters could be an ARGV::Struct. The
149rest would be parsed Getopt style.
150
151# CONTRIBUTE
152
153The source code and issues are on https://github.com/pplu/ARGV-Struct
154
155# THANKS
156
157Matt S. Trout for suggesting that ARGV::Struct syntax be JSONY compatible
158
159# AUTHOR
160
161    Jose Luis Martinez
162    CPAN ID: JLMARTIN
163    CAPSiDE
164    jlmartinez@capside.com
165    http://www.pplusdomain.net
166
167# COPYRIGHT
168
169Copyright (c) 2015 by Jose Luis Martinez Torres
170
171This program is free software; you can redistribute
172it and/or modify it under the same terms as Perl itself.
173
174The full text of the license can be found in the
175LICENSE file included with this module.
176