cmdlet 0.0.7 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.builders/.templates/cmdlet.rb +26 -0
- data/.builders/.templates/{command_spec.rb → cmdlet_spec.rb} +4 -4
- data/.builders/.templates/require_all_cmdlets.rb +5 -0
- data/.builders/_.rb +7 -1
- data/.builders/boot.rb +2 -0
- data/.builders/data/categories.json +2 -10
- data/.builders/data/cmdlets/array.json +121 -0
- data/.builders/data/cmdlets/case.json +313 -0
- data/.builders/data/cmdlets/comparison.json +245 -0
- data/.builders/data/cmdlets/inflection.json +129 -0
- data/.builders/director/category_builder.rb +26 -0
- data/.builders/director/category_dao.rb +38 -0
- data/.builders/director/category_director.rb +24 -10
- data/.builders/director/cmdlet_builder.rb +27 -34
- data/.builders/director/cmdlet_child.rb +16 -44
- data/.builders/director/cmdlet_dao.rb +29 -0
- data/.builders/director/cmdlet_director.rb +37 -13
- data/.builders/director/dao.rb +16 -0
- data/.builders/documents/commands.rb +15 -16
- data/.builders/documents/use_cases.rb +32 -34
- data/.builders/documents/x_functions.rb +7 -10
- data/.builders/generators/01-bootstrap.rb +112 -112
- data/.builders/generators/20-categories.rb +16 -0
- data/.builders/generators/30-commands-bak.rb +53 -0
- data/.builders/generators/cmdlets/array.rb +71 -0
- data/.builders/generators/cmdlets/case.rb +184 -0
- data/.builders/generators/cmdlets/comparison.rb +126 -0
- data/.builders/generators/cmdlets/inflection.rb +93 -0
- data/CHANGELOG.md +37 -0
- data/Guardfile +1 -1
- data/lib/cmdlet/_.rb +33 -0
- data/lib/cmdlet/array/join.rb +8 -10
- data/lib/cmdlet/array/join_post.rb +22 -0
- data/lib/cmdlet/array/join_pre.rb +22 -0
- data/lib/cmdlet/base_cmdlet.rb +17 -0
- data/lib/cmdlet/case/back_slash.rb +16 -0
- data/lib/cmdlet/case/camel.rb +16 -0
- data/lib/cmdlet/case/constant.rb +16 -0
- data/lib/cmdlet/case/dash.rb +16 -0
- data/lib/cmdlet/case/dot.rb +16 -0
- data/lib/cmdlet/case/double_colon.rb +16 -0
- data/lib/cmdlet/case/human.rb +20 -0
- data/lib/cmdlet/case/lamel.rb +16 -0
- data/lib/cmdlet/case/lower.rb +18 -0
- data/lib/cmdlet/case/sentence.rb +20 -0
- data/lib/cmdlet/case/slash.rb +16 -0
- data/lib/cmdlet/case/snake.rb +16 -0
- data/lib/cmdlet/case/title.rb +21 -0
- data/lib/cmdlet/case/upper.rb +18 -0
- data/lib/cmdlet/comparison/and.rb +16 -0
- data/lib/cmdlet/comparison/default.rb +20 -0
- data/lib/cmdlet/comparison/eq.rb +20 -0
- data/lib/cmdlet/comparison/gt.rb +17 -0
- data/lib/cmdlet/comparison/gte.rb +17 -0
- data/lib/cmdlet/comparison/lt.rb +17 -0
- data/lib/cmdlet/comparison/lte.rb +17 -0
- data/lib/cmdlet/comparison/ne.rb +20 -0
- data/lib/cmdlet/comparison/or.rb +16 -0
- data/lib/cmdlet/inflection/ordinal.rb +20 -0
- data/lib/cmdlet/inflection/ordinalize.rb +20 -0
- data/lib/cmdlet/inflection/pluralize.rb +20 -0
- data/lib/cmdlet/inflection/pluralize_by_number.rb +28 -0
- data/lib/cmdlet/inflection/singularize.rb +20 -0
- data/lib/cmdlet/version.rb +1 -1
- data/lib/cmdlet.rb +5 -0
- data/package-lock.json +2 -2
- data/package.json +1 -1
- metadata +51 -9
- data/.builders/.templates/all_commands.rb +0 -5
- data/.builders/.templates/command.rb +0 -26
- data/.builders/documents/categories.rb +0 -24
- data/.builders/documents/cmdlets.rb +0 -30
- data/.builders/generators/20-commands.rb +0 -54
- data/.builders/generators/25-categories.rb +0 -20
@@ -0,0 +1,245 @@
|
|
1
|
+
{
|
2
|
+
"category_key": "comparison",
|
3
|
+
"cmdlets": [
|
4
|
+
{
|
5
|
+
"name": "and",
|
6
|
+
"description": "Return true if **all of** the given values are truthy.",
|
7
|
+
"result": "return true when every value is truthy",
|
8
|
+
"category": "comparison",
|
9
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
10
|
+
"base_class_require": null,
|
11
|
+
"base_class": null,
|
12
|
+
"parameters": [
|
13
|
+
{
|
14
|
+
"name": "values",
|
15
|
+
"description": "list of values (via *splat) to be checked via AND condition",
|
16
|
+
"splat": "*",
|
17
|
+
"default": null,
|
18
|
+
"param_type": "Object"
|
19
|
+
}
|
20
|
+
],
|
21
|
+
"examples": [
|
22
|
+
|
23
|
+
],
|
24
|
+
"ruby": " values.all? { |value| value }\n"
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"name": "default",
|
28
|
+
"description": "Return true if **all of** the given values are truthy.",
|
29
|
+
"result": "return true when every value is truthy",
|
30
|
+
"category": "comparison",
|
31
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
32
|
+
"base_class_require": null,
|
33
|
+
"base_class": null,
|
34
|
+
"parameters": [
|
35
|
+
{
|
36
|
+
"name": "values",
|
37
|
+
"description": "one or more paramaters that may or may not contain nil",
|
38
|
+
"splat": "*",
|
39
|
+
"default": null,
|
40
|
+
"param_type": "Object"
|
41
|
+
}
|
42
|
+
],
|
43
|
+
"examples": [
|
44
|
+
|
45
|
+
],
|
46
|
+
"ruby": " default_value = values[-1]\n\n find_value = values[0..-2].find { |value| !value.nil? }\n\n find_value || default_value\n"
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"name": "eq",
|
50
|
+
"description": "Return true if two values are equal",
|
51
|
+
"result": "return truthy value if left hand side equals right hand side",
|
52
|
+
"category": "comparison",
|
53
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
54
|
+
"base_class_require": null,
|
55
|
+
"base_class": null,
|
56
|
+
"parameters": [
|
57
|
+
{
|
58
|
+
"name": "lhs",
|
59
|
+
"description": "lhs - left hand side value",
|
60
|
+
"splat": null,
|
61
|
+
"default": null,
|
62
|
+
"param_type": "Object"
|
63
|
+
},
|
64
|
+
{
|
65
|
+
"name": "rhs",
|
66
|
+
"description": "rhs - right hand side value",
|
67
|
+
"splat": null,
|
68
|
+
"default": null,
|
69
|
+
"param_type": "Object"
|
70
|
+
}
|
71
|
+
],
|
72
|
+
"examples": [
|
73
|
+
|
74
|
+
],
|
75
|
+
"ruby": " lhs = lhs.to_s if lhs.is_a?(Symbol)\n rhs = rhs.to_s if rhs.is_a?(Symbol)\n\n lhs == rhs\n"
|
76
|
+
},
|
77
|
+
{
|
78
|
+
"name": "gt",
|
79
|
+
"description": "Return true if left hand side GREATER THAN right hand side",
|
80
|
+
"result": "truthy value if left hand side GREATER THAN right hand side",
|
81
|
+
"category": "comparison",
|
82
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
83
|
+
"base_class_require": null,
|
84
|
+
"base_class": null,
|
85
|
+
"parameters": [
|
86
|
+
{
|
87
|
+
"name": "lhs",
|
88
|
+
"description": "lhs - left hand side value",
|
89
|
+
"splat": null,
|
90
|
+
"default": null,
|
91
|
+
"param_type": "Object"
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"name": "rhs",
|
95
|
+
"description": "rhs - right hand side value",
|
96
|
+
"splat": null,
|
97
|
+
"default": null,
|
98
|
+
"param_type": "Object"
|
99
|
+
}
|
100
|
+
],
|
101
|
+
"examples": [
|
102
|
+
|
103
|
+
],
|
104
|
+
"ruby": " lhs > rhs\n"
|
105
|
+
},
|
106
|
+
{
|
107
|
+
"name": "gte",
|
108
|
+
"description": "Return true if left hand side GREATER THAN or EQUAL TO right hand side",
|
109
|
+
"result": "truthy value if left hand side GREATER THAN or EQUAL TO right hand side",
|
110
|
+
"category": "comparison",
|
111
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
112
|
+
"base_class_require": null,
|
113
|
+
"base_class": null,
|
114
|
+
"parameters": [
|
115
|
+
{
|
116
|
+
"name": "lhs",
|
117
|
+
"description": "lhs - left hand side value",
|
118
|
+
"splat": null,
|
119
|
+
"default": null,
|
120
|
+
"param_type": "Object"
|
121
|
+
},
|
122
|
+
{
|
123
|
+
"name": "rhs",
|
124
|
+
"description": "rhs - right hand side value",
|
125
|
+
"splat": null,
|
126
|
+
"default": null,
|
127
|
+
"param_type": "Object"
|
128
|
+
}
|
129
|
+
],
|
130
|
+
"examples": [
|
131
|
+
|
132
|
+
],
|
133
|
+
"ruby": " lhs >= rhs\n"
|
134
|
+
},
|
135
|
+
{
|
136
|
+
"name": "lt",
|
137
|
+
"description": "Return true if left hand side LESS THAN right hand side",
|
138
|
+
"result": "truthy value if left hand side LESS THAN right hand side",
|
139
|
+
"category": "comparison",
|
140
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
141
|
+
"base_class_require": null,
|
142
|
+
"base_class": null,
|
143
|
+
"parameters": [
|
144
|
+
{
|
145
|
+
"name": "lhs",
|
146
|
+
"description": "lhs - left hand side value",
|
147
|
+
"splat": null,
|
148
|
+
"default": null,
|
149
|
+
"param_type": "Object"
|
150
|
+
},
|
151
|
+
{
|
152
|
+
"name": "rhs",
|
153
|
+
"description": "rhs - right hand side value",
|
154
|
+
"splat": null,
|
155
|
+
"default": null,
|
156
|
+
"param_type": "Object"
|
157
|
+
}
|
158
|
+
],
|
159
|
+
"examples": [
|
160
|
+
|
161
|
+
],
|
162
|
+
"ruby": " lhs < rhs\n"
|
163
|
+
},
|
164
|
+
{
|
165
|
+
"name": "lte",
|
166
|
+
"description": "Return true if left hand side LESS THAN or EQUAL TO right hand side",
|
167
|
+
"result": "truthy value if left hand side LESS THAN or EQUAL TO right hand side",
|
168
|
+
"category": "comparison",
|
169
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
170
|
+
"base_class_require": null,
|
171
|
+
"base_class": null,
|
172
|
+
"parameters": [
|
173
|
+
{
|
174
|
+
"name": "lhs",
|
175
|
+
"description": "lhs - left hand side value",
|
176
|
+
"splat": null,
|
177
|
+
"default": null,
|
178
|
+
"param_type": "Object"
|
179
|
+
},
|
180
|
+
{
|
181
|
+
"name": "rhs",
|
182
|
+
"description": "rhs - right hand side value",
|
183
|
+
"splat": null,
|
184
|
+
"default": null,
|
185
|
+
"param_type": "Object"
|
186
|
+
}
|
187
|
+
],
|
188
|
+
"examples": [
|
189
|
+
|
190
|
+
],
|
191
|
+
"ruby": " lhs <= rhs\n"
|
192
|
+
},
|
193
|
+
{
|
194
|
+
"name": "ne",
|
195
|
+
"description": "Return true if left hand side is NOT equal to right hand side",
|
196
|
+
"result": "truthy value if left hand side is NOT equal to right hand side",
|
197
|
+
"category": "comparison",
|
198
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
199
|
+
"base_class_require": null,
|
200
|
+
"base_class": null,
|
201
|
+
"parameters": [
|
202
|
+
{
|
203
|
+
"name": "lhs",
|
204
|
+
"description": "lhs - left hand side value",
|
205
|
+
"splat": null,
|
206
|
+
"default": null,
|
207
|
+
"param_type": "Object"
|
208
|
+
},
|
209
|
+
{
|
210
|
+
"name": "rhs",
|
211
|
+
"description": "rhs - right hand side value",
|
212
|
+
"splat": null,
|
213
|
+
"default": null,
|
214
|
+
"param_type": "Object"
|
215
|
+
}
|
216
|
+
],
|
217
|
+
"examples": [
|
218
|
+
|
219
|
+
],
|
220
|
+
"ruby": " lhs = lhs.to_s if lhs.is_a?(Symbol)\n rhs = rhs.to_s if rhs.is_a?(Symbol)\n\n lhs != rhs\n"
|
221
|
+
},
|
222
|
+
{
|
223
|
+
"name": "or",
|
224
|
+
"description": "Return true if any value is truthy.",
|
225
|
+
"result": "return true when first value is truthy",
|
226
|
+
"category": "comparison",
|
227
|
+
"category_description": "Comparison helpers, eg. or, and, equal, not equal, less than, greater than etc.",
|
228
|
+
"base_class_require": null,
|
229
|
+
"base_class": null,
|
230
|
+
"parameters": [
|
231
|
+
{
|
232
|
+
"name": "values",
|
233
|
+
"description": "list of values (via *splat) to be checked via AND condition",
|
234
|
+
"splat": "*",
|
235
|
+
"default": null,
|
236
|
+
"param_type": "Object"
|
237
|
+
}
|
238
|
+
],
|
239
|
+
"examples": [
|
240
|
+
|
241
|
+
],
|
242
|
+
"ruby": " values.any? { |value| value }\n"
|
243
|
+
}
|
244
|
+
]
|
245
|
+
}
|
@@ -0,0 +1,129 @@
|
|
1
|
+
{
|
2
|
+
"category_key": "inflection",
|
3
|
+
"cmdlets": [
|
4
|
+
{
|
5
|
+
"name": "ordinal",
|
6
|
+
"description": "The suffix that should be added to a number to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th",
|
7
|
+
"result": "ordinal suffix that would be required for a number",
|
8
|
+
"category": "inflection",
|
9
|
+
"category_description": "Inflection handling routines, eg. pluralize, singular, ordinalize",
|
10
|
+
"base_class_require": null,
|
11
|
+
"base_class": null,
|
12
|
+
"parameters": [
|
13
|
+
{
|
14
|
+
"name": "value",
|
15
|
+
"description": "value - numeric value",
|
16
|
+
"splat": null,
|
17
|
+
"default": null,
|
18
|
+
"param_type": "String|Int"
|
19
|
+
}
|
20
|
+
],
|
21
|
+
"examples": [
|
22
|
+
|
23
|
+
],
|
24
|
+
"ruby": " return '' if value.nil?\n\n value = value.to_i if value.is_a? String\n\n value.ordinal\n"
|
25
|
+
},
|
26
|
+
{
|
27
|
+
"name": "ordinalize",
|
28
|
+
"description": "Turns a number into an ordinal string used to denote the position in an ordered sequence such as 1st, 2nd, 3rd, 4th.",
|
29
|
+
"result": "number value turned to 1st, 2nd, 3rd, 4th etc.",
|
30
|
+
"category": "inflection",
|
31
|
+
"category_description": "Inflection handling routines, eg. pluralize, singular, ordinalize",
|
32
|
+
"base_class_require": null,
|
33
|
+
"base_class": null,
|
34
|
+
"parameters": [
|
35
|
+
{
|
36
|
+
"name": "value",
|
37
|
+
"description": "value - numeric value",
|
38
|
+
"splat": null,
|
39
|
+
"default": null,
|
40
|
+
"param_type": "Int"
|
41
|
+
}
|
42
|
+
],
|
43
|
+
"examples": [
|
44
|
+
|
45
|
+
],
|
46
|
+
"ruby": " return '' if value.nil?\n\n value = value.to_i if value.is_a? String\n\n value.ordinalize\n"
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"name": "pluralize",
|
50
|
+
"description": "Returns the plural form of the word in the string",
|
51
|
+
"result": "value in plural form",
|
52
|
+
"category": "inflection",
|
53
|
+
"category_description": "Inflection handling routines, eg. pluralize, singular, ordinalize",
|
54
|
+
"base_class_require": null,
|
55
|
+
"base_class": null,
|
56
|
+
"parameters": [
|
57
|
+
{
|
58
|
+
"name": "value",
|
59
|
+
"description": "value - value to pluralize",
|
60
|
+
"splat": null,
|
61
|
+
"default": null,
|
62
|
+
"param_type": "String"
|
63
|
+
}
|
64
|
+
],
|
65
|
+
"examples": [
|
66
|
+
|
67
|
+
],
|
68
|
+
"ruby": " return '' if value.nil?\n\n value = value.to_s if value.is_a?(Symbol)\n\n value.pluralize\n"
|
69
|
+
},
|
70
|
+
{
|
71
|
+
"name": "pluralize_by_number",
|
72
|
+
"description": "Returns the plural form of the word based on a count",
|
73
|
+
"result": "value and number are used to calculate plural/singular form",
|
74
|
+
"category": "inflection",
|
75
|
+
"category_description": "Inflection handling routines, eg. pluralize, singular, ordinalize",
|
76
|
+
"base_class_require": null,
|
77
|
+
"base_class": null,
|
78
|
+
"parameters": [
|
79
|
+
{
|
80
|
+
"name": "value",
|
81
|
+
"description": "value - value to pluralize",
|
82
|
+
"splat": null,
|
83
|
+
"default": null,
|
84
|
+
"param_type": "String"
|
85
|
+
},
|
86
|
+
{
|
87
|
+
"name": "count",
|
88
|
+
"description": "count used to determine pluralization",
|
89
|
+
"splat": null,
|
90
|
+
"default": null,
|
91
|
+
"param_type": "Int"
|
92
|
+
},
|
93
|
+
{
|
94
|
+
"name": "format",
|
95
|
+
"description": "(Optional) what format should output be. :word, :number_word",
|
96
|
+
"splat": null,
|
97
|
+
"default": null,
|
98
|
+
"param_type": "String"
|
99
|
+
}
|
100
|
+
],
|
101
|
+
"examples": [
|
102
|
+
|
103
|
+
],
|
104
|
+
"ruby": " return '' if value.nil?\n\n count = count.to_i if count.is_a? String\n format = :word if format.nil?\n\n case format.to_sym\n when :number_word, :number_and_word\n \"#{count} #{value.pluralize(count)}\"\n else # aka :word\n value.pluralize(count)\n end\n"
|
105
|
+
},
|
106
|
+
{
|
107
|
+
"name": "singularize",
|
108
|
+
"description": "The reverse of #pluralize, returns the singular form of a word in a string",
|
109
|
+
"result": "plural value turned to singular value",
|
110
|
+
"category": "inflection",
|
111
|
+
"category_description": "Inflection handling routines, eg. pluralize, singular, ordinalize",
|
112
|
+
"base_class_require": null,
|
113
|
+
"base_class": null,
|
114
|
+
"parameters": [
|
115
|
+
{
|
116
|
+
"name": "value",
|
117
|
+
"description": "value - value to singularized",
|
118
|
+
"splat": null,
|
119
|
+
"default": null,
|
120
|
+
"param_type": "String"
|
121
|
+
}
|
122
|
+
],
|
123
|
+
"examples": [
|
124
|
+
|
125
|
+
],
|
126
|
+
"ruby": " return '' if value.nil?\n\n value = value.to_s if value.is_a?(Symbol)\n\n value.singularize\n"
|
127
|
+
}
|
128
|
+
]
|
129
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CategoryBuilder < KDirector::Builders::ActionsBuilder
|
4
|
+
def category(name, description)
|
5
|
+
value = {
|
6
|
+
name: name,
|
7
|
+
description: description
|
8
|
+
}
|
9
|
+
|
10
|
+
add(:categories, value: value)
|
11
|
+
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def save_categories(**opts)
|
16
|
+
k_builder
|
17
|
+
.cd(:builder_data)
|
18
|
+
.add('categories.json', content: to_json, **opts)
|
19
|
+
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def osave_categories(**opts)
|
24
|
+
save_categories(**{ open: true }.merge(opts))
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CategoryDao
|
4
|
+
attr_reader :k_builder
|
5
|
+
attr_reader :load_time
|
6
|
+
attr_reader :data
|
7
|
+
|
8
|
+
def initialize(k_builder)
|
9
|
+
@k_builder = k_builder
|
10
|
+
@load_time = nil
|
11
|
+
@data = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def file_name
|
15
|
+
k_builder.target_folders.join(:builder_data, 'categories.json')
|
16
|
+
end
|
17
|
+
|
18
|
+
def reload?
|
19
|
+
@load_time.nil? || @load_time < File.mtime(file_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_category(name)
|
23
|
+
result = categories.find { |category| category[:name] == name.to_s }
|
24
|
+
|
25
|
+
raise "Category #{name} not found" if result.nil?
|
26
|
+
|
27
|
+
result
|
28
|
+
end
|
29
|
+
|
30
|
+
def categories
|
31
|
+
if reload?
|
32
|
+
@data = JSON.parse(File.read(file_name), symbolize_names: true)
|
33
|
+
@categories = data[:categories]
|
34
|
+
@load_time = File.mtime(file_name)
|
35
|
+
end
|
36
|
+
@categories
|
37
|
+
end
|
38
|
+
end
|
@@ -1,25 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class CategoryDirector < KDirector::Directors::BaseDirector
|
4
|
-
|
5
|
-
value = {
|
6
|
-
name: name,
|
7
|
-
description: description
|
8
|
-
}
|
4
|
+
defaults(builder_type: CategoryBuilder, on_exist: :write, on_action: :execute)
|
9
5
|
|
10
|
-
|
6
|
+
def category(name, description)
|
7
|
+
builder.category(name, description)
|
11
8
|
|
12
9
|
self
|
13
10
|
end
|
14
11
|
|
15
|
-
def
|
16
|
-
|
12
|
+
def generate
|
13
|
+
generate_require_all_cmdlets
|
14
|
+
|
15
|
+
self
|
17
16
|
end
|
18
17
|
|
19
|
-
def save_categories
|
18
|
+
def save_categories(**opts)
|
20
19
|
cd(:builder_data)
|
21
|
-
add('categories.json', content: builder.to_json)
|
20
|
+
add('categories.json', content: builder.to_json, **opts)
|
22
21
|
|
23
22
|
self
|
24
23
|
end
|
24
|
+
|
25
|
+
def osave_categories(**opts)
|
26
|
+
save_categories(**{ open: true }.merge(opts))
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def generate_require_all_cmdlets
|
32
|
+
cd(:lib)
|
33
|
+
add('_.rb',
|
34
|
+
template_file: 'require_all_cmdlets.rb',
|
35
|
+
cmdlets: data_access.cmdlet.all_cmdlets)
|
36
|
+
|
37
|
+
end
|
38
|
+
|
25
39
|
end
|
@@ -1,72 +1,65 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class CmdletBuilder < KDirector::Builders::ActionsBuilder
|
4
|
-
attr_reader :
|
5
|
-
# attr_accessor :actions
|
6
|
-
# attr_accessor :last_action
|
4
|
+
attr_reader :current_cmdlet
|
7
5
|
|
8
6
|
def initialize
|
9
7
|
super
|
10
8
|
|
11
|
-
dom[:
|
12
|
-
dom[:
|
13
|
-
# @actions = []
|
14
|
-
# @last_action = {}
|
9
|
+
dom[:category_key] = nil
|
10
|
+
dom[:cmdlets] = []
|
15
11
|
end
|
16
12
|
|
17
|
-
def
|
18
|
-
dom[:
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
def category_key
|
14
|
+
dom[:category_key]
|
15
|
+
end
|
16
|
+
|
17
|
+
def category_key=(value)
|
18
|
+
set(:category_key, value: value)
|
22
19
|
end
|
23
20
|
|
24
|
-
def
|
25
|
-
dom[:
|
21
|
+
def cmdlets
|
22
|
+
dom[:cmdlets]
|
26
23
|
end
|
27
24
|
|
28
|
-
def
|
29
|
-
@
|
30
|
-
dom[:
|
25
|
+
def add_cmdlet
|
26
|
+
@current_cmdlet = new_cmdlet
|
27
|
+
dom[:cmdlets] << current_cmdlet
|
31
28
|
end
|
32
29
|
|
33
|
-
def
|
34
|
-
@
|
30
|
+
def cmdlet_setting(name, value)
|
31
|
+
@current_cmdlet[name] = value
|
35
32
|
end
|
36
33
|
|
37
|
-
def
|
34
|
+
def add_cmdlet_parameter(name, description, **opts)
|
38
35
|
parameter = {
|
39
36
|
name: name,
|
40
|
-
description: description
|
41
|
-
|
42
|
-
}
|
37
|
+
description: description
|
38
|
+
}.merge(opts)
|
43
39
|
|
44
|
-
@
|
40
|
+
@current_cmdlet[:parameters] << parameter
|
45
41
|
end
|
46
42
|
|
47
|
-
def
|
43
|
+
def add_cmdlet_example(value)
|
48
44
|
lines = value.split("\n")
|
49
45
|
value = lines.map { |line| " # #{line.strip}" }.join("\n")
|
50
46
|
|
51
|
-
@
|
47
|
+
@current_cmdlet[:examples] << value
|
52
48
|
end
|
53
49
|
|
54
|
-
|
55
50
|
private
|
56
51
|
|
57
|
-
def
|
52
|
+
def new_cmdlet
|
53
|
+
category = data_access.category.find_category(category_key)
|
54
|
+
|
58
55
|
{
|
59
56
|
name: nil,
|
60
57
|
description: nil,
|
61
58
|
result: nil,
|
62
|
-
category:
|
63
|
-
category_description:
|
59
|
+
category: category[:name],
|
60
|
+
category_description: category[:description],
|
64
61
|
base_class_require: nil,
|
65
62
|
base_class: nil,
|
66
|
-
example_input_value: nil,
|
67
|
-
example_output_value: nil,
|
68
|
-
test_input_value: nil,
|
69
|
-
test_output_value: nil,
|
70
63
|
parameters: [],
|
71
64
|
examples: []
|
72
65
|
}
|
@@ -1,67 +1,39 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
class
|
3
|
+
class CmdletChild < KDirector::Directors::ChildDirector
|
4
4
|
def initialize(parent, **opts)
|
5
5
|
super(parent, **opts)
|
6
6
|
|
7
|
-
builder.
|
8
|
-
|
9
|
-
# defaults = {
|
10
|
-
# repo_name: opts[:repo_name], # || parent.builder.dom&[:github]&[:repo_name]
|
11
|
-
# username: opts[:username] || default_github_username, # || parent.builder.dom&[:github]&[:username]
|
12
|
-
# organization: opts[:organization] # || parent.builder.dom&[:github]&[:organization]
|
13
|
-
# }
|
7
|
+
builder.add_cmdlet
|
14
8
|
end
|
15
9
|
|
16
10
|
def name(value)
|
17
|
-
builder.
|
11
|
+
builder.cmdlet_setting(:name, value)
|
18
12
|
end
|
19
13
|
|
20
14
|
def description(value)
|
21
|
-
builder.
|
15
|
+
builder.cmdlet_setting(:description, value)
|
22
16
|
end
|
23
17
|
|
24
18
|
def result(value)
|
25
|
-
builder.
|
26
|
-
end
|
27
|
-
|
28
|
-
def category(value)
|
29
|
-
builder.helper_setting(:category, value)
|
19
|
+
builder.cmdlet_setting(:result, value)
|
30
20
|
end
|
31
21
|
|
32
|
-
def
|
33
|
-
builder.
|
22
|
+
def ruby(value)
|
23
|
+
builder.cmdlet_setting(:ruby, value)
|
34
24
|
end
|
35
25
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
# def example_input_value(value)
|
45
|
-
# builder.helper_setting(:example_input_value, value)
|
46
|
-
# end
|
47
|
-
|
48
|
-
# def example_output_value(value)
|
49
|
-
# builder.helper_setting(:example_output_value, value)
|
50
|
-
# end
|
51
|
-
|
52
|
-
# def test_input_value(value)
|
53
|
-
# builder.helper_setting(:test_input_value, value)
|
54
|
-
# end
|
55
|
-
|
56
|
-
# def test_output_value(value)
|
57
|
-
# builder.helper_setting(:test_output_value, value)
|
58
|
-
# end
|
59
|
-
|
60
|
-
def parameter(name, description, splat: false)
|
61
|
-
builder.add_helper_parameter(name, description, splat: splat)
|
26
|
+
def parameter(name, description, splat: nil, default: nil, param_type: 'String')
|
27
|
+
builder.add_cmdlet_parameter(
|
28
|
+
name,
|
29
|
+
description,
|
30
|
+
splat: splat,
|
31
|
+
default: default,
|
32
|
+
param_type: param_type
|
33
|
+
)
|
62
34
|
end
|
63
35
|
|
64
36
|
def example(value)
|
65
|
-
builder.
|
37
|
+
builder.add_cmdlet_example(value)
|
66
38
|
end
|
67
39
|
end
|