lino 2.5.0 → 3.0.0.pre.1

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: 9abe77247b0e441d73bb60678b26fca6e7ea020a95d2e50996243bfeaf7105b3
4
- data.tar.gz: 7f92a36e4804f0ed8388813881d399ca3dd852b3b2091575ee6b4ebbd34b3ae5
3
+ metadata.gz: 814ba4c3b5790b29c0bed0ea964441d6f382b7bd6430ae69c5d45871a38065b7
4
+ data.tar.gz: 815e2d108e1d79f02ce5d0b6e315193d753322f097de7da6cc65d21a84ca63ef
5
5
  SHA512:
6
- metadata.gz: e7a6eeec352e08b48c1134b9e33273268475ecc14a1bfa466f235f7034d5f59348e4739fed6bda0629faeae799bd09b2cce7a955b15cb9dc0bfdeff728ef8d58
7
- data.tar.gz: 1618d41e38eda052a9f87f1c4cd190a74de598f53ad1c1d0df0a8861d886401bce8f4dce637822b92b9398c2b31e4eebe88bdd711a07e3dc24de4bb4400812d5
6
+ metadata.gz: ae965325ec2dc8fb05611c498da286b816997de2ab0e7730d4b9a8507150308e3aacd43c71880251c98aa3c31b00215e186a9b11a34a45ee1042a857f4f65925
7
+ data.tar.gz: db20e12bb7e81337519ad34d07342e9136993b364ffe4d14063eec04d145e085c034e1b607cdb622dc3d469e05402aba97cb88690d8b92c06cf26abb417f5521
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lino (2.5.0)
4
+ lino (3.0.0.pre.1)
5
5
  hamster (~> 3.0)
6
6
  open4 (~> 1.3)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (6.1.0)
11
+ activesupport (6.1.3.1)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (>= 1.6, < 2)
14
14
  minitest (>= 5.1)
@@ -18,28 +18,32 @@ GEM
18
18
  public_suffix (>= 2.0.2, < 5.0)
19
19
  ast (2.4.2)
20
20
  colored2 (3.1.2)
21
- concurrent-ruby (1.1.7)
21
+ concurrent-ruby (1.1.8)
22
22
  diff-lcs (1.4.4)
23
- docile (1.3.4)
24
- excon (0.78.1)
25
- faraday (1.3.0)
23
+ docile (1.3.5)
24
+ excon (0.81.0)
25
+ faraday (1.4.1)
26
+ faraday-excon (~> 1.1)
26
27
  faraday-net_http (~> 1.0)
28
+ faraday-net_http_persistent (~> 1.1)
27
29
  multipart-post (>= 1.2, < 3)
28
- ruby2_keywords
29
- faraday-net_http (1.0.0)
30
- gem-release (2.2.0)
30
+ ruby2_keywords (>= 0.0.4)
31
+ faraday-excon (1.1.0)
32
+ faraday-net_http (1.0.1)
33
+ faraday-net_http_persistent (1.1.0)
34
+ gem-release (2.2.1)
31
35
  hamster (3.0.0)
32
36
  concurrent-ruby (~> 1.0)
33
- i18n (1.8.6)
37
+ i18n (1.8.10)
34
38
  concurrent-ruby (~> 1.0)
35
- minitest (5.14.2)
39
+ minitest (5.14.4)
36
40
  multipart-post (2.1.1)
37
- octokit (4.20.0)
41
+ octokit (4.21.0)
38
42
  faraday (>= 0.9)
39
43
  sawyer (~> 0.8.0, >= 0.5.3)
40
44
  open4 (1.3.4)
41
45
  parallel (1.20.1)
42
- parser (3.0.0.0)
46
+ parser (3.0.1.0)
43
47
  ast (~> 2.4.1)
44
48
  public_suffix (4.0.6)
45
49
  rainbow (3.0.0)
@@ -49,23 +53,23 @@ GEM
49
53
  excon (~> 0.72)
50
54
  rake_factory (~> 0.23)
51
55
  sshkey (~> 2.0)
52
- rake_factory (0.27.0)
56
+ rake_factory (0.29.0)
53
57
  activesupport (>= 4)
54
58
  rake (~> 13.0)
55
- rake_github (0.5.0)
59
+ rake_github (0.7.0)
56
60
  colored2 (~> 3.1)
57
61
  octokit (~> 4.16)
58
62
  rake_factory (~> 0.23)
59
63
  sshkey (~> 2.0)
60
- rake_gpg (0.12.0)
64
+ rake_gpg (0.14.0)
61
65
  rake_factory (>= 0.23, < 1)
62
66
  ruby_gpg2 (>= 0.6, < 1)
63
- rake_ssh (0.4.0)
67
+ rake_ssh (0.6.0)
64
68
  colored2 (~> 3.1)
65
69
  rake_factory (~> 0.23)
66
70
  sshkey (~> 2.0)
67
71
  regexp_parser (2.1.1)
68
- rexml (3.2.4)
72
+ rexml (3.2.5)
69
73
  rspec (3.10.0)
70
74
  rspec-core (~> 3.10.0)
71
75
  rspec-expectations (~> 3.10.0)
@@ -75,11 +79,11 @@ GEM
75
79
  rspec-expectations (3.10.1)
76
80
  diff-lcs (>= 1.2.0, < 2.0)
77
81
  rspec-support (~> 3.10.0)
78
- rspec-mocks (3.10.1)
82
+ rspec-mocks (3.10.2)
79
83
  diff-lcs (>= 1.2.0, < 2.0)
80
84
  rspec-support (~> 3.10.0)
81
- rspec-support (3.10.1)
82
- rubocop (1.12.0)
85
+ rspec-support (3.10.2)
86
+ rubocop (1.13.0)
83
87
  parallel (~> 1.10)
84
88
  parser (>= 3.0.0.0)
85
89
  rainbow (>= 2.2.2, < 4.0)
@@ -92,17 +96,17 @@ GEM
92
96
  parser (>= 2.7.1.5)
93
97
  rubocop-rake (0.5.1)
94
98
  rubocop
95
- rubocop-rspec (2.2.0)
99
+ rubocop-rspec (2.3.0)
96
100
  rubocop (~> 1.0)
97
101
  rubocop-ast (>= 1.1.0)
98
102
  ruby-progressbar (1.11.0)
99
- ruby2_keywords (0.0.2)
100
- ruby_gpg2 (0.6.0)
103
+ ruby2_keywords (0.0.4)
104
+ ruby_gpg2 (0.8.0)
101
105
  lino (>= 1.5)
102
106
  sawyer (0.8.2)
103
107
  addressable (>= 2.3.5)
104
108
  faraday (> 0.8, < 2.0)
105
- simplecov (0.20.0)
109
+ simplecov (0.21.2)
106
110
  docile (~> 1.1)
107
111
  simplecov-html (~> 0.11)
108
112
  simplecov_json_formatter (~> 0.1)
@@ -133,4 +137,4 @@ DEPENDENCIES
133
137
  simplecov (~> 0.16)
134
138
 
135
139
  BUNDLED WITH
136
- 2.2.16
140
+ 2.2.17
data/README.md CHANGED
@@ -379,6 +379,33 @@ Lino::CommandLineBuilder.for_command('ls')
379
379
  # => ls /some/directory -l
380
380
  ```
381
381
 
382
+ The option placement can be overridden on an option by option basis:
383
+
384
+ ```ruby
385
+ Lino::CommandLineBuilder.for_command('gcloud')
386
+ .with_options_after_subcommands
387
+ .with_option('--log-level', 'debug', placement: :after_command)
388
+ .with_option('--password', 'super-secure')
389
+ .with_subcommands(%w[sql instances set-root-password])
390
+ .build
391
+ .to_s
392
+
393
+ # => gcloud --log-level debug sql instances set-root-password \
394
+ # --password super-secure
395
+ ```
396
+
397
+ The `:placement` keyword argument accepts placement values of `:after_command`,
398
+ `:after_subcommands` and `:after_arguments`.
399
+
400
+ > Note: `#with_options` supports placement overriding when the options are
401
+ > passed as an array of hashes and a `placement` key is included in the
402
+ > hash.
403
+
404
+ > Note: `#with_repeated_option` also supports the `placement` named parameter.
405
+
406
+ > Note: option specific placement take precedence over the global option
407
+ > placement
408
+
382
409
  #### Appliables
383
410
 
384
411
  Command and subcommand builders both support passing 'appliables' that are
@@ -7,13 +7,13 @@ module Lino
7
7
  include Lino::Utilities
8
8
 
9
9
  def with_appliable(appliable)
10
- return self if missing?(appliable)
10
+ return self if nil?(appliable)
11
11
 
12
12
  appliable.apply(self)
13
13
  end
14
14
 
15
15
  def with_appliables(appliables)
16
- return self if missing?(appliables)
16
+ return self if nil_or_empty?(appliables)
17
17
 
18
18
  appliables.inject(self) do |s, appliable|
19
19
  s.with_appliable(appliable)
@@ -10,15 +10,6 @@ require_relative 'appliables'
10
10
  module Lino
11
11
  # rubocop:disable Metrics/ClassLength
12
12
  class CommandLineBuilder
13
- SELECTORS = {
14
- after_command:
15
- %i[environment_variables command options subcommands arguments],
16
- after_subcommands:
17
- %i[environment_variables command subcommands options arguments],
18
- after_arguments:
19
- %i[environment_variables command subcommands arguments options]
20
- }.freeze
21
-
22
13
  include Lino::Utilities
23
14
  include Lino::Options
24
15
  include Lino::Appliables
@@ -49,10 +40,11 @@ module Lino
49
40
  @option_quoting = option_quoting
50
41
  @option_placement = option_placement
51
42
  end
43
+
52
44
  # rubocop:enable Metrics/ParameterLists
53
45
 
54
46
  def with_subcommand(subcommand, &block)
55
- return self if missing?(subcommand)
47
+ return self if nil?(subcommand)
56
48
 
57
49
  with(
58
50
  subcommands: @subcommands.add(
@@ -64,7 +56,7 @@ module Lino
64
56
  end
65
57
 
66
58
  def with_subcommands(subcommands, &block)
67
- return self if missing?(subcommands)
59
+ return self if nil_or_empty?(subcommands)
68
60
 
69
61
  without_block = subcommands[0...-1]
70
62
  with_block = subcommands.last
@@ -82,26 +74,30 @@ module Lino
82
74
  with(option_quoting: character)
83
75
  end
84
76
 
77
+ def with_option_placement(option_placement)
78
+ with(option_placement: option_placement)
79
+ end
80
+
85
81
  def with_options_after_command
86
- with(option_placement: :after_command)
82
+ with_option_placement(:after_command)
87
83
  end
88
84
 
89
85
  def with_options_after_subcommands
90
- with(option_placement: :after_subcommands)
86
+ with_option_placement(:after_subcommands)
91
87
  end
92
88
 
93
89
  def with_options_after_arguments
94
- with(option_placement: :after_arguments)
90
+ with_option_placement(:after_arguments)
95
91
  end
96
92
 
97
93
  def with_argument(argument)
98
- return self if missing?(argument)
94
+ return self if nil?(argument)
99
95
 
100
96
  with(arguments: @arguments.add({ components: [argument] }))
101
97
  end
102
98
 
103
99
  def with_arguments(arguments)
104
- return self if missing?(arguments)
100
+ return self if nil_or_empty?(arguments)
105
101
 
106
102
  arguments.inject(self) { |s, argument| s.with_argument(argument) }
107
103
  end
@@ -118,7 +114,7 @@ module Lino
118
114
  end
119
115
 
120
116
  def with_environment_variables(environment_variables)
121
- return self if missing?(environment_variables)
117
+ return self if nil_or_empty?(environment_variables)
122
118
 
123
119
  environment_variables.entries.inject(self) do |s, var|
124
120
  s.with_environment_variable(
@@ -130,16 +126,29 @@ module Lino
130
126
 
131
127
  def build
132
128
  components = formatted_components
133
- command_line = SELECTORS[@option_placement]
134
- .inject([]) { |c, key| c << components[key] }
135
- .reject(&:empty?)
136
- .join(' ')
129
+ command_line =
130
+ component_paths
131
+ .collect { |path| path.inject(components) { |c, p| c && c[p] } }
132
+ .reject(&:empty?)
133
+ .join(' ')
137
134
 
138
135
  CommandLine.new(command_line)
139
136
  end
140
137
 
141
138
  private
142
139
 
140
+ def component_paths
141
+ [
142
+ %i[environment_variables],
143
+ %i[command],
144
+ %i[options after_command],
145
+ %i[subcommands],
146
+ %i[options after_subcommands],
147
+ %i[arguments],
148
+ %i[options after_arguments]
149
+ ]
150
+ end
151
+
143
152
  def formatted_components
144
153
  {
145
154
  environment_variables: formatted_environment_variables,
@@ -156,13 +165,24 @@ module Lino
156
165
  end
157
166
  end
158
167
 
159
- def formatted_options
168
+ def formatted_options_with_placement(placement)
160
169
  map_and_join(
161
- @options,
170
+ options_with_placement(placement),
162
171
  &(quote_with(@option_quoting) >> join_with(@option_separator))
163
172
  )
164
173
  end
165
174
 
175
+ def formatted_options
176
+ %i[
177
+ after_command
178
+ after_subcommands
179
+ after_arguments
180
+ ].inject({}) do |options, placement|
181
+ options
182
+ .merge({ placement => formatted_options_with_placement(placement) })
183
+ end
184
+ end
185
+
166
186
  def formatted_subcommands
167
187
  map_and_join(@subcommands) do |sub|
168
188
  sub.build(@option_separator, @option_quoting)
@@ -176,6 +196,13 @@ module Lino
176
196
  )
177
197
  end
178
198
 
199
+ def options_with_placement(placement)
200
+ @options.select { |o| o[:placement] == placement } +
201
+ if @option_placement == placement
202
+ @options.select { |o| o[:placement].nil? }
203
+ end
204
+ end
205
+
179
206
  def with(**replacements)
180
207
  CommandLineBuilder.new(**state.merge(replacements))
181
208
  end
@@ -193,5 +220,6 @@ module Lino
193
220
  }
194
221
  end
195
222
  end
223
+
196
224
  # rubocop:enable Metrics/ClassLength
197
225
  end
data/lib/lino/options.rb CHANGED
@@ -6,45 +6,65 @@ module Lino
6
6
  module Options
7
7
  include Lino::Utilities
8
8
 
9
- def with_option(option, value, separator: nil, quoting: nil)
10
- return self if missing?(value)
9
+ def with_option(
10
+ option,
11
+ value,
12
+ separator: nil,
13
+ quoting: nil,
14
+ placement: nil
15
+ )
16
+ return self if nil?(value)
11
17
 
12
18
  with(options: @options.add(
13
19
  {
14
20
  components: [option, value],
15
21
  separator: separator,
16
- quoting: quoting
22
+ quoting: quoting,
23
+ placement: placement
17
24
  }
18
25
  ))
19
26
  end
20
27
 
21
28
  def with_options(options)
22
- return self if missing?(options)
29
+ return self if nil_or_empty?(options)
23
30
 
24
31
  options.entries.inject(self) do |s, entry|
25
32
  s.with_option(
26
- entry.include?(:option) ? entry[:option] : entry[0],
27
- entry.include?(:value) ? entry[:value] : entry[1],
28
- separator: (entry.include?(:separator) ? entry[:separator] : nil),
29
- quoting: (entry.include?(:quoting) ? entry[:quoting] : nil)
33
+ or_nth(entry, :option, 0),
34
+ or_nth(entry, :value, 1),
35
+ separator: or_nil(entry, :separator),
36
+ quoting: or_nil(entry, :quoting),
37
+ placement: or_nil(entry, :placement)
30
38
  )
31
39
  end
32
40
  end
33
41
 
34
- def with_repeated_option(option, values, separator: nil, quoting: nil)
42
+ def with_repeated_option(
43
+ option,
44
+ values,
45
+ separator: nil,
46
+ quoting: nil,
47
+ placement: nil
48
+ )
35
49
  values.inject(self) do |s, value|
36
- s.with_option(option, value, separator: separator, quoting: quoting)
50
+ s.with_option(
51
+ option,
52
+ value,
53
+ separator: separator,
54
+ quoting: quoting,
55
+ placement: placement
56
+ )
37
57
  end
38
58
  end
39
59
 
40
60
  def with_flag(flag)
41
- return self if missing?(flag)
61
+ return self if nil?(flag)
42
62
 
43
63
  with(options: @options.add({ components: [flag] }))
44
64
  end
45
65
 
46
66
  def with_flags(flags)
47
- return self if missing?(flags)
67
+ return self if nil_or_empty?(flags)
48
68
 
49
69
  flags.inject(self) { |s, flag| s.with_flag(flag) }
50
70
  end
@@ -22,8 +22,16 @@ module Lino
22
22
  end
23
23
  end
24
24
 
25
- def missing?(value)
26
- value.nil? || (value.respond_to?(:empty?) && value.empty?)
25
+ def nil?(value)
26
+ value.nil?
27
+ end
28
+
29
+ def empty?(value)
30
+ value.respond_to?(:empty?) && value.empty?
31
+ end
32
+
33
+ def nil_or_empty?(value)
34
+ nil?(value) || empty?(value)
27
35
  end
28
36
 
29
37
  private
@@ -41,5 +49,13 @@ module Lino
41
49
  components
42
50
  end
43
51
  end
52
+
53
+ def or_nil(enumerable, key)
54
+ enumerable.include?(key) ? enumerable[key] : nil
55
+ end
56
+
57
+ def or_nth(enumerable, key, index)
58
+ enumerable.include?(key) ? enumerable[key] : enumerable[index]
59
+ end
44
60
  end
45
61
  end
data/lib/lino/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lino
4
- VERSION = '2.5.0'
4
+ VERSION = '3.0.0.pre.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lino
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 3.0.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby Clemson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-13 00:00:00.000000000 Z
11
+ date: 2021-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hamster
@@ -244,9 +244,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
244
244
  version: '2.6'
245
245
  required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  requirements:
247
- - - ">="
247
+ - - ">"
248
248
  - !ruby/object:Gem::Version
249
- version: '0'
249
+ version: 1.3.1
250
250
  requirements: []
251
251
  rubygems_version: 3.0.1
252
252
  signing_key: