spud 0.1.9 → 0.1.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9b52bb3b0a406042b1c0feaf8c6952974992b1c79586eb372417c03253367db
4
- data.tar.gz: 366ce2813f418f1b0a5795a28c73f37128ef3a82c0dff95809877ab5dca5783e
3
+ metadata.gz: fb821b1f4c184c6f4fda6e5fe02f17807786cbae5d2678f5ce63d154e8986e29
4
+ data.tar.gz: 9db7fac77dcd10a339c6f5ded2136b36801b547abee13ee73d062674f8a949f6
5
5
  SHA512:
6
- metadata.gz: 1fe21ca0d2b91d02c995deb4515382e5a59ee54160bcee71af23608cb634962b3beb16c764193ee9ff46314d8f7251d5fdc40ae1a535a5646362ba208784c7a7
7
- data.tar.gz: e7f16245115ca30d84585c5fee030e1be064dff6e38fd67196f5423501699242a132f7dab0e58885d7f6d24c54f16828960a23b7cba9e65dfc648bfe835e8f02
6
+ metadata.gz: 37572660fdd244779b01427399527d1ec89f7533657f0e9b2ec8e620efc2ba3111dc6c3b5f12429270dddfbb9f46a018a5745934684581ea1af4b6eed11558c5
7
+ data.tar.gz: 40247e664b05f7e059c3b676e0465bab1b03927dceda1ffaf6fd6991c145ce2afc76d8780bb856ab5ddf923271febfb689956a7d0057b3768b944c6c598488f5
@@ -8,6 +8,14 @@ module Spud
8
8
  def filename
9
9
  raise NotImplementedError
10
10
  end
11
+
12
+ def positional_params
13
+ []
14
+ end
15
+
16
+ def keyword_params
17
+ []
18
+ end
11
19
  end
12
20
  end
13
21
  end
@@ -21,9 +21,9 @@ module Spud::BuildTools
21
21
  def invoke(*args, **kwargs)
22
22
  raise Spud::Error, "'#{@name}' is up to date" if up_to_date?
23
23
 
24
- missing = required_params.length - args.length
24
+ missing = positional_params.length - args.length
25
25
  if missing > 0
26
- names = required_params.map { |name| "'#{name}'" }.join(', ')
26
+ names = positional_params.map { |name| "'#{name}'" }.join(', ')
27
27
  arguments = missing > 1 ? 'arguments' : 'argument'
28
28
  raise Spud::Error, "invocation of '#{@name}' missing required #{arguments} #{names}"
29
29
  end
@@ -37,6 +37,15 @@ module Spud::BuildTools
37
37
  end
38
38
  end
39
39
 
40
+ # Params
41
+ def positional_params
42
+ @positional_params ||= params.select { |p| p.first == :req }.map(&:last)
43
+ end
44
+
45
+ def keyword_params
46
+ @keyword_params ||= params.select { |p| p.first == :key }.map(&:last)
47
+ end
48
+
40
49
  private
41
50
 
42
51
  # Up to date checking
@@ -86,11 +95,11 @@ module Spud::BuildTools
86
95
 
87
96
  # Lambda
88
97
  def key_params?
89
- lam.parameters.map(&:first).include?(:key)
98
+ @key_params ||= !keyword_params.empty?
90
99
  end
91
100
 
92
- def required_params
93
- lam.parameters.select { |p| p.first == :req }.map(&:last)
101
+ def params
102
+ @params ||= lam.parameters
94
103
  end
95
104
 
96
105
  def lam
@@ -16,10 +16,6 @@ module Spud::BuildTools
16
16
  end
17
17
  end
18
18
 
19
- def __shell(cmd, params = {})
20
- @__process = Spud::Shell.new(cmd, params)
21
- end
22
-
23
19
  def sh(cmd)
24
20
  out = sh?(cmd)
25
21
  raise ShellError unless out.status.exitstatus.zero?
@@ -29,7 +25,7 @@ module Spud::BuildTools
29
25
 
30
26
  def sh?(cmd)
31
27
  puts cmd
32
- __shell(cmd)
28
+ Spud::Shell.new(cmd)
33
29
  end
34
30
 
35
31
  def shh(cmd)
@@ -40,7 +36,7 @@ module Spud::BuildTools
40
36
  end
41
37
 
42
38
  def shh?(cmd)
43
- __shell(cmd)
39
+ Spud::Shell.new(cmd)
44
40
  end
45
41
 
46
42
  def shhh(cmd)
@@ -51,7 +47,7 @@ module Spud::BuildTools
51
47
  end
52
48
 
53
49
  def shhh?(cmd)
54
- __shell(cmd, silent: true)
50
+ Spud::Shell.new(cmd, silent: true)
55
51
  end
56
52
 
57
53
  def invoke(name, *args, **kwargs)
@@ -91,20 +91,73 @@ module Spud
91
91
  end
92
92
 
93
93
  def print_rules!
94
- table = rules.map { |name, rule| [name, rule.filename] }
94
+ #table = rules.map { |name, rule| { name: name, filename: rule.filename } }
95
+
96
+ longest_name = 0
97
+ longest_filename = 0
98
+ longest_positional = 0
99
+ longest_keyword = 0
100
+ table = []
101
+ rules.each do |name, rule|
102
+ longest_name = name.length if name.length > longest_name
103
+
104
+ positional = rule.positional_params.map(&method(:wrap_param)).join(' ')
105
+ longest_positional = positional.length if positional.length > longest_positional
106
+
107
+ keyword = rule.keyword_params.map(&method(:prefix_param)).join(' ')
108
+ longest_keyword = keyword.length if keyword.length > longest_keyword
109
+
110
+ longest_filename = rule.filename.length if rule.filename.length > longest_filename
111
+
112
+ table << [name, positional, keyword, rule.filename]
113
+ end
114
+
115
+ table.each do |(name, positional, keyword, filename)|
116
+ fields = [name.ljust(longest_name)]
117
+ fields << positional.ljust(longest_positional) unless longest_positional == 0
118
+ fields << keyword.ljust(longest_keyword) unless longest_keyword == 0
119
+ fields << filename.ljust(longest_filename)
120
+
121
+ puts fields.join(' ')
122
+ end
123
+
124
+ return
95
125
 
96
126
  longest_rule = 0
97
127
  longest_filename = 0
128
+ longest_positional = 0
129
+ longest_keyword = 0
98
130
  table.each do |(rule, filename)|
99
131
  longest_rule = rule.length if rule.length > longest_rule
100
132
  longest_filename = filename.length if filename.length > longest_filename
133
+
134
+ positional = rule.positional_params.map(&method(:wrap_param)).join(' ')
135
+ longest_positional = positional.length if positional.length > longest_positional
136
+
137
+ keyword = rule.keyword_params.map(&method(:prefix_param)).join(' ')
138
+ longest_keyword = keyword.length if keyword.length > longest_keyword
101
139
  end
102
140
 
103
141
  table.each do |(rule, filename)|
142
+ [
143
+ [rule, longest_rule],
144
+ [positional, longest_positional],
145
+ [filename, longest_filename],
146
+ [filename, longest_filename],
147
+ ]
148
+
104
149
  puts "#{rule.ljust(longest_rule)} #{filename.ljust(longest_filename)}"
105
150
  end
106
151
  end
107
152
 
153
+ def wrap_param(name)
154
+ "<#{name}>"
155
+ end
156
+
157
+ def prefix_param(name)
158
+ name.length == 1 ? "-#{name}" : "--#{name}"
159
+ end
160
+
108
161
  # Help
109
162
  def print_help!
110
163
  help = StringIO.new
@@ -1,3 +1,3 @@
1
1
  module Spud
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.10'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Booth