miniparse 0.3.0 → 0.3.1
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/examples/ex02_options.rb +6 -2
- data/examples/ex08_app_simple.rb +21 -0
- data/lib/miniparse/app.rb +7 -4
- data/lib/miniparse/option_broker.rb +3 -3
- data/lib/miniparse/parser.rb +6 -6
- data/lib/miniparse/version.rb +1 -1
- data/miniparse.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fb31188afaf39cf89e8fdf5dfdc46b75dfe97017
|
|
4
|
+
data.tar.gz: 7544b57ab5bd3e29a7e4b9d8ecfbaec360bfe654
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d2c3f7f297e25205d8c8e227ba62192aa104b1f85df79439d178e0751b617b042f286ee04348fa46e00ba8b04c2a5276bfd536a19277c87fb7c9d2923c2b2de4
|
|
7
|
+
data.tar.gz: 85f6fe46c54f8026d96d4c4edb11289fe39bd7e2c0f13481d88a438c3f9fd4fdc8f00f1ddb279ac8c39848535d961280b82062eea5e72c77400d6356b605bc50
|
data/examples/ex02_options.rb
CHANGED
|
@@ -2,9 +2,13 @@ require 'miniparse'
|
|
|
2
2
|
|
|
3
3
|
parser = Miniparse::Parser.new
|
|
4
4
|
|
|
5
|
-
parser.add_option("--sort", "always sort the output",
|
|
6
|
-
|
|
5
|
+
parser.add_option("--sort", "always sort the output",
|
|
6
|
+
shortable: true)
|
|
7
7
|
|
|
8
|
+
# a negatable option can be specified as '--option' or '--no-option'
|
|
9
|
+
parser.add_option("--pill", "just a silly option",
|
|
10
|
+
shortable: true, negatable: true)
|
|
11
|
+
|
|
8
12
|
# if description is nil, then the option won't appear in the help description, only in the usage string
|
|
9
13
|
parser.add_option("--debug", nil)
|
|
10
14
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "miniparse/app"
|
|
2
|
+
|
|
3
|
+
# the help introduction can be omitted
|
|
4
|
+
App.configure_parser("my program help introduction\n") do |parser|
|
|
5
|
+
Miniparse.set_control(
|
|
6
|
+
autoshortable: true,
|
|
7
|
+
)
|
|
8
|
+
parser.add_option("--list", "list something")
|
|
9
|
+
parser.parse ARGV
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# to see App.debug you have to specify the --debug option
|
|
13
|
+
# for example: 'ruby ex08_app_simple.rb --debug'
|
|
14
|
+
App.debug App.options # to stdout
|
|
15
|
+
App.info App.options # to stdout
|
|
16
|
+
App.warn App.options # to stderr
|
|
17
|
+
App.error App.options # to stderr (note: it doesn't exit)
|
|
18
|
+
|
|
19
|
+
puts "parser object: #{App.parser}"
|
|
20
|
+
|
|
21
|
+
puts 'Done.'
|
data/lib/miniparse/app.rb
CHANGED
|
@@ -8,6 +8,7 @@ module App
|
|
|
8
8
|
|
|
9
9
|
@parser = nil
|
|
10
10
|
@do_configure_parser = lambda { |parser| parser.parse ARGV }
|
|
11
|
+
@program_desc = nil
|
|
11
12
|
|
|
12
13
|
def self.error(msg)
|
|
13
14
|
$stderr.puts "error: #{msg}"
|
|
@@ -29,21 +30,23 @@ module App
|
|
|
29
30
|
parser.options
|
|
30
31
|
end
|
|
31
32
|
|
|
32
|
-
def self.configure_parser(
|
|
33
|
+
def self.configure_parser(program_description = nil,&block)
|
|
33
34
|
reset_parser
|
|
34
|
-
@
|
|
35
|
+
@program_desc = program_description
|
|
36
|
+
@do_configure_parser = block
|
|
37
|
+
nil
|
|
35
38
|
end
|
|
36
39
|
|
|
37
40
|
# lazy parser creation
|
|
38
41
|
def self.parser
|
|
39
42
|
return @parser if @parser
|
|
40
|
-
@parser = Miniparse::Parser.new
|
|
43
|
+
@parser = Miniparse::Parser.new(@program_desc)
|
|
41
44
|
parser.add_option("--debug", nil, negatable: false)
|
|
42
45
|
@do_configure_parser.call(parser)
|
|
43
46
|
parser
|
|
44
47
|
end
|
|
45
48
|
|
|
46
|
-
#
|
|
49
|
+
# re-initialize the parser (but doesn't affect the configuration)
|
|
47
50
|
def self.reset_parser
|
|
48
51
|
@parser = nil
|
|
49
52
|
end
|
|
@@ -6,11 +6,11 @@ class OptionBroker
|
|
|
6
6
|
|
|
7
7
|
attr_reader :parsed_values
|
|
8
8
|
|
|
9
|
-
def initialize(&
|
|
9
|
+
def initialize(&help_block)
|
|
10
10
|
@parsed_values = {}
|
|
11
11
|
@added_options = {}
|
|
12
|
-
if
|
|
13
|
-
add_option(spec: "--help", negatable: false, &
|
|
12
|
+
if help_block
|
|
13
|
+
add_option(spec: "--help", negatable: false, &help_block)
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
16
|
|
data/lib/miniparse/parser.rb
CHANGED
|
@@ -19,15 +19,15 @@ class Parser
|
|
|
19
19
|
def current_command; commander.current_command; end
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
def initialize(program_description =
|
|
22
|
+
def initialize(program_description = nil)
|
|
23
|
+
@commander = Commander.new
|
|
24
|
+
@program_desc = program_description
|
|
23
25
|
@global_broker = OptionBroker.new do
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
print program_desc + "\n" if program_desc
|
|
27
|
+
print help_usage + "\n"
|
|
28
|
+
print help_desc + "\n"
|
|
27
29
|
exit ERR_HELP_REQ
|
|
28
30
|
end
|
|
29
|
-
@commander = Commander.new
|
|
30
|
-
@program_desc = program_description
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
# @param spec is the option specification, similar to the option invocation
|
data/lib/miniparse/version.rb
CHANGED
data/miniparse.gemspec
CHANGED
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
|
9
9
|
spec.authors = ["Juanma Rodriguez"]
|
|
10
10
|
spec.email = ["jmrod4@gmail.com"]
|
|
11
11
|
|
|
12
|
-
spec.summary = %q{Miniparse is
|
|
12
|
+
spec.summary = %q{Miniparse is an easy to use yet flexible and powerful ruby library for parsing command-line options.}
|
|
13
13
|
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
|
14
14
|
spec.homepage = "https://github.com/jmrod4/miniparse"
|
|
15
15
|
spec.license = "MIT"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: miniparse
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Juanma Rodriguez
|
|
@@ -90,6 +90,7 @@ files:
|
|
|
90
90
|
- examples/ex05_block.rb
|
|
91
91
|
- examples/ex06_task_app.rb
|
|
92
92
|
- examples/ex07_controls.rb
|
|
93
|
+
- examples/ex08_app_simple.rb
|
|
93
94
|
- lib/miniparse.rb
|
|
94
95
|
- lib/miniparse/app.rb
|
|
95
96
|
- lib/miniparse/command.rb
|
|
@@ -123,7 +124,7 @@ rubyforge_project:
|
|
|
123
124
|
rubygems_version: 2.4.8
|
|
124
125
|
signing_key:
|
|
125
126
|
specification_version: 4
|
|
126
|
-
summary: Miniparse is
|
|
127
|
+
summary: Miniparse is an easy to use yet flexible and powerful ruby library for parsing
|
|
127
128
|
command-line options.
|
|
128
129
|
test_files: []
|
|
129
130
|
has_rdoc:
|