lino 2.1.0 → 2.2.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: e889c057a237dfb1af77b0adbb0f661ef0cf37193341a6bddd8add27a64f12eb
4
- data.tar.gz: 121d2e75f308626b29b1ac306f959583bd6cc9b18df0fb57b15d993f90f08dd5
3
+ metadata.gz: f6b8d73d1b83fd4e09bd2cd61bcc0b0717bb14c43976688dbe26d7b84037f725
4
+ data.tar.gz: b1e0ee813a1300a0935a78eaa224677ec60d36181a573e3f4a0ec0e9fb426c61
5
5
  SHA512:
6
- metadata.gz: 9f1319025180174dbce34687d0cbad930551e2ffad455da8b86ac31f47ba874aef4d012d3f4db23e1dd9de07f15e44a732bf4b937cd95cc1f559b18564fcea4d
7
- data.tar.gz: 8a57fca71f15442bbef99be911bc6284f4e2f87c22425bdf996c09fb8c30429116c2bf3b27d6dca8f91e679f7240b9d1251048273f92c04ddb80c41de2c04b8e
6
+ metadata.gz: e78ac95f2c066ca9de9b1b04aceae7ab7ed0a744df486558414abfb8bf725f3bb3a9f37c53220fbd68b7a5bbb2ec9d0eb98da2e40d08943692ac07a7799f0a07
7
+ data.tar.gz: 1697191e1593ceef0785913ec5091ba06cad2af156ba97db7196157da9bf017cfc710d434b71012a44b3470c059669a86f06b1e5fdb865593437ab89a4d662dc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lino (2.1.0)
4
+ lino (2.2.0.pre.1)
5
5
  hamster (~> 3.0)
6
6
  open4 (~> 1.3)
7
7
 
data/README.md CHANGED
@@ -79,7 +79,7 @@ Lino::CommandLineBuilder.for_command('diff')
79
79
 
80
80
  # => diff ./file1.txt ./file2.txt
81
81
 
82
- # commands with an array of arguments
82
+ # ... or alternatively
83
83
  Lino::CommandLineBuilder.for_command('diff')
84
84
  .with_arguments(['./file1.txt', nil, '', './file2.txt'])
85
85
  .build
@@ -142,6 +142,39 @@ Lino::CommandLineBuilder.for_command('node')
142
142
  .to_s
143
143
 
144
144
  # => PORT=3030 LOG_LEVEL=debug node ./server.js
145
+
146
+ # note: by default, options are placed after the command, before all subcommands
147
+ # and arguments
148
+
149
+ # this can be expressed explicitly
150
+ Lino::CommandLineBuilder.for_command('gcloud')
151
+ .with_options_after_command
152
+ .with_option('--password', 'super-secure')
153
+ .with_subcommands(%w[sql instances set-root-password some-database])
154
+ .build
155
+ .to_s
156
+
157
+ # => gcloud --password super-secure sql instances set-root-password some-database
158
+
159
+ # options can also come after subcommands
160
+ Lino::CommandLineBuilder.for_command('gcloud')
161
+ .with_options_after_subcommands
162
+ .with_option('--password', 'super-secure')
163
+ .with_subcommands(%w[sql instances set-root-password some-database])
164
+ .build
165
+ .to_s
166
+
167
+ # => gcloud sql instances set-root-password some-database --password super-secure
168
+
169
+ # options can also come after arguments, although usages of this are rare
170
+ Lino::CommandLineBuilder.for_command('ls')
171
+ .with_options_after_arguments
172
+ .with_flag('-l')
173
+ .with_argument('/some/directory')
174
+ .build
175
+ .to_s
176
+
177
+ # => ls /some/directory -l
145
178
  ```
146
179
 
147
180
  ### `Lino::CommandLine`
@@ -9,6 +9,15 @@ require_relative 'options'
9
9
  module Lino
10
10
  # rubocop:disable Metrics/ClassLength
11
11
  class CommandLineBuilder
12
+ SELECTORS = {
13
+ after_command:
14
+ %i[environment_variables command options subcommands arguments],
15
+ after_subcommands:
16
+ %i[environment_variables command subcommands options arguments],
17
+ after_arguments:
18
+ %i[environment_variables command subcommands arguments options]
19
+ }.freeze
20
+
12
21
  include Lino::Utilities
13
22
  include Lino::Options
14
23
 
@@ -26,7 +35,8 @@ module Lino
26
35
  arguments: [],
27
36
  environment_variables: [],
28
37
  option_separator: ' ',
29
- option_quoting: nil
38
+ option_quoting: nil,
39
+ option_placement: :after_command
30
40
  )
31
41
  @command = command
32
42
  @subcommands = Hamster::Vector.new(subcommands)
@@ -35,6 +45,7 @@ module Lino
35
45
  @environment_variables = Hamster::Vector.new(environment_variables)
36
46
  @option_separator = option_separator
37
47
  @option_quoting = option_quoting
48
+ @option_placement = option_placement
38
49
  end
39
50
  # rubocop:enable Metrics/ParameterLists
40
51
 
@@ -65,6 +76,18 @@ module Lino
65
76
  with(option_quoting: character)
66
77
  end
67
78
 
79
+ def with_options_after_command
80
+ with(option_placement: :after_command)
81
+ end
82
+
83
+ def with_options_after_subcommands
84
+ with(option_placement: :after_subcommands)
85
+ end
86
+
87
+ def with_options_after_arguments
88
+ with(option_placement: :after_arguments)
89
+ end
90
+
68
91
  def with_argument(argument)
69
92
  return self if missing?(argument)
70
93
 
@@ -87,21 +110,27 @@ module Lino
87
110
  end
88
111
 
89
112
  def build
90
- components = [
91
- formatted_environment_variables,
92
- @command,
93
- formatted_options,
94
- formatted_subcommands,
95
- formatted_arguments
96
- ]
113
+ components = formatted_components
114
+ command_line = SELECTORS[@option_placement]
115
+ .inject([]) { |c, key| c << components[key] }
116
+ .reject(&:empty?)
117
+ .join(' ')
97
118
 
98
- command_string = components.reject(&:empty?).join(' ')
99
-
100
- CommandLine.new(command_string)
119
+ CommandLine.new(command_line)
101
120
  end
102
121
 
103
122
  private
104
123
 
124
+ def formatted_components
125
+ {
126
+ environment_variables: formatted_environment_variables,
127
+ command: @command,
128
+ options: formatted_options,
129
+ subcommands: formatted_subcommands,
130
+ arguments: formatted_arguments
131
+ }
132
+ end
133
+
105
134
  def formatted_environment_variables
106
135
  map_and_join(@environment_variables) do |var|
107
136
  "#{var[0]}=\"#{var[1].to_s.gsub(/"/, '\\"')}\""
@@ -140,7 +169,8 @@ module Lino
140
169
  arguments: @arguments,
141
170
  environment_variables: @environment_variables,
142
171
  option_separator: @option_separator,
143
- option_quoting: @option_quoting
172
+ option_quoting: @option_quoting,
173
+ option_placement: @option_placement
144
174
  }
145
175
  end
146
176
  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.1.0'
4
+ VERSION = '2.2.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.1.0
4
+ version: 2.2.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-04 00:00:00.000000000 Z
11
+ date: 2021-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hamster
@@ -243,9 +243,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
243
  version: '2.6'
244
244
  required_rubygems_version: !ruby/object:Gem::Requirement
245
245
  requirements:
246
- - - ">="
246
+ - - ">"
247
247
  - !ruby/object:Gem::Version
248
- version: '0'
248
+ version: 1.3.1
249
249
  requirements: []
250
250
  rubygems_version: 3.0.1
251
251
  signing_key: