cri 2.13.0 → 2.14.0

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: 2aa633b78bf3bb39d2ddc9c5abc1ce94f27dd57bb1d130336acc58c1ae83ffcf
4
- data.tar.gz: 2cc7102d387382bdfe15a0ccdb080d92c989f77716d217c0899a3ec688090886
3
+ metadata.gz: e4990c5f7f5168cb66f3e434512976721a3dc2b1e93b0a88306c58106aacb21c
4
+ data.tar.gz: 6866a5179a3c338c905e5d50cb89391b12608e7d0d246def19a3e0e5971fa6f8
5
5
  SHA512:
6
- metadata.gz: 82e32293ba6c802449eeb1731742250bb5f5503cfdd1d05d8fd2e1b113ee3704e39a684cf9d87adf02c26becb95209bb34f32bc749e09017fb31b10dc5abde72
7
- data.tar.gz: 5a51c230c68d3a4612eaae905605448997133418b12a703a1b154ac6c39a7e67e94305bbd680edfd6332b8fa806d9e3b94eb7d7c54529b0bc868f081f295d246
6
+ metadata.gz: cd21b56d57ce4356a19a4875ada15f13c7019f739ea7267a104610c3ad33557dff506c589e4b70929d20d77a938d2fb71e963ca5b2a908ad54a7ac6e89dea4e1
7
+ data.tar.gz: b7dfaf7409934b132cc640ca21a0128af76ea1835986627ea68d83922233fe6b14b8e8a296143ed6d545beb7c408ea028cc8353aca8d2b4371171d5c01ba02cb
data/Gemfile.lock ADDED
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cri (2.13.0)
5
+ colored (~> 1.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ asciidoctor (1.5.7.1)
11
+ ast (2.4.0)
12
+ colored (1.2)
13
+ coveralls (0.8.22)
14
+ json (>= 1.8, < 3)
15
+ simplecov (~> 0.16.1)
16
+ term-ansicolor (~> 1.3)
17
+ thor (~> 0.19.4)
18
+ tins (~> 1.6)
19
+ docile (1.3.1)
20
+ jaro_winkler (1.5.1)
21
+ json (2.1.0)
22
+ minitest (5.11.3)
23
+ parallel (1.12.1)
24
+ parser (2.5.1.2)
25
+ ast (~> 2.4.0)
26
+ powerpack (0.1.2)
27
+ rainbow (3.0.0)
28
+ rake (12.3.1)
29
+ rubocop (0.58.2)
30
+ jaro_winkler (~> 1.5.1)
31
+ parallel (~> 1.10)
32
+ parser (>= 2.5, != 2.5.1.1)
33
+ powerpack (~> 0.1)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ ruby-progressbar (~> 1.7)
36
+ unicode-display_width (~> 1.0, >= 1.0.1)
37
+ ruby-progressbar (1.10.0)
38
+ simplecov (0.16.1)
39
+ docile (~> 1.1)
40
+ json (>= 1.8, < 3)
41
+ simplecov-html (~> 0.10.0)
42
+ simplecov-html (0.10.2)
43
+ term-ansicolor (1.6.0)
44
+ tins (~> 1.0)
45
+ thor (0.19.4)
46
+ tins (1.16.3)
47
+ unicode-display_width (1.4.0)
48
+ yard (0.9.16)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ asciidoctor
55
+ bundler (~> 1.6)
56
+ coveralls
57
+ cri!
58
+ minitest
59
+ rake
60
+ rubocop
61
+ yard
62
+
63
+ BUNDLED WITH
64
+ 1.16.4
data/NEWS.md CHANGED
@@ -1,5 +1,10 @@
1
- Cri News
2
- ========
1
+ # Cri News
2
+
3
+ ## 2.14.0
4
+
5
+ Features:
6
+
7
+ * Added `Cri::Command.load_file`
3
8
 
4
9
  ## 2.13.0
5
10
 
data/README.md CHANGED
@@ -343,6 +343,64 @@ command has subcommands, and no subcommands are otherwise explicitly specified:
343
343
  default_subcommand 'compile'
344
344
  ```
345
345
 
346
+ ### Loading commands from separate files
347
+
348
+ You can use `Cri::Command.load_file` to load a command from a file.
349
+
350
+ For example, given the file _commands/check.rb_ with the following contents:
351
+
352
+ ```ruby
353
+ name 'check'
354
+ usage 'check'
355
+ summary 'runs all checks'
356
+ description '…'
357
+
358
+ run do |opts, args, cmd|
359
+ puts "Running checks…"
360
+ end
361
+ ```
362
+
363
+ To load this command:
364
+
365
+ ```ruby
366
+ Cri::Command.load_file('commands/check.rb')
367
+ ```
368
+
369
+ `Cri::Command.load_file` expects the file to be in UTF-8.
370
+
371
+ You can also use it to load subcommands:
372
+
373
+ ```ruby
374
+ root_cmd = Cri::Command.load_file('commands/nanoc.rb')
375
+ root_cmd.add_command(Cri::Command.load_file('commands/comile.rb'))
376
+ root_cmd.add_command(Cri::Command.load_file('commands/view.rb'))
377
+ root_cmd.add_command(Cri::Command.load_file('commands/check.rb'))
378
+ ```
379
+
380
+ #### Automatically inferring command names
381
+
382
+ Pass `infer_name: true` to `Cri::Command.load_file` to use the file basename as the name of the command.
383
+
384
+ For example, given a file _commands/check.rb_ with the following contents:
385
+
386
+ ```ruby
387
+ usage 'check'
388
+ summary 'runs all checks'
389
+ description '…'
390
+
391
+ run do |opts, args, cmd|
392
+ puts "Running checks…"
393
+ end
394
+ ```
395
+
396
+ To load this command and infer the name:
397
+
398
+ ```ruby
399
+ cmd = Cri::Command.load_file('commands/check.rb', infer_name: true)
400
+ ```
401
+
402
+ `cmd.name` will be `check`, derived from the filename.
403
+
346
404
  ## Contributors
347
405
 
348
406
  * Bart Mesuere
data/lib/cri/command.rb CHANGED
@@ -132,6 +132,22 @@ module Cri
132
132
  dsl.command
133
133
  end
134
134
 
135
+ # Creates a new command using a DSL, from code defined in the given filename.
136
+ #
137
+ # @param [String] filename The filename that contains the command definition
138
+ # as a string
139
+ #
140
+ # @return [Cri::Command] The newly defined command
141
+ def self.load_file(filename, infer_name: false)
142
+ code = File.read(filename, encoding: 'UTF-8')
143
+ define(code, filename).tap do |cmd|
144
+ if infer_name
145
+ command_name = File.basename(filename, '.rb')
146
+ cmd.modify { name command_name }
147
+ end
148
+ end
149
+ end
150
+
135
151
  # Returns a new command that has support for the `-h`/`--help` option and
136
152
  # also has a `help` subcommand. It is intended to be modified (adding
137
153
  # name, summary, description, other subcommands, …)
data/lib/cri/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Cri
4
4
  # The current Cri version.
5
- VERSION = '2.13.0'
5
+ VERSION = '2.14.0'
6
6
  end
data/test/test_command.rb CHANGED
@@ -756,5 +756,79 @@ module Cri
756
756
  assert_equal [], lines(out)
757
757
  assert_equal ['moo: incorrect number of arguments given: expected 0, but got 1'], lines(err)
758
758
  end
759
+
760
+ def test_load_file
761
+ Dir.mktmpdir('foo') do |dir|
762
+ filename = "#{dir}/moo.rb"
763
+ File.write(filename, <<~CMD)
764
+ name 'moo'
765
+ usage 'dunno whatever'
766
+ summary 'does stuff'
767
+ description 'This command does a lot of stuff.'
768
+ no_params
769
+
770
+ run do |_opts, args|
771
+ end
772
+ CMD
773
+
774
+ cmd = Cri::Command.load_file(filename)
775
+ assert_equal('moo', cmd.name)
776
+ end
777
+ end
778
+
779
+ def test_load_file_infer_name_false
780
+ Dir.mktmpdir('foo') do |dir|
781
+ filename = "#{dir}/moo.rb"
782
+ File.write(filename, <<~CMD)
783
+ usage 'dunno whatever'
784
+ summary 'does stuff'
785
+ description 'This command does a lot of stuff.'
786
+ no_params
787
+
788
+ run do |_opts, args|
789
+ end
790
+ CMD
791
+
792
+ cmd = Cri::Command.load_file(filename)
793
+ assert_equal(nil, cmd.name)
794
+ end
795
+ end
796
+
797
+ def test_load_file_infer_name
798
+ Dir.mktmpdir('foo') do |dir|
799
+ filename = "#{dir}/moo.rb"
800
+ File.write(filename, <<~CMD)
801
+ usage 'dunno whatever'
802
+ summary 'does stuff'
803
+ description 'This command does a lot of stuff.'
804
+ no_params
805
+
806
+ run do |_opts, args|
807
+ end
808
+ CMD
809
+
810
+ cmd = Cri::Command.load_file(filename, infer_name: true)
811
+ assert_equal('moo', cmd.name)
812
+ end
813
+ end
814
+
815
+ def test_load_file_infer_name_double
816
+ Dir.mktmpdir('foo') do |dir|
817
+ filename = "#{dir}/moo.rb"
818
+ File.write(filename, <<~CMD)
819
+ name 'oink'
820
+ usage 'dunno whatever'
821
+ summary 'does stuff'
822
+ description 'This command does a lot of stuff.'
823
+ no_params
824
+
825
+ run do |_opts, args|
826
+ end
827
+ CMD
828
+
829
+ cmd = Cri::Command.load_file(filename, infer_name: true)
830
+ assert_equal('moo', cmd.name)
831
+ end
832
+ end
759
833
  end
760
834
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cri
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.0
4
+ version: 2.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Defreyne
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-17 00:00:00.000000000 Z
11
+ date: 2018-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored
@@ -50,6 +50,7 @@ extra_rdoc_files:
50
50
  files:
51
51
  - CODE_OF_CONDUCT.md
52
52
  - Gemfile
53
+ - Gemfile.lock
53
54
  - LICENSE
54
55
  - NEWS.md
55
56
  - README.md