samovar 2.1.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,41 +4,39 @@
4
4
 
5
5
  Samovar is a modern framework for building command-line tools and applications. It provides a declarative class-based DSL for building command-line parsers that include automatic documentation generation. It helps you keep your functionality clean and isolated where possible.
6
6
 
7
- [![Build Status](https://secure.travis-ci.org/ioquatix/samovar.svg)](http://travis-ci.org/ioquatix/samovar)
8
- [![Code Climate](https://codeclimate.com/github/ioquatix/samovar.svg)](https://codeclimate.com/github/ioquatix/samovar)
9
- [![Coverage Status](https://coveralls.io/repos/ioquatix/samovar/badge.svg)](https://coveralls.io/r/ioquatix/samovar)
7
+ [![Development Status](https://github.com/ioquatix/samovar/workflows/Test/badge.svg)](https://github.com/ioquatix/samovar/actions?workflow=Test)
10
8
 
11
9
  ## Motivation
12
10
 
13
- I've been using [Trollop](https://github.com/ManageIQ/trollop) and while it's not bad, it's hard to use for sub-commands in a way that generates nice documentation. It also has pretty limited support for complex command lines (e.g. nested commands, splits, matching tokens, etc). Samovar is a high level bridge between the command line and your code: it generates decent documentation, maps nicely between the command line syntax and your functions, and supports sub-commands using classes which are easy to compose.
11
+ I've been using [Optimist](https://github.com/ManageIQ/optimist) and while it's not bad, it's hard to use for sub-commands in a way that generates nice documentation. It also has pretty limited support for complex command lines (e.g. nested commands, splits, matching tokens, etc). Samovar is a high level bridge between the command line and your code: it generates decent documentation, maps nicely between the command line syntax and your functions, and supports sub-commands using classes which are easy to compose.
14
12
 
15
13
  One of the other issues I had with existing frameworks is testability. Most frameworks expect to have some pretty heavy logic directly in the binary executable, or at least don't structure your code in a way which makes testing easy. Samovar structures your command processing logic into classes which can be easily tested in isolation, which means that you can mock up and [spec your command-line executables easily](https://github.com/ioquatix/teapot/blob/master/spec/teapot/command_spec.rb).
16
14
 
17
15
  ## Examples
18
16
 
19
- - [Teapot](https://github.com/ioquatix/teapot/blob/master/lib/teapot/command.rb) is a build system and uses multiple top-level commands.
20
- - [Utopia](https://github.com/ioquatix/utopia/blob/master/lib/utopia/command.rb) is a web application platform and uses nested commands.
21
- - [Synco](https://github.com/ioquatix/synco/blob/master/lib/synco/command.rb) is a backup tool and sends commands across the network and has lots of options with default values.
17
+ - [Teapot](https://github.com/ioquatix/teapot/blob/master/lib/teapot/command.rb) is a build system and uses multiple top-level commands.
18
+ - [Utopia](https://github.com/ioquatix/utopia/blob/master/lib/utopia/command.rb) is a web application platform and uses nested commands.
19
+ - [Synco](https://github.com/ioquatix/synco/blob/master/lib/synco/command.rb) is a backup tool and sends commands across the network and has lots of options with default values.
22
20
 
23
21
  ## Installation
24
22
 
25
23
  Add this line to your application's Gemfile:
26
24
 
27
- gem 'samovar'
25
+ gem 'samovar'
28
26
 
29
27
  And then execute:
30
28
 
31
- $ bundle
29
+ $ bundle
32
30
 
33
31
  Or install it yourself as:
34
32
 
35
- $ gem install samovar
33
+ $ gem install samovar
36
34
 
37
35
  ## Usage
38
36
 
39
37
  Generally speaking, you should create `Command` classes that represent specific functions in your program. The top level command might look something like this:
40
38
 
41
- ```ruby
39
+ ``` ruby
42
40
  require 'samovar'
43
41
 
44
42
  class List < Samovar::Command
@@ -72,7 +70,7 @@ Application.call # Defaults to ARGV.
72
70
 
73
71
  ### Basic Options
74
72
 
75
- ```ruby
73
+ ``` ruby
76
74
  require 'samovar'
77
75
 
78
76
  class Application < Samovar::Command
@@ -101,7 +99,7 @@ application.options[:things] # ['x', 'y', 'z']
101
99
 
102
100
  ### Nested Commands
103
101
 
104
- ```ruby
102
+ ``` ruby
105
103
  require 'samovar'
106
104
 
107
105
  class Create < Samovar::Command
@@ -128,7 +126,7 @@ Application.new(['create']).invoke
128
126
 
129
127
  ### ARGV Splits
130
128
 
131
- ```ruby
129
+ ``` ruby
132
130
  require 'samovar'
133
131
 
134
132
  class Application < Samovar::Command
@@ -143,7 +141,7 @@ application.argv # ['apples', 'oranges', 'feijoas']
143
141
 
144
142
  ### Parsing Tokens
145
143
 
146
- ```ruby
144
+ ``` ruby
147
145
  require 'samovar'
148
146
 
149
147
  class Application < Samovar::Command
@@ -162,13 +160,13 @@ application.cakes # ['chocolate cake', 'fruit cake']
162
160
 
163
161
  Given a custom `Samovar::Command` subclass, you can instantiate it with options:
164
162
 
165
- ```ruby
163
+ ``` ruby
166
164
  application = Application['--root', path]
167
165
  ```
168
166
 
169
167
  You can also duplicate an existing command instance with additions/changes:
170
168
 
171
- ```ruby
169
+ ``` ruby
172
170
  concurrent_application = application['--threads', 12]
173
171
  ```
174
172
 
@@ -176,64 +174,50 @@ These forms can be useful when invoking one command from another, or in unit tes
176
174
 
177
175
  ## Contributing
178
176
 
179
- 1. Fork it
180
- 2. Create your feature branch (`git checkout -b my-new-feature`)
181
- 3. Commit your changes (`git commit -am 'Add some feature'`)
182
- 4. Push to the branch (`git push origin my-new-feature`)
183
- 5. Create new Pull Request
177
+ We welcome contributions to this project.
184
178
 
185
- ### Future Work
179
+ 1. Fork it.
180
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
181
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
182
+ 4. Push to the branch (`git push origin my-new-feature`).
183
+ 5. Create new Pull Request.
186
184
 
187
- #### Multi-value Options
185
+ ### Developer Certificate of Origin
186
+
187
+ This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
188
+
189
+ ### Contributor Covenant
190
+
191
+ This project is governed by [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
192
+
193
+ ## Future Work
194
+
195
+ ### Multi-value Options
188
196
 
189
197
  Right now, options can take a single argument, e.g. `--count <int>`. Ideally, we support a specific sub-parser defined by the option, e.g. `--count <int...>` or `--tag <section> <tags...>`. These would map to specific parsers using `Samovar::One` and `Samovar::Many` internally.
190
198
 
191
- #### Global Options
199
+ ### Global Options
192
200
 
193
201
  Options can only be parsed at the place they are explicitly mentioned, e.g. a command with sub-commands won't parse an option added to the end of the command:
194
202
 
195
- ```ruby
203
+ ``` ruby
196
204
  command list --help
197
205
  ```
198
206
 
199
207
  One might reasonably expect this to parse but it isn't so easy to generalize this:
200
208
 
201
- ```ruby
209
+ ``` ruby
202
210
  command list -- --help
203
211
  ```
204
212
 
205
213
  In this case, do we show help? Some effort is required to disambiguate this. Initially, it makes sense to keep things as simple as possible. But, it might make sense for some options to be declared in a global scope, which are extracted before parsing begins. I'm not sure if this is really a good idea. It might just be better to give good error output in this case (you specified an option but it was in the wrong place).
206
214
 
207
- #### Shell Auto-completion
215
+ ### Shell Auto-completion
208
216
 
209
217
  Because of the structure of the Samovar command parser, it should be possible to generate a list of all possible tokens at each point. Therefore, semantically correct tab completion should be possible.
210
218
 
211
219
  As a secondary to this, it would be nice if `Samovar::One` and `Samovar::Many` could take a list of potential tokens so that auto-completion could give meaningful suggestions, and possibly improved validation.
212
220
 
213
- #### Short/Long Help
221
+ ### Short/Long Help
214
222
 
215
223
  It might be interesting to explore whether it's possible to have `-h` and `--help` do different things. This could include command specific help output, more detailed help output (similar to a man page), and other useful help related tasks.
216
-
217
- ## License
218
-
219
- Released under the MIT license.
220
-
221
- Copyright, 2016, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
222
-
223
- Permission is hereby granted, free of charge, to any person obtaining a copy
224
- of this software and associated documentation files (the "Software"), to deal
225
- in the Software without restriction, including without limitation the rights
226
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
227
- copies of the Software, and to permit persons to whom the Software is
228
- furnished to do so, subject to the following conditions:
229
-
230
- The above copyright notice and this permission notice shall be included in
231
- all copies or substantial portions of the Software.
232
-
233
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
234
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
235
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
236
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
237
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
238
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
239
- THE SOFTWARE.
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,17 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: samovar
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
- autorequire:
8
+ - Gabriel Mazetto
9
+ autorequire:
9
10
  bindir: bin
10
- cert_chain: []
11
- date: 2020-01-23 00:00:00.000000000 Z
11
+ cert_chain:
12
+ - |
13
+ -----BEGIN CERTIFICATE-----
14
+ MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
15
+ ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
16
+ CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
17
+ MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
18
+ MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
19
+ bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
20
+ igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
21
+ 9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
22
+ sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
23
+ e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN
24
+ XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrVm9upSc0ss
25
+ RZ6qwOQmXCo/lLcDUxJAgG95cPw//sI00tZan75VgsGzSWAOdjQpFM0l4dxvKwHn
26
+ tUeT3ZsAgt0JnGqNm2Bkz81kG4A2hSyFZTFA8vZGhp+hz+8Q573tAR89y9YJBdYM
27
+ zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW
28
+ xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
29
+ BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
30
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
31
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
32
+ cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
33
+ xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
34
+ c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
35
+ 8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
36
+ JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
37
+ eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
38
+ Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
39
+ voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
40
+ -----END CERTIFICATE-----
41
+ date: 2023-06-29 00:00:00.000000000 Z
12
42
  dependencies:
13
43
  - !ruby/object:Gem::Dependency
14
- name: mapping
44
+ name: console
15
45
  requirement: !ruby/object:Gem::Requirement
16
46
  requirements:
17
47
  - - "~>"
@@ -25,7 +55,7 @@ dependencies:
25
55
  - !ruby/object:Gem::Version
26
56
  version: '1.0'
27
57
  - !ruby/object:Gem::Dependency
28
- name: console
58
+ name: mapping
29
59
  requirement: !ruby/object:Gem::Requirement
30
60
  requirements:
31
61
  - - "~>"
@@ -39,7 +69,7 @@ dependencies:
39
69
  - !ruby/object:Gem::Version
40
70
  version: '1.0'
41
71
  - !ruby/object:Gem::Dependency
42
- name: covered
72
+ name: bundler
43
73
  requirement: !ruby/object:Gem::Requirement
44
74
  requirements:
45
75
  - - ">="
@@ -53,7 +83,7 @@ dependencies:
53
83
  - !ruby/object:Gem::Version
54
84
  version: '0'
55
85
  - !ruby/object:Gem::Dependency
56
- name: bundler
86
+ name: covered
57
87
  requirement: !ruby/object:Gem::Requirement
58
88
  requirements:
59
89
  - - ">="
@@ -67,46 +97,25 @@ dependencies:
67
97
  - !ruby/object:Gem::Version
68
98
  version: '0'
69
99
  - !ruby/object:Gem::Dependency
70
- name: rake
100
+ name: sus
71
101
  requirement: !ruby/object:Gem::Requirement
72
102
  requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '10.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '10.0'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
103
+ - - ">="
88
104
  - !ruby/object:Gem::Version
89
- version: '3.6'
105
+ version: '0'
90
106
  type: :development
91
107
  prerelease: false
92
108
  version_requirements: !ruby/object:Gem::Requirement
93
109
  requirements:
94
- - - "~>"
110
+ - - ">="
95
111
  - !ruby/object:Gem::Version
96
- version: '3.6'
97
- description:
112
+ version: '0'
113
+ description:
98
114
  email:
99
- - samuel.williams@oriontransfer.co.nz
100
115
  executables: []
101
116
  extensions: []
102
117
  extra_rdoc_files: []
103
118
  files:
104
- - ".gitignore"
105
- - ".rspec"
106
- - ".travis.yml"
107
- - Gemfile
108
- - README.md
109
- - Rakefile
110
119
  - lib/samovar.rb
111
120
  - lib/samovar/command.rb
112
121
  - lib/samovar/error.rb
@@ -126,22 +135,14 @@ files:
126
135
  - lib/samovar/split.rb
127
136
  - lib/samovar/table.rb
128
137
  - lib/samovar/version.rb
129
- - samovar.gemspec
130
- - spec/samovar/coerce_spec.rb
131
- - spec/samovar/command_spec.rb
132
- - spec/samovar/many_spec.rb
133
- - spec/samovar/nested_spec.rb
134
- - spec/samovar/one_spec.rb
135
- - spec/samovar/options_spec.rb
136
- - spec/samovar/split_spec.rb
137
- - spec/samovar/table_spec.rb
138
- - spec/spec_helper.rb
139
- - teapot.png
138
+ - license.md
139
+ - readme.md
140
140
  homepage: https://github.com/ioquatix/samovar
141
141
  licenses:
142
142
  - MIT
143
- metadata: {}
144
- post_install_message:
143
+ metadata:
144
+ funding_uri: https://github.com/sponsors/ioquatix/
145
+ post_install_message:
145
146
  rdoc_options: []
146
147
  require_paths:
147
148
  - lib
@@ -156,18 +157,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
157
  - !ruby/object:Gem::Version
157
158
  version: '0'
158
159
  requirements: []
159
- rubygems_version: 3.1.2
160
- signing_key:
160
+ rubygems_version: 3.4.7
161
+ signing_key:
161
162
  specification_version: 4
162
163
  summary: Samovar is a flexible option parser excellent support for sub-commands and
163
164
  help documentation.
164
- test_files:
165
- - spec/samovar/coerce_spec.rb
166
- - spec/samovar/command_spec.rb
167
- - spec/samovar/many_spec.rb
168
- - spec/samovar/nested_spec.rb
169
- - spec/samovar/one_spec.rb
170
- - spec/samovar/options_spec.rb
171
- - spec/samovar/split_spec.rb
172
- - spec/samovar/table_spec.rb
173
- - spec/spec_helper.rb
165
+ test_files: []
metadata.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ ���S�O˳=�eƗ��Mo�֔4�����BS�}�Z��>iS���D���m�;m����n�O���Va��dmU#��/�������=��>�] D r៌~K���=�pkГL.U��R��<G �
2
+ x����q�6:A�~�l�=U�#3lb�7 �hqj�X@ ��_D��� 3�M1�)V���4�;���������t9g��ǜv��H��p�`��wta��ܪK�
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- .rspec_status
11
- .tags
data/.rspec DELETED
@@ -1,4 +0,0 @@
1
- --format documentation
2
- --backtrace
3
- --warnings
4
- --require spec_helper
data/.travis.yml DELETED
@@ -1,20 +0,0 @@
1
- language: ruby
2
- dist: xenial
3
- cache: bundler
4
-
5
- matrix:
6
- include:
7
- - rvm: 2.3
8
- - rvm: 2.4
9
- - rvm: 2.5
10
- - rvm: 2.6
11
- - rvm: 2.6
12
- env: COVERAGE=BriefSummary,Coveralls
13
- - rvm: truffleruby
14
- - rvm: jruby-head
15
- env: JRUBY_OPTS="--debug -X+O"
16
- - rvm: ruby-head
17
- allow_failures:
18
- - rvm: ruby-head
19
- - rvm: truffleruby
20
- - rvm: jruby-head
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in samovar.gemspec
4
- gemspec
5
-
6
- group :test do
7
- gem 'pry'
8
- end
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- # Load all rake tasks:
5
- import(*Dir.glob('tasks/**/*.rake'))
6
-
7
- RSpec::Core::RakeTask.new(:test)
8
-
9
- task :default => :test
data/samovar.gemspec DELETED
@@ -1,28 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'samovar/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "samovar"
8
- spec.version = Samovar::VERSION
9
- spec.authors = ["Samuel Williams"]
10
- spec.email = ["samuel.williams@oriontransfer.co.nz"]
11
-
12
- spec.summary = %q{Samovar is a flexible option parser excellent support for sub-commands and help documentation.}
13
- spec.homepage = "https://github.com/ioquatix/samovar"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_dependency "mapping", "~> 1.0"
22
- spec.add_dependency "console", "~> 1.0"
23
-
24
- spec.add_development_dependency "covered"
25
- spec.add_development_dependency "bundler"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "rspec", "~> 3.6"
28
- end
@@ -1,45 +0,0 @@
1
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'samovar'
22
-
23
- module Samovar::CoerceSpec
24
- class Coerce < Samovar::Command
25
- options do
26
- option '--things <array>', "A list of things" do |input|
27
- input.split(/\s*,\s*/)
28
- end
29
-
30
- option '--count <integer>', "A number to count", type: Integer
31
- end
32
- end
33
-
34
- RSpec.describe Samovar::Command do
35
- it "should coerce to array" do
36
- top = Coerce['--things', 'a,b,c']
37
- expect(top.options[:things]).to be == ['a', 'b', 'c']
38
- end
39
-
40
- it "should coerce to integer" do
41
- top = Coerce['--count', '10']
42
- expect(top.options[:count]).to be == 10
43
- end
44
- end
45
- end
@@ -1,91 +0,0 @@
1
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'samovar'
22
-
23
- module Samovar::CommandSpec
24
- class Bottom < Samovar::Command
25
- self.description = "Create a new teapot package using the specified repository."
26
-
27
- one :project_name, "The name of the new project in title-case, e.g. 'My Project'."
28
- many :packages, "Any additional packages you'd like to include in the project."
29
- split :argv, "Additional arguments to be passed to the sub-process."
30
- end
31
-
32
- class Top < Samovar::Command
33
- self.description = "A decentralised package manager and build tool."
34
-
35
- options do
36
- option '-c/--configuration <name>', "Specify a specific build configuration.", default: 'TEAPOT_CONFIGURATION'
37
- option '-i/--in/--root <path>', "Work in the given root directory."
38
- option '--verbose | --quiet', "Verbosity of output for debugging.", key: :logging
39
- option '-h/--help', "Print out help information."
40
- option '-v/--version', "Print out the application version."
41
- end
42
-
43
- nested :command, {
44
- 'bottom' => Bottom
45
- }
46
- end
47
-
48
- RSpec.describe Samovar::Command do
49
- it "should invoke call" do
50
- expect(Top).to receive(:new).and_wrap_original do |original_method, *arguments, &block|
51
- original_method.call(*arguments, &block).tap do |instance|
52
- expect(instance).to receive(:call)
53
- end
54
- end
55
-
56
- Top.call([])
57
- end
58
-
59
- it "should use default value" do
60
- top = Top[]
61
- expect(top.options[:configuration]).to be == 'TEAPOT_CONFIGURATION'
62
- end
63
-
64
- it "can update options" do
65
- top = Top[]
66
- expect(top.options[:configuration]).to be == 'TEAPOT_CONFIGURATION'
67
-
68
- top = top['--verbose']
69
- expect(top.options[:configuration]).to be == 'TEAPOT_CONFIGURATION'
70
- expect(top.options[:logging]).to be == :verbose
71
- end
72
-
73
- it "should parse a simple command" do
74
- top = Top["-c", "path", "bottom", "foobar", "A", "B", "--", "args", "args"]
75
-
76
- expect(top.options[:configuration]).to be == 'path'
77
- expect(top.command.class).to be == Bottom
78
- expect(top.command.project_name).to be == 'foobar'
79
- expect(top.command.packages).to be == ['A', 'B']
80
- expect(top.command.argv).to be == ["args", "args"]
81
- end
82
-
83
- it "should generate documentation" do
84
- top = Top[]
85
- buffer = StringIO.new
86
- top.print_usage(output: buffer)
87
-
88
- expect(buffer.string).to be_include(Top.description)
89
- end
90
- end
91
- end
@@ -1,49 +0,0 @@
1
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'samovar/many'
22
-
23
- RSpec.describe Samovar::Many do
24
- let(:default) {["1", "2", "3"]}
25
- let(:input) {["2", "3", "--else"]}
26
-
27
- subject{described_class.new(:items, "some items", default: default)}
28
-
29
- it "has string representation" do
30
- expect(subject.to_s).to be == "<items...>"
31
- end
32
-
33
- it "should have default" do
34
- expect(subject.default).to be == default
35
- end
36
-
37
- it "should use default" do
38
- expect(subject.parse([])).to be == default
39
- end
40
-
41
- it "should use specified default" do
42
- expect(subject.parse([], nil, ["2"])).to be == ["2"]
43
- end
44
-
45
- it "should not use default if input specified" do
46
- expect(subject.parse(input)).to be == ["2", "3"]
47
- expect(input).to be == ["--else"]
48
- end
49
- end