lino 2.0.0.pre.1 → 2.2.0.pre.4

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: b1ed8a59b3a9171234c636171f9b7304637067db63ff130c04c14a780418f28c
4
- data.tar.gz: 927e637996bab9611c2233e92b1ab5b0869a5de36847dce88086880fd1022d71
3
+ metadata.gz: 027d718112a95bd94fcd6f88a2f387de6d60abc41a131112a226e9e21b14b0be
4
+ data.tar.gz: ad1156f5456e249bf30ca814a3b6e55342ad62ff0c7b70ceb923e16992df56ce
5
5
  SHA512:
6
- metadata.gz: 357901083b289bbf18a2c3f7425ae01967d950c0329b6c793dd214fe2b265bea8f69d40886cd58d169bac03dcff1eb7337ad6a909788da0370836065fa51b9da
7
- data.tar.gz: 53a7a833e0725f4f9597dc05afa7213a67790b5c77d0f76bacbbda403a82464dc4a187fc8265999db6dd4e47e4f05deb257370c97734a0356f81ebcf451bb67b
6
+ metadata.gz: 20e8f1c420a38574a3ab77b262cb7935afa64ec0db1ada92de14552adb5f845c330e2ddeb92a267c9037f682be0cc7ee170b78e40949a371011aeaa1644a194b
7
+ data.tar.gz: 296b6b3b2f14aeb52a96e7c9458d1a84180764118ae94de38ab041d70ea7428088195a49d7b5f7e0daab1946d50cf8269d5faf4f24dcf50b1db79b2134efa1df
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lino (2.0.0.pre.1)
4
+ lino (2.2.0.pre.4)
5
5
  hamster (~> 3.0)
6
6
  open4 (~> 1.3)
7
7
 
data/README.md CHANGED
@@ -62,6 +62,30 @@ Lino::CommandLineBuilder.for_command('gpg')
62
62
 
63
63
  # => gpg --recipient tobyclemson@gmail.com --sign ./doc.txt
64
64
 
65
+ # ... or alternatively
66
+ Lino::CommandLineBuilder.for_command('gpg')
67
+ .with_options({
68
+ '--recipient' => 'tobyclemson@gmail.com',
69
+ '--sign' => './doc.txt'
70
+ })
71
+ .build
72
+ .to_s
73
+
74
+ # => gpg --recipient tobyclemson@gmail.com --sign ./doc.txt
75
+
76
+ # ... or alternatively
77
+ Lino::CommandLineBuilder.for_command('gpg')
78
+ .with_options(
79
+ [
80
+ { option: '--recipient', value: 'tobyclemson@gmail.com' },
81
+ { option: '--sign', value: './doc.txt' }
82
+ ]
83
+ )
84
+ .build
85
+ .to_s
86
+
87
+ # => gpg --recipient tobyclemson@gmail.com --sign ./doc.txt
88
+
65
89
  # commands with an option repeated multiple times
66
90
  Lino::CommandLineBuilder.for_command('example.sh')
67
91
  .with_repeated_option('--opt', ['file1.txt', nil, '', 'file2.txt'])
@@ -79,7 +103,7 @@ Lino::CommandLineBuilder.for_command('diff')
79
103
 
80
104
  # => diff ./file1.txt ./file2.txt
81
105
 
82
- # commands with an array of arguments
106
+ # ... or alternatively
83
107
  Lino::CommandLineBuilder.for_command('diff')
84
108
  .with_arguments(['./file1.txt', nil, '', './file2.txt'])
85
109
  .build
@@ -142,6 +166,39 @@ Lino::CommandLineBuilder.for_command('node')
142
166
  .to_s
143
167
 
144
168
  # => PORT=3030 LOG_LEVEL=debug node ./server.js
169
+
170
+ # note: by default, options are placed after the command, before all subcommands
171
+ # and arguments
172
+
173
+ # this can be expressed explicitly
174
+ Lino::CommandLineBuilder.for_command('gcloud')
175
+ .with_options_after_command
176
+ .with_option('--password', 'super-secure')
177
+ .with_subcommands(%w[sql instances set-root-password some-database])
178
+ .build
179
+ .to_s
180
+
181
+ # => gcloud --password super-secure sql instances set-root-password some-database
182
+
183
+ # options can also come after subcommands
184
+ Lino::CommandLineBuilder.for_command('gcloud')
185
+ .with_options_after_subcommands
186
+ .with_option('--password', 'super-secure')
187
+ .with_subcommands(%w[sql instances set-root-password some-database])
188
+ .build
189
+ .to_s
190
+
191
+ # => gcloud sql instances set-root-password some-database --password super-secure
192
+
193
+ # options can also come after arguments, although usages of this are rare
194
+ Lino::CommandLineBuilder.for_command('ls')
195
+ .with_options_after_arguments
196
+ .with_flag('-l')
197
+ .with_argument('/some/directory')
198
+ .build
199
+ .to_s
200
+
201
+ # => ls /some/directory -l
145
202
  ```
146
203
 
147
204
  ### `Lino::CommandLine`
data/Rakefile CHANGED
@@ -16,6 +16,7 @@ task default: %i[
16
16
 
17
17
  namespace :encryption do
18
18
  namespace :passphrase do
19
+ desc 'Generate encryption passphrase for CI GPG key'
19
20
  task :generate do
20
21
  File.open('config/secrets/ci/encryption.passphrase', 'w') do |f|
21
22
  f.write(SecureRandom.base64(36))
@@ -96,6 +97,7 @@ RakeGithub.define_repository_tasks(
96
97
  end
97
98
 
98
99
  namespace :pipeline do
100
+ desc 'Prepare CircleCI Pipeline'
99
101
  task prepare: %i[
100
102
  circle_ci:project:follow
101
103
  circle_ci:env_vars:ensure
@@ -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
 
@@ -72,6 +95,8 @@ module Lino
72
95
  end
73
96
 
74
97
  def with_arguments(arguments)
98
+ return self if missing?(arguments)
99
+
75
100
  arguments.inject(self) { |s, argument| s.with_argument(argument) }
76
101
  end
77
102
 
@@ -87,21 +112,27 @@ module Lino
87
112
  end
88
113
 
89
114
  def build
90
- components = [
91
- formatted_environment_variables,
92
- @command,
93
- formatted_options,
94
- formatted_subcommands,
95
- formatted_arguments
96
- ]
97
-
98
- command_string = components.reject(&:empty?).join(' ')
115
+ components = formatted_components
116
+ command_line = SELECTORS[@option_placement]
117
+ .inject([]) { |c, key| c << components[key] }
118
+ .reject(&:empty?)
119
+ .join(' ')
99
120
 
100
- CommandLine.new(command_string)
121
+ CommandLine.new(command_line)
101
122
  end
102
123
 
103
124
  private
104
125
 
126
+ def formatted_components
127
+ {
128
+ environment_variables: formatted_environment_variables,
129
+ command: @command,
130
+ options: formatted_options,
131
+ subcommands: formatted_subcommands,
132
+ arguments: formatted_arguments
133
+ }
134
+ end
135
+
105
136
  def formatted_environment_variables
106
137
  map_and_join(@environment_variables) do |var|
107
138
  "#{var[0]}=\"#{var[1].to_s.gsub(/"/, '\\"')}\""
@@ -140,7 +171,8 @@ module Lino
140
171
  arguments: @arguments,
141
172
  environment_variables: @environment_variables,
142
173
  option_separator: @option_separator,
143
- option_quoting: @option_quoting
174
+ option_quoting: @option_quoting,
175
+ option_placement: @option_placement
144
176
  }
145
177
  end
146
178
  end
data/lib/lino/options.rb CHANGED
@@ -14,6 +14,19 @@ module Lino
14
14
  ))
15
15
  end
16
16
 
17
+ def with_options(options)
18
+ return self if missing?(options)
19
+
20
+ options.entries.inject(self) do |s, entry|
21
+ s.with_option(
22
+ entry.include?(:option) ? entry[:option] : entry[0],
23
+ entry.include?(:value) ? entry[:value] : entry[1],
24
+ separator: (entry.include?(:separator) ? entry[:separator] : nil),
25
+ quoting: (entry.include?(:quoting) ? entry[:quoting] : nil)
26
+ )
27
+ end
28
+ end
29
+
17
30
  def with_repeated_option(option, values, separator: nil, quoting: nil)
18
31
  values.inject(self) do |s, value|
19
32
  s.with_option(option, value, separator: separator, quoting: quoting)
@@ -21,7 +34,15 @@ module Lino
21
34
  end
22
35
 
23
36
  def with_flag(flag)
37
+ return self if missing?(flag)
38
+
24
39
  with(options: @options.add({ components: [flag] }))
25
40
  end
41
+
42
+ def with_flags(flags)
43
+ return self if missing?(flags)
44
+
45
+ flags.inject(self) { |s, flag| s.with_flag(flag) }
46
+ end
26
47
  end
27
48
  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.0.0.pre.1'
4
+ VERSION = '2.2.0.pre.4'
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.0.0.pre.1
4
+ version: 2.2.0.pre.4
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