lino 1.10.0.pre.2 → 2.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: b6ad4b0f5639831eb11ab6878d387be88e20c910e4d9c74101f7db6541086e31
4
- data.tar.gz: 79e65ded113a76a7a2d8c44c39ef171f890561004a61ffac43f4f918348e8349
3
+ metadata.gz: b1ed8a59b3a9171234c636171f9b7304637067db63ff130c04c14a780418f28c
4
+ data.tar.gz: 927e637996bab9611c2233e92b1ab5b0869a5de36847dce88086880fd1022d71
5
5
  SHA512:
6
- metadata.gz: bc12bc01a910dddbc53d71650d01ed78caaf7372b4e864c6419ed7cf64bc68f87df3dea55970581dbe86055c9feb10e6b1ef7d0e571e3d2eab32b0f8b712ca7f
7
- data.tar.gz: 5f4d632f1a87320d55ef9ccd318d71e8c189faf1121dac84f9746502650922a5c20c714ff5a5a4711cb4b797fbbf70134a3f1c1fc027f8f9d760069a8b3d363f
6
+ metadata.gz: 357901083b289bbf18a2c3f7425ae01967d950c0329b6c793dd214fe2b265bea8f69d40886cd58d169bac03dcff1eb7337ad6a909788da0370836065fa51b9da
7
+ data.tar.gz: 53a7a833e0725f4f9597dc05afa7213a67790b5c77d0f76bacbbda403a82464dc4a187fc8265999db6dd4e47e4f05deb257370c97734a0356f81ebcf451bb67b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lino (1.10.0.pre.2)
4
+ lino (2.0.0.pre.1)
5
5
  hamster (~> 3.0)
6
6
  open4 (~> 1.3)
7
7
 
data/README.md CHANGED
@@ -120,6 +120,18 @@ Lino::CommandLineBuilder.for_command('gcloud')
120
120
  .to_s
121
121
 
122
122
  # => gcloud sql instances set-root-password some-database --password super-secure
123
+
124
+ # ... or alternatively
125
+ Lino::CommandLineBuilder.for_command('gcloud')
126
+ .with_subcommands(
127
+ %w[sql instances set-root-password some-database]
128
+ ) do |sub|
129
+ sub.with_option('--password', 'super-secure')
130
+ end
131
+ .build
132
+ .to_s
133
+
134
+ # => gcloud sql instances set-root-password some-database --password super-secure
123
135
 
124
136
  # commands controlled by environment variables
125
137
  Lino::CommandLineBuilder.for_command('node')
@@ -183,10 +195,25 @@ To install dependencies and run the build, run the pre-commit build:
183
195
  ./go
184
196
  ```
185
197
 
186
- To run only the specs:
198
+ This runs all unit tests and other checks including coverage and code linting /
199
+ formatting.
200
+
201
+ To run only the unit tests, including coverage:
202
+
203
+ ```shell script
204
+ ./go test:unit
205
+ ```
206
+
207
+ To attempt to fix any code linting / formatting issues:
208
+
209
+ ```shell script
210
+ ./go library:fix
211
+ ```
212
+
213
+ To check for code linting / formatting issues without fixing:
187
214
 
188
215
  ```shell script
189
- ./go spec
216
+ ./go library:check
190
217
  ```
191
218
 
192
219
  You can also run `bin/console` for an interactive prompt that will allow you to
@@ -4,13 +4,13 @@ require 'hamster'
4
4
  require_relative 'utilities'
5
5
  require_relative 'command_line'
6
6
  require_relative 'subcommand_builder'
7
- require_relative 'switches'
7
+ require_relative 'options'
8
8
 
9
9
  module Lino
10
10
  # rubocop:disable Metrics/ClassLength
11
11
  class CommandLineBuilder
12
12
  include Lino::Utilities
13
- include Lino::Switches
13
+ include Lino::Options
14
14
 
15
15
  class << self
16
16
  def for_command(command)
@@ -22,7 +22,7 @@ module Lino
22
22
  def initialize(
23
23
  command: nil,
24
24
  subcommands: [],
25
- switches: [],
25
+ options: [],
26
26
  arguments: [],
27
27
  environment_variables: [],
28
28
  option_separator: ' ',
@@ -30,7 +30,7 @@ module Lino
30
30
  )
31
31
  @command = command
32
32
  @subcommands = Hamster::Vector.new(subcommands)
33
- @switches = Hamster::Vector.new(switches)
33
+ @options = Hamster::Vector.new(options)
34
34
  @arguments = Hamster::Vector.new(arguments)
35
35
  @environment_variables = Hamster::Vector.new(environment_variables)
36
36
  @option_separator = option_separator
@@ -48,6 +48,15 @@ module Lino
48
48
  )
49
49
  end
50
50
 
51
+ def with_subcommands(subcommands, &block)
52
+ without_block = subcommands[0...-1]
53
+ with_block = subcommands.last
54
+
55
+ without_block
56
+ .inject(self) { |s, sc| s.with_subcommand(sc) }
57
+ .with_subcommand(with_block, &block)
58
+ end
59
+
51
60
  def with_option_separator(option_separator)
52
61
  with(option_separator: option_separator)
53
62
  end
@@ -57,12 +66,13 @@ module Lino
57
66
  end
58
67
 
59
68
  def with_argument(argument)
60
- with(arguments: add_argument(argument))
69
+ return self if missing?(argument)
70
+
71
+ with(arguments: @arguments.add({ components: [argument] }))
61
72
  end
62
73
 
63
74
  def with_arguments(arguments)
64
- arguments.each { |argument| add_argument(argument) }
65
- with({})
75
+ arguments.inject(self) { |s, argument| s.with_argument(argument) }
66
76
  end
67
77
 
68
78
  def with_environment_variable(environment_variable, value)
@@ -80,7 +90,7 @@ module Lino
80
90
  components = [
81
91
  formatted_environment_variables,
82
92
  @command,
83
- formatted_switches,
93
+ formatted_options,
84
94
  formatted_subcommands,
85
95
  formatted_arguments
86
96
  ]
@@ -98,9 +108,9 @@ module Lino
98
108
  end
99
109
  end
100
110
 
101
- def formatted_switches
111
+ def formatted_options
102
112
  map_and_join(
103
- @switches,
113
+ @options,
104
114
  &(quote_with(@option_quoting) >> join_with(@option_separator))
105
115
  )
106
116
  end
@@ -112,7 +122,10 @@ module Lino
112
122
  end
113
123
 
114
124
  def formatted_arguments
115
- map_and_join(@arguments, &join_with(' '))
125
+ map_and_join(
126
+ @arguments,
127
+ &join_with(' ')
128
+ )
116
129
  end
117
130
 
118
131
  def with(**replacements)
@@ -123,19 +136,13 @@ module Lino
123
136
  {
124
137
  command: @command,
125
138
  subcommands: @subcommands,
126
- switches: @switches,
139
+ options: @options,
127
140
  arguments: @arguments,
128
141
  environment_variables: @environment_variables,
129
142
  option_separator: @option_separator,
130
143
  option_quoting: @option_quoting
131
144
  }
132
145
  end
133
-
134
- def add_argument(argument)
135
- return @arguments if missing?(argument)
136
-
137
- @arguments = @arguments.add({ components: [argument] })
138
- end
139
146
  end
140
147
  # rubocop:enable Metrics/ClassLength
141
148
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lino
4
+ module Options
5
+ def with_option(option, value, separator: nil, quoting: nil)
6
+ return self if missing?(value)
7
+
8
+ with(options: @options.add(
9
+ {
10
+ components: [option, value],
11
+ separator: separator,
12
+ quoting: quoting
13
+ }
14
+ ))
15
+ end
16
+
17
+ def with_repeated_option(option, values, separator: nil, quoting: nil)
18
+ values.inject(self) do |s, value|
19
+ s.with_option(option, value, separator: separator, quoting: quoting)
20
+ end
21
+ end
22
+
23
+ def with_flag(flag)
24
+ with(options: @options.add({ components: [flag] }))
25
+ end
26
+ end
27
+ end
@@ -2,12 +2,12 @@
2
2
 
3
3
  require 'hamster'
4
4
  require_relative 'utilities'
5
- require_relative 'switches'
5
+ require_relative 'options'
6
6
 
7
7
  module Lino
8
8
  class SubcommandBuilder
9
9
  include Lino::Utilities
10
- include Lino::Switches
10
+ include Lino::Options
11
11
 
12
12
  class <<self
13
13
  def for_subcommand(subcommand)
@@ -15,16 +15,16 @@ module Lino
15
15
  end
16
16
  end
17
17
 
18
- def initialize(subcommand: nil, switches: [])
18
+ def initialize(subcommand: nil, options: [])
19
19
  @subcommand = subcommand
20
- @switches = Hamster::Vector.new(switches)
20
+ @options = Hamster::Vector.new(options)
21
21
  end
22
22
 
23
23
  def build(option_separator, option_quoting)
24
24
  components = [
25
25
  @subcommand,
26
26
  map_and_join(
27
- @switches,
27
+ @options,
28
28
  &(quote_with(option_quoting) >> join_with(option_separator))
29
29
  )
30
30
  ]
@@ -40,7 +40,7 @@ module Lino
40
40
  def state
41
41
  {
42
42
  subcommand: @subcommand,
43
- switches: @switches
43
+ options: @options
44
44
  }
45
45
  end
46
46
  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 = '1.10.0.pre.2'
4
+ VERSION = '2.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: 1.10.0.pre.2
4
+ version: 2.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-02 00:00:00.000000000 Z
11
+ date: 2021-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hamster
@@ -224,8 +224,8 @@ files:
224
224
  - lib/lino.rb
225
225
  - lib/lino/command_line.rb
226
226
  - lib/lino/command_line_builder.rb
227
+ - lib/lino/options.rb
227
228
  - lib/lino/subcommand_builder.rb
228
- - lib/lino/switches.rb
229
229
  - lib/lino/utilities.rb
230
230
  - lib/lino/version.rb
231
231
  homepage: https://github.com/infrablocks/lino
data/lib/lino/switches.rb DELETED
@@ -1,34 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lino
4
- module Switches
5
- def with_option(switch, value, separator: nil, quoting: nil)
6
- with(switches: add_option(switch, value, separator, quoting))
7
- end
8
-
9
- def with_repeated_option(switch, values, separator: nil, quoting: nil)
10
- values.each do |value|
11
- add_option(switch, value, separator, quoting)
12
- end
13
- with({})
14
- end
15
-
16
- def with_flag(flag)
17
- with(switches: @switches.add({ components: [flag] }))
18
- end
19
-
20
- private
21
-
22
- def add_option(switch, value, separator, quoting)
23
- return @switches if missing?(value)
24
-
25
- @switches = @switches.add(
26
- {
27
- components: [switch, value],
28
- separator: separator,
29
- quoting: quoting
30
- }
31
- )
32
- end
33
- end
34
- end