auto-optparse 1.0.0 → 1.1.0
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/auto/optparse/parser_configuration.rb +21 -1
- data/lib/auto/optparse/version.rb +1 -1
- data/lib/auto.rb +7 -3
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2d0eec18845df9087d69a493a06c397d06c83126a07737edd2f3f6dab8c51512
|
|
4
|
+
data.tar.gz: d28d9c51287744497939d183cf903dfce242def7b350c769f612c26168ec2066
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d0b153ad1b464ab864f5a590b62dd36824abe3004c705ceadd5fbaf0482c8ad892546a1a21ee2927b9aff9bdd630ce2909a713864fe5e486b69e8ae044a5caf
|
|
7
|
+
data.tar.gz: 55fc216a451ead3fe33052fa2ed378dd8268ca904f12d32ffbd421761001d5ab36603d539da6e5053a69b9a7382e003e3c28ada78ddf9f6f258411c416a14087
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'optparse'
|
|
2
|
+
require 'colorize'
|
|
2
3
|
|
|
3
4
|
require 'auto/optparse/error'
|
|
4
5
|
|
|
@@ -9,7 +10,7 @@ module Auto
|
|
|
9
10
|
def configure(argvies: ARGV)
|
|
10
11
|
parser = OptionParser.new
|
|
11
12
|
options.each do |k, v|
|
|
12
|
-
parser.on(*generate_optparse_entry(k, v),
|
|
13
|
+
parser.on(*generate_optparse_entry(k, v), default_value(v))
|
|
13
14
|
end
|
|
14
15
|
yield parser if block_given?
|
|
15
16
|
parser.parse!(argvies, into: options)
|
|
@@ -29,6 +30,25 @@ module Auto
|
|
|
29
30
|
raise UnsupportedDefaultOption, "Don't know how to convert #{k.inspect} => #{v.inspect} (#{v.class}) to option!"
|
|
30
31
|
end
|
|
31
32
|
end
|
|
33
|
+
|
|
34
|
+
def default_value(v)
|
|
35
|
+
"Default: #{v.inspect.send(value_color(v))}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def value_color(v) # rubocop:disable Metrics/MethodLength
|
|
39
|
+
case v
|
|
40
|
+
when TrueClass
|
|
41
|
+
:green
|
|
42
|
+
when FalseClass
|
|
43
|
+
:red
|
|
44
|
+
when Numeric
|
|
45
|
+
:blue
|
|
46
|
+
when String
|
|
47
|
+
:yellow
|
|
48
|
+
else
|
|
49
|
+
:white
|
|
50
|
+
end
|
|
51
|
+
end
|
|
32
52
|
end
|
|
33
53
|
end
|
|
34
54
|
end
|
data/lib/auto.rb
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
|
+
require 'colorize'
|
|
2
|
+
|
|
1
3
|
# class-level stateless helpers
|
|
2
4
|
module Auto
|
|
3
5
|
def self.run(klass, argvies: ARGV, calling_file: caller_locations.first.path)
|
|
4
6
|
run!(klass, argvies: argvies) if run?(calling_file: calling_file) # otherwise we call from here
|
|
5
7
|
end
|
|
6
8
|
|
|
7
|
-
def self.run!(klass, argvies: ARGV, &block)
|
|
9
|
+
def self.run!(klass, argvies: ARGV, &block) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
8
10
|
instance = klass.new
|
|
9
11
|
instance.configure(argvies: argvies, &block)
|
|
10
12
|
instance.run
|
|
11
13
|
rescue StandardError => exc
|
|
12
14
|
puts
|
|
13
|
-
|
|
15
|
+
print ' ERROR '.white.on_red
|
|
16
|
+
print ' '
|
|
17
|
+
puts exc.class.name.red
|
|
14
18
|
puts exc.message
|
|
15
|
-
puts exc.backtrace.join("\n")
|
|
19
|
+
puts exc.backtrace.join("\n").gray
|
|
16
20
|
exit false
|
|
17
21
|
end
|
|
18
22
|
|
metadata
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: auto-optparse
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Emil Chludziński
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
-
dependencies:
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: colorize
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
12
26
|
description: |
|
|
13
27
|
`Auto::Optparse` is a module that speeds up writing short scripts by configuring `OptionParser` from `@options` hash.
|
|
14
28
|
It will cast commonly used types and generate barebones-but-readable `--help` output.
|