rigit 0.1.6 → 0.1.7

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
  SHA256:
3
- metadata.gz: 115d92a220f39a44c6ade5078aa76be9a7dc716361ea2926f85d1ba80c588354
4
- data.tar.gz: f1446dd700308179e588082abfe736e9f48101468e687273158aa2285920547c
3
+ metadata.gz: dd2a2c78d7c9698965042e42736818edfbf35b015ee4e5f76fbf410dd0c6d4e4
4
+ data.tar.gz: c88d8463c4992fc279cf579a0cc1422f71ebd875e58631e25d940991d88a0708
5
5
  SHA512:
6
- metadata.gz: 0c90c6ec8a808dea93f11f69c808719d792e1e10ae452aab7d9099b2b441ec1be6c27d68e92c7e194a03d15c1f85de6e400a90893f21699baeb593e7680b894f
7
- data.tar.gz: 0f67a31c66197d9a0853582a36f1669a3fc3d032bbf85d809118fc1e330b9531569502071a60377c6c1f3df7178c55e778fa9139cfe3e5d2f9e8bd2b0d8667ee
6
+ metadata.gz: 766579f3d737a555cc26a8e4f47f9480f969d0938f15d8f94d6582f1b66d8cbc3fe2dd82a1dafa193c19ebdd1591a45a18768db9ba8bb0fc96bed170b184917b
7
+ data.tar.gz: fd7b722589b4b7f46cb25d414b75f939ed316288cb3a37f258391e5a692893694f087d95af782152241770afe53fa0a9e18d034437a30299b232a88b3f05546f
data/README.md CHANGED
@@ -33,6 +33,7 @@ Table of Contents
33
33
  * [Executing commands before/after scaffolding](#executing-commands-beforeafter-scaffolding)
34
34
  * [Scaffolding parameters](#scaffolding-parameters)
35
35
  * [Conditional parameters](#conditional-parameters)
36
+ * [Calculated parameters](#calculated-parameters)
36
37
 
37
38
  Installation
38
39
  --------------------------------------------------
@@ -244,8 +245,13 @@ params:
244
245
  type: select
245
246
  list: [irb, pry]
246
247
  condition: console=yes
248
+
249
+ uppercase_name:
250
+ type: ruby
251
+ code: input[:name].upcase
247
252
  ```
248
253
 
254
+
249
255
  #### Showing messages before/after scaffolding
250
256
 
251
257
  Use the `intro` and `outro` options to show short message that will be
@@ -261,6 +267,7 @@ intro: Welcome to my blue !txtblu!rig!txtrst!`
261
267
  outro: Installation completed successfully
262
268
  ```
263
269
 
270
+
264
271
  #### Executing commands before/after scaffolding
265
272
 
266
273
  Use the `before` and `after` options to specify one or more commands to
@@ -280,6 +287,7 @@ after:
280
287
  "Run setup script": "myscript %{name}"
281
288
  ```
282
289
 
290
+
283
291
  #### Scaffolding parameters
284
292
 
285
293
  The `params` option contains a list of parameters required by the rig.
@@ -288,13 +296,14 @@ Each definition in the `params` key should start with the name of the
288
296
  variable (`name`, `console` and `console_type` in the above example), and
289
297
  contain the below specifications:
290
298
 
291
- | Key | Purpose |
292
- |-------------|----------------------------------------------------------|
293
- | `prompt` | The text to display when asking for user input |
294
- | `type` | The variable tyoe. Can be `yesno`, `text` or `select` |
295
- | `default` | The default value. When using `yesno`, use `yes` or `no` |
296
- | `list` | An array of allowed options (only used in `select` type) |
297
- | `condition` | Optional `key=value`. See [conditional parameters](#conditional-parameters) below |
299
+ Key | Purpose
300
+ -------------|--------------------------------------------------------------
301
+ `prompt` | The text to display when asking for user input
302
+ `type` | The variable tyoe. Can be `yesno`, `text`, `select` or `ruby`
303
+ `default` | The default value. When using `yesno`, use `yes` or `no`
304
+ `list` | An array of allowed options (only used in `select` type)
305
+ `condition` | Optional `key=value`. See [conditional parameters](#conditional-parameters) below
306
+ `code` | A ruby code to evaluate (only used in `ruby` type). See [calculated parameters](#calculated-parameters) below
298
307
 
299
308
  Example:
300
309
 
@@ -306,6 +315,7 @@ params:
306
315
  default: project
307
316
  ```
308
317
 
318
+
309
319
  #### Conditional parameters
310
320
 
311
321
  You can configure some of the parameters to prompt the user for input based
@@ -332,6 +342,33 @@ params:
332
342
  list: [irb, pry]
333
343
  condition: console=yes
334
344
  ```
345
+
346
+
347
+ #### Calculated parameters
348
+
349
+ You can define a parameter that is calculated with a piece of ruby code.
350
+
351
+ This parameter may or may not use values from previous input parameters.
352
+
353
+ In the below example, the `constant_name` parameter will be the uppercase
354
+ version of the `name` parameter:
355
+
356
+ Example:
357
+
358
+ ```yaml
359
+ params:
360
+ name:
361
+ type: ruby
362
+ code: |
363
+ "bob"
364
+
365
+ constant_name:
366
+ type: ruby
367
+ code: |
368
+ input[:name].upcase
369
+ ```
370
+
371
+
335
372
  ---
336
373
 
337
374
  [example-rig]: https://github.com/DannyBen/example-rig
@@ -135,11 +135,11 @@ module Rigit::Commands
135
135
  end
136
136
 
137
137
  def verify_target_dir
138
- if !Dir.empty? target_dir
139
- dirstring = target_dir == '.' ? 'Current directory' : "Directory '#{target_dir}'"
140
- continue = tty_prompt.yes? "#{dirstring} is not empty. Continue anyway?", default: false
141
- raise Rigit::Exit, "Goodbye" unless continue
142
- end
138
+ return if Dir.empty?(target_dir) or force
139
+
140
+ dirstring = target_dir == '.' ? 'Current directory' : "Directory '#{target_dir}'"
141
+ continue = tty_prompt.yes? "#{dirstring} is not empty. Continue anyway?", default: false
142
+ raise Rigit::Exit, "Goodbye" unless continue
143
143
  end
144
144
  end
145
145
  end
@@ -6,7 +6,7 @@ module Rigit
6
6
  # from the rig config file), and asks the user for input one by one, while
7
7
  # considering prefilled values.
8
8
  class Prompt
9
- attr_reader :params
9
+ attr_reader :params, :input
10
10
 
11
11
  def initialize(params)
12
12
  @params = params
@@ -16,12 +16,12 @@ module Rigit
16
16
  # used for values, and skip asking the user to provide answers for the
17
17
  # ones that are prefilled.
18
18
  def get_input(prefill={})
19
- result = {}
19
+ @input = {}
20
20
  params.each do |key, spec|
21
- next if skip_by_condition? spec, result
22
- result[key] = prefill.has_key?(key) ? prefill[key] : ask(spec)
21
+ next if skip_by_condition? spec
22
+ @input[key] = prefill.has_key?(key) ? prefill[key] : ask(spec)
23
23
  end
24
- result
24
+ @input
25
25
  end
26
26
 
27
27
  private
@@ -37,15 +37,17 @@ module Rigit
37
37
  prompt.ask text, default: default
38
38
  when 'select'
39
39
  prompt.select text, param.list, marker: '>'
40
+ when 'ruby'
41
+ instance_eval param.code
40
42
  else
41
43
  raise ConfigError, "Unknown type '#{param[:type]}'"
42
44
  end
43
45
  end
44
46
 
45
- def skip_by_condition?(spec, filled_values)
47
+ def skip_by_condition?(spec)
46
48
  return unless spec.has_key? :condition
47
49
  key, value = spec.condition.split '='
48
- filled_values[key.to_sym] != value
50
+ input[key.to_sym] != value
49
51
  end
50
52
 
51
53
  def prompt
@@ -1,3 +1,3 @@
1
1
  module Rigit
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rigit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-11 00:00:00.000000000 Z
11
+ date: 2018-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: super_docopt