new 1.0.9 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjNlNjUyMWY0NjY3ZjBjZThkZTM0MjQwODU1YTllYTNhNjYwZDBlZA==
4
+ ZDY3MTQ0YWIyYTE0NWE3NmQ5OTAxYzViYzNjNzE4ODNhNzM0YmM0ZA==
5
5
  data.tar.gz: !binary |-
6
- NmQ4NmQ4NTUwZWU3ZTAwNmFkZTJkMjUzOTYwN2Y0M2FjMDc2MzExZg==
6
+ M2FkMGUxYmM5MzM4Y2EzYzA0NDg2NGRiODZhNWZkODNkMjY1MDgzOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmE3NjBmODFiNDMxODkzNTFmYTAzMjA5YTlhMzEwZWQ4NDU4MmI0MzhiOTJm
10
- NzczOGVjOWY2Yzk2NzQ5NTI5YThhMGJkZDBiN2U3MzJkNTA4MDFjYTQ1N2Fk
11
- NjM2MzZkZDFhYTUwZDQ3MzFiY2RlZjZjMGQwZmZhZGE4MDlmM2Q=
9
+ MzcwN2E4NWIyZGMyYTVjZTIyMjBlYjk1MmJiNTgwMzMxOTA0NmE2ZGZlOTll
10
+ MmQ5MjZjMjQ2MjJkOWI1NzQ4ZDcxYzIxNmE5ZjUyMWIyNDhjYzc0MzBmZTU2
11
+ NTJhMGNkMTQyZGE2N2NjNDU2YTljNzYzNGRhMmNjYjJiYWVlM2I=
12
12
  data.tar.gz: !binary |-
13
- MzlhMWQ4OWFjYmNhMTQ5YzYxMWNiM2I4OGVlNDA3ZmRkNzViMzM5ODU4ZTYz
14
- MTU0NmIyMGU3YTgwNmFlOGVlNTQ0M2Y5YTA1ZGZlMmU2YmZkODcyMWQ4YzRl
15
- MDI2NzE4ODRlZDJjZDFiNDI1NWY0NjIzMzcxZjZmMDc2ZDFjNDc=
13
+ NzQ4ZDU1NDFhYjg0ZDljNWU4YmY0NzQ0ZmFkYjYxMTI4YWUzNzBlNjkyOWM0
14
+ MjkwOGY0NTUzMTJhYjYxNjdkZTY3ZjE1ZjYwZmY0OTdlNTk5NDBlZTc1ZmRj
15
+ ZDI1OTNhMWQ3MDMwNTNlZTY1NzU4MDY5ZTg5YmE4ZTdhMWJiNDk=
data/lib/new.rb CHANGED
@@ -1,3 +1,7 @@
1
+ #
2
+ # New is the core class that acts as the controller for new
3
+ # It is reponsible for storing the state and globally accessible data
4
+ #
1
5
  require 'active_support/core_ext/hash/deep_merge'
2
6
  require 'yaml'
3
7
 
@@ -1,3 +1,6 @@
1
+ #
2
+ # New::Cli is a class built on Thor for interfacing with the user on the command line
3
+ #
1
4
  require 'active_support/core_ext/hash/reverse_merge'
2
5
  require 'active_support/core_ext/hash/keys'
3
6
  require 'cli_miami'
@@ -196,6 +199,7 @@ class New::Cli < Thor
196
199
  end
197
200
 
198
201
  desc 'tasks', 'List all available tasks'
202
+ option :task, :aliases => ['-t'], :desc => 'Get details for a single task'
199
203
  option :sources, :type => :boolean, :aliases => ['-s'], :default => false, :desc => 'Show/Hide task sources'
200
204
  def tasks args = {}
201
205
  # merge into default options
@@ -207,71 +211,96 @@ class New::Cli < Thor
207
211
 
208
212
  New.load_newfiles if options[:load_newfiles]
209
213
  if options[:load_sources]
210
- S.ay
211
214
  S.ay 'Fetching sources...', :header
212
215
  S.ay "Use the #{'green'.green} value for defining task sources in your Newfile", :indent => 2 if options[:show_source]
213
216
  S.ay
214
217
  New::Source.load_sources
215
218
  end
216
219
 
217
- New::Source.sources.each do |source_name, source|
218
- # determine the widest task & add some padding
219
- longest_task_length = source.tasks.keys.map(&:length).max
220
+ if @options['task']
221
+ task = New::Source.find_task @options['task']
222
+ S.ay task.name.to_s.upcase, :preset => :header, :style => :underline, :padding => 30, :justify => :center
223
+ S.ay "source: #{task.source.name.to_s}", :color => :cyan, :padding => 30, :justify => :center
224
+ S.ay
220
225
 
221
- S.ay source_name.to_s, :indent => 2, :newline => false, :style => :underline
222
- S.ay source.path, :highlight_value
226
+ max_option_length = task.class_options.keys.map(&:length).max
227
+ task.class_options.each do |name, settings|
228
+ S.ay name.to_s, :preset => :highlight_key, :padding => max_option_length, :style => :underline
229
+ S.ay settings[:description], :highlight_value
223
230
 
224
- source.tasks.each do |task_name, task|
225
- if options[:show_source]
226
- padding = longest_task_length + source_name.to_s.length + 2
227
- S.ay "#{source_name}##{task_name}", :preset => :header, :newline => false, :indent => 2, :padding => padding, :justify => :ljust
228
- else
229
- padding = longest_task_length + 2
230
- S.ay task_name.to_s, :preset => :header, :newline => false, :indent => 2, :padding => padding, :justify => :ljust
231
+ S.ay 'Type:', :preset => :highlight_key, :padding => max_option_length + 13
232
+ S.ay "#{settings[:type] || 'String'}", :highlight_value
233
+
234
+ if settings[:required]
235
+ S.ay 'Required:', :preset => :highlight_key, :padding => max_option_length + 13
236
+ S.ay 'true', :highlight_value
237
+ elsif settings[:default]
238
+ S.ay 'Default:', :preset => :highlight_key, :padding => max_option_length + 13
239
+ S.ay settings[:default].to_s, :highlight_value
231
240
  end
232
- S.ay task.description, :indent => 2
241
+
242
+ if settings[:validation]
243
+ S.ay 'Validation:', :preset => :highlight_key, :padding => max_option_length + 13
244
+ S.ay settings[:validation].to_s, :highlight_value
245
+ end
246
+
247
+ S.ay
233
248
  end
249
+ else
250
+ New::Source.sources.each do |source_name, source|
251
+ # determine the widest task & add some padding
252
+ longest_task_length = source.tasks.keys.map(&:length).max
253
+
254
+ S.ay source_name.to_s, :indent => 2, :newline => false, :style => :underline
255
+ S.ay source.path, :highlight_value
256
+
257
+ source.tasks.each do |task_name, task|
258
+ if options[:show_source]
259
+ padding = longest_task_length + source_name.to_s.length + 2
260
+ S.ay "#{source_name}##{task_name}", :preset => :header, :newline => false, :indent => 2, :padding => padding, :justify => :ljust
261
+ else
262
+ padding = longest_task_length + 2
263
+ S.ay task_name.to_s, :preset => :header, :newline => false, :indent => 2, :padding => padding, :justify => :ljust
264
+ end
265
+ S.ay task.description, :indent => 2
266
+ end
234
267
 
235
- S.ay
268
+ S.ay
269
+ end
236
270
  end
237
271
  end
238
272
 
239
273
  desc 'release', 'Release a new version of your project'
274
+ option :bump, :aliases => ['-b'], :enum => ['M', 'm', 'p'], :desc => 'Version part to bump'
240
275
  option :verbose, :type => :boolean, :aliases => ['-v'], :default => false, :desc => 'Verbose mode'
241
276
  option :skip, :type => :array, :aliases => ['-s'], :default => [], :desc => 'Tasks to skip for this release'
242
277
  def release
243
- New.set_verbose if @options['verbose']
244
278
  New.set_cli
279
+ New.set_verbose if @options['verbose']
245
280
  New.load_newfiles
246
281
 
247
- # request the version to bump
248
282
  S.ay
249
- S.ay 'Releasing a new version of: ', :highlight_key
250
- S.ay New.new_object[:name], :highlight_value
251
- S.ay 'What do you want to bump: ', :highlight_key
252
- S.ay "[#{'Mmp'.green}] (#{'M'.green}ajor / #{'m'.green}inor / #{'p'.green}atch)", :preset => :highlight_value, :color => :white
283
+ S.ay 'Releasing a new version of:', :highlight_key
284
+ S.ay New.new_object[:name].to_s, :highlight_value
285
+
253
286
  version = Semantic::Version.new New.new_object[:version]
254
- version_bump_part = nil
255
- until version_bump_part
256
- S.ay 'Current Version:', :highlight_key
257
- A.sk version.to_s, :highlight_value do |response|
258
- version_bump_part = case response
259
- when 'M'
260
- version.major += 1
261
- version.minor = 0
262
- version.patch = 0
263
- when 'm'
264
- version.minor += 1
265
- version.patch = 0
266
- when 'p'
267
- version.patch += 1
268
- else
269
- S.ay 'You must choose from [Mmp]', :error
270
- nil
287
+ S.ay 'Current Version:', :highlight_key
288
+ S.ay version.to_s, :highlight_value
289
+
290
+ if @options['bump']
291
+ version = bump_version version, @options['bump']
292
+ else
293
+ S.ay 'What do you want to bump:', :highlight_key
294
+ S.ay "[#{'Mmp'.green}] (#{'M'.green}ajor / #{'m'.green}inor / #{'p'.green}atch)", :preset => :highlight_value, :color => :white
295
+ version_bump_part = nil
296
+ until version_bump_part
297
+ A.sk '', :prompt do |response|
298
+ version = version_bump_part = bump_version version, response
271
299
  end
272
300
  end
273
301
  end
274
- S.ay 'New Version: ', :highlight_key
302
+
303
+ S.ay 'New Version:', :highlight_key
275
304
  S.ay version.to_s, :highlight_value
276
305
  S.ay
277
306
 
@@ -297,7 +326,7 @@ class New::Cli < Thor
297
326
  desc 'version', 'Show the current version'
298
327
  def version
299
328
  New.load_newfiles
300
- S.ay New.new_object[:name], :highlight_key
329
+ S.ay New.new_object[:name], :preset => :highlight_key, :padding => 0, :indent => 0
301
330
  S.ay New.new_object[:version], :highlight_value
302
331
  end
303
332
 
@@ -405,11 +434,7 @@ class New::Cli < Thor
405
434
 
406
435
  # convert array to hash of Strings
407
436
  if validation.is_a? Array
408
- validation_hash = {}
409
- validation.each do |v|
410
- validation_hash[v.to_sym] = String
411
- end
412
- validation = validation_hash
437
+ validation = array_to_hash validation
413
438
  end
414
439
 
415
440
  if validation.is_a? Hash
@@ -417,7 +442,7 @@ class New::Cli < Thor
417
442
 
418
443
  user_response = nil
419
444
  until user_response == 'n'
420
- S.ay "#{user_array.length} objects created: ", :indent => 2, :newline => false
445
+ S.ay "#{user_array.length} objects created:", :indent => 2, :newline => false
421
446
  S.ay user_array.join(', '), :highlight_value
422
447
  A.sk 'Press ENTER to create another object. Enter `n` to stop.', :prompt do |response|
423
448
  if response == 'n'
@@ -461,11 +486,7 @@ class New::Cli < Thor
461
486
 
462
487
  # convert array to hash of Strings
463
488
  if validation.is_a? Array
464
- validation_hash = {}
465
- validation.each do |v|
466
- validation_hash[v.to_sym] = String
467
- end
468
- validation = validation_hash
489
+ validation = array_to_hash validation
469
490
  end
470
491
 
471
492
  # get user values for required validation keys
@@ -535,6 +556,44 @@ class New::Cli < Thor
535
556
 
536
557
  return user_hash
537
558
  end
559
+
560
+ # convert an array to a hash
561
+ # uses the array elements as hash keys, and sets the value to String
562
+ # @param array [Array] any array
563
+ # @return [Hash]
564
+ #
565
+ def array_to_hash array
566
+ array_hash = {}
567
+ array.each do |v|
568
+ array_hash[v.to_sym] = String
569
+ end
570
+
571
+ return array_hash
572
+ end
573
+
574
+ # bump a semantic version
575
+ # @param version [Semantic::Version] a Semantic::Version object
576
+ # @param part [String] a supported part character [Mmp]
577
+ # @return [Semantic::Version] a new Semantic::Version object
578
+ #
579
+ def bump_version version, part
580
+ case part
581
+ when 'M'
582
+ version.major += 1
583
+ version.minor = 0
584
+ version.patch = 0
585
+ when 'm'
586
+ version.minor += 1
587
+ version.patch = 0
588
+ when 'p'
589
+ version.patch += 1
590
+ else
591
+ S.ay 'You must choose from [Mmp]', :error
592
+ return nil
593
+ end
594
+
595
+ return version
596
+ end
538
597
  end
539
598
 
540
599
  default_task :release
@@ -1,5 +1,7 @@
1
+ #
2
+ # New::Source represents a source (local or remote) that contains new tasks
3
+ #
1
4
  require 'sourcerer'
2
-
3
5
  class New::Source
4
6
  #
5
7
  # CLASS METHODS
@@ -1,3 +1,6 @@
1
+ #
2
+ # New::Task is the base class that all custom tasks need to inherit from
3
+ #
1
4
  class New::Task
2
5
  extend New::Validation
3
6
 
@@ -65,6 +68,9 @@ class New::Task
65
68
  end
66
69
 
67
70
  # run a system command
71
+ # @param command [String] the system command to run
72
+ # @return [Boolean] true/false based on if the exit status of the command
73
+ #
68
74
  def run_command command
69
75
  # if verbose, dont redirect output to null
70
76
  command += ' >> /dev/null 2>&1' unless New.verbose
@@ -1,3 +1,6 @@
1
+ #
2
+ # New::Validation is a module for all validation methods
3
+ #
1
4
  module New::Validation
2
5
  # validate a task option using a task and its associated options
3
6
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: new
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brewster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-06 00:00:00.000000000 Z
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler