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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94e23afa0c21f69bf7808df18eb4691d3019c750
4
- data.tar.gz: a71698db070d73deeb59117e9c81d08e49b920e6
3
+ metadata.gz: 8c3f0dcd446901efeaf33fd45b5a74de623c6e31
4
+ data.tar.gz: 820c773fe4275f2d3f922208655d1f2485d3eb16
5
5
  SHA512:
6
- metadata.gz: b7025b9a628fb3bccccb4ed41cd55236736b36b89f9ec0f8b14423d551416a0ea7682fbd57d9e620d2e1234779b532a4779d48cc9cc0bcc58620ef748a2fbb44
7
- data.tar.gz: d166e9bcecd037c0bb51b5567ef02f8027cc7e8751eabfc377f2ae5a06355645523dda34c65ef490f0235aa889d547a70f39a19c1819eefb908b6aaceb153b11
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 (need to comment-out the `nrser-rash`
4
- # line in there too)
5
- # eval_gemfile File.join( ENV['ENV_SUPPORT_DIR'], 'rash', 'Gemfile' )
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'
@@ -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 }, argv: #{ argv.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
- logger.debug "options: #{ options.inspect }"
47
- # options are the last arg, unless we didn't find any
48
- #
49
- # NOTE: this causes functions without an optional `options` arg
50
- # on the end to raise an exception when called with any options.
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
- rtn = mod.method(method_name).call *args
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
- logger.debug "return value: #{ rtn.inspect }"
83
- if formatted = format(rtn)
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).
@@ -102,4 +102,8 @@ module NRSER::Rash::Formatters
102
102
  sio.string
103
103
  end
104
104
 
105
+ def self.lines obj
106
+ obj.join "\n"
107
+ end
108
+
105
109
  end # module NRSER::Rash::Formatters
@@ -6,7 +6,7 @@ module NRSER
6
6
  #
7
7
  # @return [String]
8
8
  #
9
- VERSION = "0.2.1"
9
+ VERSION = "0.2.2"
10
10
 
11
11
  # Absolute, expanded path to the gem's root directory.
12
12
  #
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nrser-rash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser