cmdline_arg_parser 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/cmdline_arg_parser.rb +14 -0
- data/lib/cmdline_arg_parser/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb671292e8e79b6aa46a6a6f5227f87197fe9f1c
|
4
|
+
data.tar.gz: be7cf592633b383912c2460a18896cf87b8082a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65f276bbbcb35fbdd60f94be565643a881a8e5375061af09f1eff6af588b24ff7349b2bc682963acf0a2c70de43cefcbd6f1b5918fba1a942698251efb00676e
|
7
|
+
data.tar.gz: 23d6b3ae5d4d7612ef2c9b5b204eb97f172e4e5639f6560e67609adc836511700fc4b692b02e1dce058befc558c52b226f2d49555bcbfcd280bd36df680b39f4
|
data/lib/cmdline_arg_parser.rb
CHANGED
@@ -16,6 +16,8 @@ module CmdlineArgParser
|
|
16
16
|
def parse(argv)
|
17
17
|
parsed_args = ParsedArgs.new
|
18
18
|
|
19
|
+
argv = expand_shorthand_switches(argv)
|
20
|
+
|
19
21
|
@subcommands.each do |subcommand|
|
20
22
|
subcommand.try_parse(argv, parsed_args)
|
21
23
|
end
|
@@ -31,6 +33,18 @@ module CmdlineArgParser
|
|
31
33
|
ReadmeBuilder.new(parser: self, specifics: builder).build
|
32
34
|
end
|
33
35
|
|
36
|
+
private
|
37
|
+
|
38
|
+
def expand_shorthand_switches(argv)
|
39
|
+
argv.flat_map do |arg|
|
40
|
+
if arg =~ /^-[a-z]/
|
41
|
+
arg[1..-1].split("").map { |arg| "-#{arg}" }
|
42
|
+
else
|
43
|
+
arg
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
34
48
|
class Subcommand
|
35
49
|
def initialize(command, options: [], switches: [])
|
36
50
|
@command = command
|