lino 2.1.0 → 2.2.0.pre.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e889c057a237dfb1af77b0adbb0f661ef0cf37193341a6bddd8add27a64f12eb
4
- data.tar.gz: 121d2e75f308626b29b1ac306f959583bd6cc9b18df0fb57b15d993f90f08dd5
3
+ metadata.gz: 729c96dd84a7a44337298eb3de557d061565d5f4defc5bd2077431e20f0917cc
4
+ data.tar.gz: 03c7697d78175ad6e2135540d2babeee039a9cdfd77cbcd789137db66561aa80
5
5
  SHA512:
6
- metadata.gz: 9f1319025180174dbce34687d0cbad930551e2ffad455da8b86ac31f47ba874aef4d012d3f4db23e1dd9de07f15e44a732bf4b937cd95cc1f559b18564fcea4d
7
- data.tar.gz: 8a57fca71f15442bbef99be911bc6284f4e2f87c22425bdf996c09fb8c30429116c2bf3b27d6dca8f91e679f7240b9d1251048273f92c04ddb80c41de2c04b8e
6
+ metadata.gz: 95af24c97c8d11bdbcdd44be3f78a72e0474fa8665f3bf3b67546caf34f6e93c7ba971b94df2efc8ae9a9b6f3e831a17c1dd04e07416fd54d48d9dd5ffed12e3
7
+ data.tar.gz: 151036608c99015ea9494e6ec17b21cb0055e6616d34669ca54009fe7b033b72de5323a240972763d512395ed3374a4d2134865f9ff89db535b5f5ca5bd9ae01
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.5)
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
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'utilities'
4
+
5
+ module Lino
6
+ module Appliables
7
+ include Lino::Utilities
8
+
9
+ def with_appliable(appliable)
10
+ return self if missing?(appliable)
11
+
12
+ appliable.apply(self)
13
+ end
14
+
15
+ def with_appliables(appliables)
16
+ return self if missing?(appliables)
17
+
18
+ appliables.inject(self) do |s, appliable|
19
+ s.with_appliable(appliable)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -5,12 +5,23 @@ require_relative 'utilities'
5
5
  require_relative 'command_line'
6
6
  require_relative 'subcommand_builder'
7
7
  require_relative 'options'
8
+ require_relative 'appliables'
8
9
 
9
10
  module Lino
10
11
  # rubocop:disable Metrics/ClassLength
11
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
+
12
22
  include Lino::Utilities
13
23
  include Lino::Options
24
+ include Lino::Appliables
14
25
 
15
26
  class << self
16
27
  def for_command(command)
@@ -26,7 +37,8 @@ module Lino
26
37
  arguments: [],
27
38
  environment_variables: [],
28
39
  option_separator: ' ',
29
- option_quoting: nil
40
+ option_quoting: nil,
41
+ option_placement: :after_command
30
42
  )
31
43
  @command = command
32
44
  @subcommands = Hamster::Vector.new(subcommands)
@@ -35,6 +47,7 @@ module Lino
35
47
  @environment_variables = Hamster::Vector.new(environment_variables)
36
48
  @option_separator = option_separator
37
49
  @option_quoting = option_quoting
50
+ @option_placement = option_placement
38
51
  end
39
52
  # rubocop:enable Metrics/ParameterLists
40
53
 
@@ -65,6 +78,18 @@ module Lino
65
78
  with(option_quoting: character)
66
79
  end
67
80
 
81
+ def with_options_after_command
82
+ with(option_placement: :after_command)
83
+ end
84
+
85
+ def with_options_after_subcommands
86
+ with(option_placement: :after_subcommands)
87
+ end
88
+
89
+ def with_options_after_arguments
90
+ with(option_placement: :after_arguments)
91
+ end
92
+
68
93
  def with_argument(argument)
69
94
  return self if missing?(argument)
70
95
 
@@ -72,6 +97,8 @@ module Lino
72
97
  end
73
98
 
74
99
  def with_arguments(arguments)
100
+ return self if missing?(arguments)
101
+
75
102
  arguments.inject(self) { |s, argument| s.with_argument(argument) }
76
103
  end
77
104
 
@@ -87,21 +114,27 @@ module Lino
87
114
  end
88
115
 
89
116
  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(' ')
117
+ components = formatted_components
118
+ command_line = SELECTORS[@option_placement]
119
+ .inject([]) { |c, key| c << components[key] }
120
+ .reject(&:empty?)
121
+ .join(' ')
99
122
 
100
- CommandLine.new(command_string)
123
+ CommandLine.new(command_line)
101
124
  end
102
125
 
103
126
  private
104
127
 
128
+ def formatted_components
129
+ {
130
+ environment_variables: formatted_environment_variables,
131
+ command: @command,
132
+ options: formatted_options,
133
+ subcommands: formatted_subcommands,
134
+ arguments: formatted_arguments
135
+ }
136
+ end
137
+
105
138
  def formatted_environment_variables
106
139
  map_and_join(@environment_variables) do |var|
107
140
  "#{var[0]}=\"#{var[1].to_s.gsub(/"/, '\\"')}\""
@@ -140,7 +173,8 @@ module Lino
140
173
  arguments: @arguments,
141
174
  environment_variables: @environment_variables,
142
175
  option_separator: @option_separator,
143
- option_quoting: @option_quoting
176
+ option_quoting: @option_quoting,
177
+ option_placement: @option_placement
144
178
  }
145
179
  end
146
180
  end
data/lib/lino/options.rb CHANGED
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'utilities'
4
+
3
5
  module Lino
4
6
  module Options
7
+ include Lino::Utilities
8
+
5
9
  def with_option(option, value, separator: nil, quoting: nil)
6
10
  return self if missing?(value)
7
11
 
@@ -14,6 +18,19 @@ module Lino
14
18
  ))
15
19
  end
16
20
 
21
+ def with_options(options)
22
+ return self if missing?(options)
23
+
24
+ options.entries.inject(self) do |s, entry|
25
+ 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)
30
+ )
31
+ end
32
+ end
33
+
17
34
  def with_repeated_option(option, values, separator: nil, quoting: nil)
18
35
  values.inject(self) do |s, value|
19
36
  s.with_option(option, value, separator: separator, quoting: quoting)
@@ -21,7 +38,15 @@ module Lino
21
38
  end
22
39
 
23
40
  def with_flag(flag)
41
+ return self if missing?(flag)
42
+
24
43
  with(options: @options.add({ components: [flag] }))
25
44
  end
45
+
46
+ def with_flags(flags)
47
+ return self if missing?(flags)
48
+
49
+ flags.inject(self) { |s, flag| s.with_flag(flag) }
50
+ end
26
51
  end
27
52
  end
@@ -3,11 +3,13 @@
3
3
  require 'hamster'
4
4
  require_relative 'utilities'
5
5
  require_relative 'options'
6
+ require_relative 'appliables'
6
7
 
7
8
  module Lino
8
9
  class SubcommandBuilder
9
10
  include Lino::Utilities
10
11
  include Lino::Options
12
+ include Lino::Appliables
11
13
 
12
14
  class <<self
13
15
  def for_subcommand(subcommand)
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.5'
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.5
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
@@ -222,6 +222,7 @@ files:
222
222
  - bin/console
223
223
  - bin/setup
224
224
  - lib/lino.rb
225
+ - lib/lino/appliables.rb
225
226
  - lib/lino/command_line.rb
226
227
  - lib/lino/command_line_builder.rb
227
228
  - lib/lino/options.rb
@@ -243,9 +244,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
243
244
  version: '2.6'
244
245
  required_rubygems_version: !ruby/object:Gem::Requirement
245
246
  requirements:
246
- - - ">="
247
+ - - ">"
247
248
  - !ruby/object:Gem::Version
248
- version: '0'
249
+ version: 1.3.1
249
250
  requirements: []
250
251
  rubygems_version: 3.0.1
251
252
  signing_key: