simple_args_dispatch 0.2.7 → 0.3.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/simple_args_dispatch.rb +16 -16
- data/lib/simple_args_dispatch/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbcad084e9c183ea9115eb614b3f91e077948980
|
4
|
+
data.tar.gz: 19c1f415640cf74522411b9dd8725e9f91b5da64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae7f3b763ba04a3722453993474c06413231ca7b7d8caf6fd910006b30f2eeaeb213a46f7481810dee39dde1675755cb73443ecd4fb86765f01e2f8dc62fa98a
|
7
|
+
data.tar.gz: b2327fdba31d354ce9178644d33cca35bd86287a02f6686a2dad8166ba2df0b58757861aa290a033d37ea430b8923fe97f48467554ceec2e6c65528067c0ab53
|
data/lib/simple_args_dispatch.rb
CHANGED
@@ -14,7 +14,11 @@ module SimpleArgsDispatch
|
|
14
14
|
# }
|
15
15
|
# end
|
16
16
|
|
17
|
-
def
|
17
|
+
def initialize(speaker = nil)
|
18
|
+
@speaker = speaker
|
19
|
+
end
|
20
|
+
|
21
|
+
def dispatch(app_name, args, actions, parent = nil, template_dir = '')
|
18
22
|
arg = args.shift
|
19
23
|
actions.each do |k, v|
|
20
24
|
if arg == k.to_s
|
@@ -26,13 +30,13 @@ module SimpleArgsDispatch
|
|
26
30
|
return
|
27
31
|
end
|
28
32
|
end
|
29
|
-
speaker.speak_up('Unknown command/option
|
33
|
+
@speaker.speak_up('Unknown command/option
|
30
34
|
|
31
35
|
')
|
32
36
|
self.show_available(app_name, actions, parent)
|
33
37
|
end
|
34
38
|
|
35
|
-
def
|
39
|
+
def launch(app_name, action, args, parent, template_dir)
|
36
40
|
args = Hash[args.flat_map { |s| s.scan(/--?([^=\s]+)(?:=(.+))?/) }]
|
37
41
|
template_args = parse_template_args(load_template(args['template_name'], template_dir), template_dir)
|
38
42
|
model = Object.const_get(action[0])
|
@@ -49,13 +53,13 @@ module SimpleArgsDispatch
|
|
49
53
|
val = eval(val) if val.is_a?(String) && val.match(/^[{\[].*[}\]]$/)
|
50
54
|
[k, val]
|
51
55
|
end].select { |_, v| !v.nil? }
|
52
|
-
speaker.speak_up("Running with arguments: " + params.map{|a, v| "#{a.to_s}='#{v.to_s}'"}.join(' ')) if $env_flags['debug'] > 0
|
56
|
+
@speaker.speak_up("Running with arguments: " + params.map{|a, v| "#{a.to_s}='#{v.to_s}'"}.join(' ')) if $env_flags['debug'] > 0
|
53
57
|
params.empty? ? dameth.call : dameth.call(params)
|
54
58
|
rescue => e
|
55
|
-
speaker.tell_error(e, "SimpleAgrsDispatch.launch")
|
59
|
+
@speaker.tell_error(e, "SimpleAgrsDispatch.launch")
|
56
60
|
end
|
57
61
|
|
58
|
-
def
|
62
|
+
def load_template(template_name, template_dir)
|
59
63
|
if template_name.to_s != '' && File.exist?(template_dir + '/' + "#{template_name}.yml")
|
60
64
|
return YAML.load_file(template_dir + '/' + "#{template_name}.yml")
|
61
65
|
end
|
@@ -64,11 +68,11 @@ module SimpleArgsDispatch
|
|
64
68
|
{}
|
65
69
|
end
|
66
70
|
|
67
|
-
def
|
71
|
+
def new_line
|
68
72
|
'---------------------------------------------------------'
|
69
73
|
end
|
70
74
|
|
71
|
-
def
|
75
|
+
def parse_template_args(template, template_dir)
|
72
76
|
template.keys.each do |k|
|
73
77
|
if k.to_s == 'load_template'
|
74
78
|
template[k] = [template[k]] if template[k].is_a?(String)
|
@@ -83,15 +87,11 @@ module SimpleArgsDispatch
|
|
83
87
|
template
|
84
88
|
end
|
85
89
|
|
86
|
-
def
|
87
|
-
speaker.speak_up("Usage: #{app_name} #{prepend + ' ' if prepend}#{available.map { |k, v| "#{k.to_s}#{'(optional)' if v == :opt}" }.join(join)}")
|
90
|
+
def show_available(app_name, available, prepend = nil, join='|', separator = new_line, extra_info = '')
|
91
|
+
@speaker.speak_up("Usage: #{app_name} #{prepend + ' ' if prepend}#{available.map { |k, v| "#{k.to_s}#{'(optional)' if v == :opt}" }.join(join)}")
|
88
92
|
if extra_info.to_s != ''
|
89
|
-
speaker.speak_up(separator)
|
90
|
-
speaker.speak_up(extra_info)
|
93
|
+
@speaker.speak_up(separator)
|
94
|
+
@speaker.speak_up(extra_info)
|
91
95
|
end
|
92
96
|
end
|
93
|
-
|
94
|
-
def self.speaker
|
95
|
-
@speaker ||= SimpleSpeaker::Speaker.new
|
96
|
-
end
|
97
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_args_dispatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- R
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|