nrser-rash 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +18 -3
- data/lib/nrser/rash/cli/call.rb +42 -14
- data/lib/nrser/rash/formatters.rb +4 -0
- data/lib/nrser/rash/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: 8c3f0dcd446901efeaf33fd45b5a74de623c6e31
|
4
|
+
data.tar.gz: 820c773fe4275f2d3f922208655d1f2485d3eb16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6e9696d2e0847942c25457b8c80f9741485e4c176a5237c563363fa10ebf98c2ddf2f62a998b7cc08964cc8293ddee09d195775ab042db23e1874c72d62f573
|
7
|
+
data.tar.gz: d943da9fdaeb43c5971cdd25ee44c5a6122c5c60ada7bfb8156f046717313abe36f47c45503610985000c5cd994ccea19f3566609856169cc6c9b1048fb0e764
|
data/Gemfile
CHANGED
@@ -1,8 +1,23 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
# Install my user functions' deps too
|
4
|
-
#
|
5
|
-
|
3
|
+
# Install my user functions' deps too
|
4
|
+
# RubyGems API Client
|
5
|
+
gem 'gems'
|
6
|
+
|
7
|
+
# Work with XML
|
8
|
+
gem 'nokogiri'
|
9
|
+
|
10
|
+
# Work with Apple Property List files (`.plist`)
|
11
|
+
#
|
12
|
+
# Kinda buggy and limited, and I think it only covers XML, but it's something.
|
13
|
+
#
|
14
|
+
gem 'plist'
|
15
|
+
|
16
|
+
# A generally more capable Apple Property List (`.plist`) handling toolkit,
|
17
|
+
# though it's also more complicated and less user-friendly than `plist` from
|
18
|
+
# what I recall, and it still can't handle some of the "old-style" plists that
|
19
|
+
# things like `defaults` and `launchctl` can shit out.
|
20
|
+
gem 'CFPropertyList'
|
6
21
|
|
7
22
|
# Use dev versions
|
8
23
|
# gem 'nrser', path: './dev/packages/gems/nrser'
|
data/lib/nrser/rash/cli/call.rb
CHANGED
@@ -23,7 +23,9 @@ module NRSER::Rash::CLI
|
|
23
23
|
#
|
24
24
|
def self.call name, argv
|
25
25
|
|
26
|
-
logger.trace "calling #{ name.inspect },
|
26
|
+
logger.trace "calling #{ name.inspect }",
|
27
|
+
argv: argv
|
28
|
+
|
27
29
|
# look for options
|
28
30
|
options = {}
|
29
31
|
args = argv.reject do |arg|
|
@@ -43,17 +45,14 @@ module NRSER::Rash::CLI
|
|
43
45
|
true
|
44
46
|
end
|
45
47
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
#
|
52
|
-
# i think this is the correct behavior: the function can't handle
|
53
|
-
# options, and should error out.
|
54
|
-
args << options unless options.empty?
|
48
|
+
|
49
|
+
logger.trace "Extracted options",
|
50
|
+
argv: argv,
|
51
|
+
args: args,
|
52
|
+
options: options
|
55
53
|
|
56
54
|
NRSER::Rash.load_functions
|
55
|
+
|
57
56
|
if name.include? '.'
|
58
57
|
*namespace, method_name = name.split '.'
|
59
58
|
namespace = namespace.flat_map { |s| s.split '::' }
|
@@ -61,12 +60,36 @@ module NRSER::Rash::CLI
|
|
61
60
|
namespace = []
|
62
61
|
method_name = name
|
63
62
|
end
|
63
|
+
|
64
|
+
# Find the module the function is in
|
64
65
|
mod = NRSER::Rash::Functions
|
65
66
|
namespace.each do |submod_name|
|
66
67
|
mod = mod.const_get(submod_name.capitalize)
|
67
68
|
end
|
69
|
+
|
70
|
+
# Get the function itself ({Metood} instance)
|
71
|
+
meth = mod.method method_name
|
72
|
+
|
73
|
+
# Symbolize option keys if the method takes keyword args
|
74
|
+
if meth.parameters.any? { |type, *_|
|
75
|
+
[:key, :keyreq, :keyrest].include? type
|
76
|
+
}
|
77
|
+
options = options.map { |key, value|
|
78
|
+
[key.to_sym, value]
|
79
|
+
}.to_h
|
80
|
+
end
|
81
|
+
|
82
|
+
# options are the last arg, unless we didn't find any
|
83
|
+
#
|
84
|
+
# NOTE: this causes functions without an optional `options` arg
|
85
|
+
# on the end to raise an exception when called with any options.
|
86
|
+
#
|
87
|
+
# i think this is the correct behavior: the function can't handle
|
88
|
+
# options, and should error out.
|
89
|
+
args << options unless options.empty?
|
90
|
+
|
68
91
|
begin
|
69
|
-
|
92
|
+
result = meth.call *args
|
70
93
|
rescue Exception => error
|
71
94
|
if NRSER::Rash.config( 'PRINT_ERRORS' ).truthy?
|
72
95
|
if NRSER::Rash.config( 'STACKTRACE' ).truthy?
|
@@ -79,13 +102,18 @@ module NRSER::Rash::CLI
|
|
79
102
|
end
|
80
103
|
end
|
81
104
|
end
|
82
|
-
|
83
|
-
|
105
|
+
|
106
|
+
logger.debug "Function #{ name } returned",
|
107
|
+
result: result
|
108
|
+
|
109
|
+
if formatted = format( result )
|
84
110
|
puts formatted
|
85
111
|
end
|
112
|
+
|
86
113
|
exit 0
|
87
114
|
end
|
88
|
-
|
115
|
+
|
116
|
+
|
89
117
|
# formats an object to write to `$stdout`.
|
90
118
|
# returns `nil` if there's nothing to write (different than returning '',
|
91
119
|
# indicating the empty string should be written).
|
data/lib/nrser/rash/version.rb
CHANGED