lino 1.6.0.pre.1 → 1.10.0.pre.1
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 +4 -4
- data/CODE_OF_CONDUCT.md +1 -1
- data/Gemfile +2 -0
- data/Gemfile.lock +30 -2
- data/README.md +55 -23
- data/Rakefile +62 -42
- data/bin/console +1 -0
- data/lib/lino.rb +2 -0
- data/lib/lino/command_line.rb +14 -10
- data/lib/lino/command_line_builder.rb +81 -45
- data/lib/lino/subcommand_builder.rb +16 -27
- data/lib/lino/switches.rb +34 -0
- data/lib/lino/utilities.rb +23 -7
- data/lib/lino/version.rb +3 -1
- metadata +54 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b2d97cd89debbd53f7eae071f39fd98568652e7771957c1e6584ca3756edc76
|
4
|
+
data.tar.gz: d1e6e64522855b0b0ac7dab0f7d309d4bf79a894bac43690fa965dbc94e4ce02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85f9539da48b728c57ff7725650d5a6fb16c41e401b6313a7bc6dfcfa91747617c21f8732e6b516d4b8f3dd28c21fa96a478b6977b431214d03e335dee3e49b0
|
7
|
+
data.tar.gz: 73ec86a9cfbabc102ee71d83c954541724eaf7454731568e9c00d7f50691e0726a39332a696a3df49f05feedfae72281ed1d79ead14929f88a60c4207b5ba26d
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
|
|
55
55
|
## Enforcement
|
56
56
|
|
57
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at
|
58
|
+
reported by contacting the project team at maintainers@infrablocks.io. All
|
59
59
|
complaints will be reviewed and investigated and will result in a response that
|
60
60
|
is deemed necessary and appropriate to the circumstances. The project team is
|
61
61
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lino (1.
|
4
|
+
lino (1.10.0.pre.1)
|
5
5
|
hamster (~> 3.0)
|
6
6
|
open4 (~> 1.3)
|
7
7
|
|
@@ -16,6 +16,7 @@ GEM
|
|
16
16
|
zeitwerk (~> 2.3)
|
17
17
|
addressable (2.7.0)
|
18
18
|
public_suffix (>= 2.0.2, < 5.0)
|
19
|
+
ast (2.4.2)
|
19
20
|
colored2 (3.1.2)
|
20
21
|
concurrent-ruby (1.1.7)
|
21
22
|
diff-lcs (1.4.4)
|
@@ -37,7 +38,11 @@ GEM
|
|
37
38
|
faraday (>= 0.9)
|
38
39
|
sawyer (~> 0.8.0, >= 0.5.3)
|
39
40
|
open4 (1.3.4)
|
41
|
+
parallel (1.20.1)
|
42
|
+
parser (3.0.0.0)
|
43
|
+
ast (~> 2.4.1)
|
40
44
|
public_suffix (4.0.6)
|
45
|
+
rainbow (3.0.0)
|
41
46
|
rake (13.0.3)
|
42
47
|
rake_circle_ci (0.9.0)
|
43
48
|
colored2 (~> 3.1)
|
@@ -59,6 +64,8 @@ GEM
|
|
59
64
|
colored2 (~> 3.1)
|
60
65
|
rake_factory (~> 0.23)
|
61
66
|
sshkey (~> 2.0)
|
67
|
+
regexp_parser (2.1.1)
|
68
|
+
rexml (3.2.4)
|
62
69
|
rspec (3.10.0)
|
63
70
|
rspec-core (~> 3.10.0)
|
64
71
|
rspec-expectations (~> 3.10.0)
|
@@ -72,6 +79,23 @@ GEM
|
|
72
79
|
diff-lcs (>= 1.2.0, < 2.0)
|
73
80
|
rspec-support (~> 3.10.0)
|
74
81
|
rspec-support (3.10.1)
|
82
|
+
rubocop (1.12.0)
|
83
|
+
parallel (~> 1.10)
|
84
|
+
parser (>= 3.0.0.0)
|
85
|
+
rainbow (>= 2.2.2, < 4.0)
|
86
|
+
regexp_parser (>= 1.8, < 3.0)
|
87
|
+
rexml
|
88
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
89
|
+
ruby-progressbar (~> 1.7)
|
90
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
91
|
+
rubocop-ast (1.4.1)
|
92
|
+
parser (>= 2.7.1.5)
|
93
|
+
rubocop-rake (0.5.1)
|
94
|
+
rubocop
|
95
|
+
rubocop-rspec (2.2.0)
|
96
|
+
rubocop (~> 1.0)
|
97
|
+
rubocop-ast (>= 1.1.0)
|
98
|
+
ruby-progressbar (1.11.0)
|
75
99
|
ruby2_keywords (0.0.2)
|
76
100
|
ruby_gpg2 (0.6.0)
|
77
101
|
lino (>= 1.5)
|
@@ -87,6 +111,7 @@ GEM
|
|
87
111
|
sshkey (2.0.0)
|
88
112
|
tzinfo (2.0.4)
|
89
113
|
concurrent-ruby (~> 1.0)
|
114
|
+
unicode-display_width (2.0.0)
|
90
115
|
zeitwerk (2.4.2)
|
91
116
|
|
92
117
|
PLATFORMS
|
@@ -102,7 +127,10 @@ DEPENDENCIES
|
|
102
127
|
rake_gpg (~> 0.12)
|
103
128
|
rake_ssh (~> 0.4)
|
104
129
|
rspec (~> 3.9)
|
130
|
+
rubocop (~> 1.12)
|
131
|
+
rubocop-rake (~> 0.5)
|
132
|
+
rubocop-rspec (~> 2.2)
|
105
133
|
simplecov (~> 0.16)
|
106
134
|
|
107
135
|
BUNDLED WITH
|
108
|
-
2.2.
|
136
|
+
2.2.15
|
data/README.md
CHANGED
@@ -40,7 +40,8 @@ command_line.execute
|
|
40
40
|
|
41
41
|
### `Lino::CommandLineBuilder`
|
42
42
|
|
43
|
-
The `CommandLineBuilder` allows a number of different styles of commands to be
|
43
|
+
The `CommandLineBuilder` allows a number of different styles of commands to be
|
44
|
+
built:
|
44
45
|
|
45
46
|
```ruby
|
46
47
|
# commands with flags
|
@@ -49,37 +50,53 @@ Lino::CommandLineBuilder.for_command('ls')
|
|
49
50
|
.with_flag('-a')
|
50
51
|
.build
|
51
52
|
.to_s
|
52
|
-
|
53
|
+
|
53
54
|
# => ls -l -a
|
54
|
-
|
55
|
+
|
55
56
|
# commands with options
|
56
57
|
Lino::CommandLineBuilder.for_command('gpg')
|
57
58
|
.with_option('--recipient', 'tobyclemson@gmail.com')
|
58
59
|
.with_option('--sign', './doc.txt')
|
59
60
|
.build
|
60
|
-
.to_s
|
61
|
-
|
61
|
+
.to_s
|
62
|
+
|
62
63
|
# => gpg --recipient tobyclemson@gmail.com --sign ./doc.txt
|
63
|
-
|
64
|
-
# commands with
|
64
|
+
|
65
|
+
# commands with an option repeated multiple times
|
66
|
+
Lino::CommandLineBuilder.for_command('example.sh')
|
67
|
+
.with_repeated_option('--opt', ['file1.txt', nil, '', 'file2.txt'])
|
68
|
+
.build
|
69
|
+
.to_s
|
70
|
+
|
71
|
+
# => example.sh --opt file1.txt --opt file2.txt
|
72
|
+
|
73
|
+
# commands with arguments
|
65
74
|
Lino::CommandLineBuilder.for_command('diff')
|
66
75
|
.with_argument('./file1.txt')
|
67
76
|
.with_argument('./file2.txt')
|
68
77
|
.build
|
69
|
-
.to_s
|
70
|
-
|
78
|
+
.to_s
|
79
|
+
|
71
80
|
# => diff ./file1.txt ./file2.txt
|
72
|
-
|
81
|
+
|
82
|
+
# commands with an array of arguments
|
83
|
+
Lino::CommandLineBuilder.for_command('diff')
|
84
|
+
.with_arguments(['./file1.txt', nil, '', './file2.txt'])
|
85
|
+
.build
|
86
|
+
.to_s
|
87
|
+
|
88
|
+
# => diff ./file1.txt ./file2.txt
|
89
|
+
|
73
90
|
# commands with custom option separator
|
74
91
|
Lino::CommandLineBuilder.for_command('java')
|
75
92
|
.with_option_separator(':')
|
76
93
|
.with_option('-splash', './images/splash.jpg')
|
77
94
|
.with_argument('./application.jar')
|
78
95
|
.build
|
79
|
-
.to_s
|
80
|
-
|
96
|
+
.to_s
|
97
|
+
|
81
98
|
# => java -splash:./images/splash.jpg ./application.jar
|
82
|
-
|
99
|
+
|
83
100
|
# commands using a subcommand style
|
84
101
|
Lino::CommandLineBuilder.for_command('git')
|
85
102
|
.with_flag('--no-pager')
|
@@ -88,9 +105,9 @@ Lino::CommandLineBuilder.for_command('git')
|
|
88
105
|
end
|
89
106
|
.build
|
90
107
|
.to_s
|
91
|
-
|
108
|
+
|
92
109
|
# => git --no-pager log --since 2016-01-01
|
93
|
-
|
110
|
+
|
94
111
|
# commands with multiple levels of subcommand
|
95
112
|
Lino::CommandLineBuilder.for_command('gcloud')
|
96
113
|
.with_subcommand('sql')
|
@@ -131,7 +148,8 @@ command_line.execute
|
|
131
148
|
# => <contents of / directory>
|
132
149
|
```
|
133
150
|
|
134
|
-
By default, the standard input stream is empty and the process writes to the
|
151
|
+
By default, the standard input stream is empty and the process writes to the
|
152
|
+
standard output and error streams.
|
135
153
|
|
136
154
|
To populate standard input:
|
137
155
|
|
@@ -139,7 +157,8 @@ To populate standard input:
|
|
139
157
|
command_line.execute(stdin: 'something to be passed to standard input')
|
140
158
|
```
|
141
159
|
|
142
|
-
The `stdin` option supports any object that responds to `each`, `read` or
|
160
|
+
The `stdin` option supports any object that responds to `each`, `read` or
|
161
|
+
`to_s`.
|
143
162
|
|
144
163
|
To provide custom streams for standard output or standard error:
|
145
164
|
|
@@ -158,16 +177,29 @@ The `stdout` and `stderr` options support any object that responds to `<<`.
|
|
158
177
|
|
159
178
|
## Development
|
160
179
|
|
161
|
-
|
180
|
+
To install dependencies and run the build, run the pre-commit build:
|
162
181
|
|
163
|
-
|
182
|
+
```shell script
|
183
|
+
./go
|
184
|
+
```
|
164
185
|
|
165
|
-
|
186
|
+
To run only the specs:
|
166
187
|
|
167
|
-
|
188
|
+
```shell script
|
189
|
+
./go spec
|
190
|
+
```
|
168
191
|
|
192
|
+
You can also run `bin/console` for an interactive prompt that will allow you to
|
193
|
+
experiment.
|
169
194
|
|
170
|
-
##
|
195
|
+
## Contributing
|
171
196
|
|
172
|
-
|
197
|
+
Bug reports and pull requests are welcome on GitHub at
|
198
|
+
https://github.com/infrablocks/lino. This project is intended to be a safe,
|
199
|
+
welcoming space for collaboration, and contributors are expected to adhere to
|
200
|
+
the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
201
|
+
|
202
|
+
## License
|
173
203
|
|
204
|
+
The gem is available as open source under the terms of the
|
205
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'yaml'
|
2
4
|
require 'rake_circle_ci'
|
3
5
|
require 'rake_github'
|
@@ -5,10 +7,12 @@ require 'rake_ssh'
|
|
5
7
|
require 'rake_gpg'
|
6
8
|
require 'securerandom'
|
7
9
|
require 'rspec/core/rake_task'
|
10
|
+
require 'rubocop/rake_task'
|
8
11
|
|
9
|
-
task :
|
10
|
-
|
11
|
-
|
12
|
+
task default: %i[
|
13
|
+
library:fix
|
14
|
+
test:unit
|
15
|
+
]
|
12
16
|
|
13
17
|
namespace :encryption do
|
14
18
|
namespace :passphrase do
|
@@ -23,83 +27,99 @@ end
|
|
23
27
|
namespace :keys do
|
24
28
|
namespace :deploy do
|
25
29
|
RakeSSH.define_key_tasks(
|
26
|
-
|
27
|
-
|
30
|
+
path: 'config/secrets/ci/',
|
31
|
+
comment: 'maintainers@infrablocks.io'
|
32
|
+
)
|
28
33
|
end
|
29
34
|
|
30
35
|
namespace :gpg do
|
31
36
|
RakeGPG.define_generate_key_task(
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
output_directory: 'config/secrets/ci',
|
38
|
+
name_prefix: 'gpg',
|
39
|
+
owner_name: 'InfraBlocks Maintainers',
|
40
|
+
owner_email: 'maintainers@infrablocks.io',
|
41
|
+
owner_comment: 'lino CI Key'
|
42
|
+
)
|
37
43
|
end
|
38
44
|
end
|
39
45
|
|
46
|
+
RuboCop::RakeTask.new
|
47
|
+
|
48
|
+
namespace :library do
|
49
|
+
desc 'Run all checks of the library'
|
50
|
+
task check: [:rubocop]
|
51
|
+
|
52
|
+
desc 'Attempt to automatically fix issues with the library'
|
53
|
+
task fix: [:'rubocop:auto_correct']
|
54
|
+
end
|
55
|
+
|
56
|
+
namespace :test do
|
57
|
+
RSpec::Core::RakeTask.new(:unit)
|
58
|
+
end
|
59
|
+
|
40
60
|
RakeCircleCI.define_project_tasks(
|
41
|
-
|
42
|
-
|
61
|
+
namespace: :circle_ci,
|
62
|
+
project_slug: 'github/infrablocks/lino'
|
43
63
|
) do |t|
|
44
64
|
circle_ci_config =
|
45
|
-
|
65
|
+
YAML.load_file('config/secrets/circle_ci/config.yaml')
|
46
66
|
|
47
|
-
t.api_token = circle_ci_config[
|
67
|
+
t.api_token = circle_ci_config['circle_ci_api_token']
|
48
68
|
t.environment_variables = {
|
49
|
-
|
50
|
-
|
51
|
-
|
69
|
+
ENCRYPTION_PASSPHRASE:
|
70
|
+
File.read('config/secrets/ci/encryption.passphrase')
|
71
|
+
.chomp
|
52
72
|
}
|
53
73
|
t.checkout_keys = []
|
54
74
|
t.ssh_keys = [
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
75
|
+
{
|
76
|
+
hostname: 'github.com',
|
77
|
+
private_key: File.read('config/secrets/ci/ssh.private')
|
78
|
+
}
|
59
79
|
]
|
60
80
|
end
|
61
81
|
|
62
82
|
RakeGithub.define_repository_tasks(
|
63
|
-
|
64
|
-
|
83
|
+
namespace: :github,
|
84
|
+
repository: 'infrablocks/lino'
|
65
85
|
) do |t|
|
66
86
|
github_config =
|
67
|
-
|
87
|
+
YAML.load_file('config/secrets/github/config.yaml')
|
68
88
|
|
69
|
-
t.access_token = github_config[
|
89
|
+
t.access_token = github_config['github_personal_access_token']
|
70
90
|
t.deploy_keys = [
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
91
|
+
{
|
92
|
+
title: 'CircleCI',
|
93
|
+
public_key: File.read('config/secrets/ci/ssh.public')
|
94
|
+
}
|
75
95
|
]
|
76
96
|
end
|
77
97
|
|
78
98
|
namespace :pipeline do
|
79
|
-
task :
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
99
|
+
task prepare: %i[
|
100
|
+
circle_ci:project:follow
|
101
|
+
circle_ci:env_vars:ensure
|
102
|
+
circle_ci:checkout_keys:ensure
|
103
|
+
circle_ci:ssh_keys:ensure
|
104
|
+
github:deploy_keys:ensure
|
85
105
|
]
|
86
106
|
end
|
87
107
|
|
88
108
|
namespace :version do
|
89
|
-
desc
|
109
|
+
desc 'Bump version for specified type (pre, major, minor, patch)'
|
90
110
|
task :bump, [:type] do |_, args|
|
91
111
|
bump_version_for(args.type)
|
92
112
|
end
|
93
113
|
end
|
94
114
|
|
95
|
-
desc
|
115
|
+
desc 'Release gem'
|
96
116
|
task :release do
|
97
|
-
sh
|
117
|
+
sh 'gem release --tag --push'
|
98
118
|
end
|
99
119
|
|
100
120
|
def bump_version_for(version_type)
|
101
|
-
sh "gem bump --version #{version_type} "
|
102
|
-
|
103
|
-
|
104
|
-
|
121
|
+
sh "gem bump --version #{version_type} " \
|
122
|
+
'&& bundle install ' \
|
123
|
+
'&& export LAST_MESSAGE="$(git log -1 --pretty=%B)" ' \
|
124
|
+
'&& git commit -a --amend -m "${LAST_MESSAGE} [ci skip]"'
|
105
125
|
end
|
data/bin/console
CHANGED
data/lib/lino.rb
CHANGED
data/lib/lino/command_line.rb
CHANGED
@@ -1,24 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'open4'
|
2
4
|
|
3
5
|
module Lino
|
4
6
|
class CommandLine
|
5
|
-
def initialize
|
7
|
+
def initialize(command_line)
|
6
8
|
@command_line = command_line
|
7
9
|
end
|
8
10
|
|
9
11
|
def execute(
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
stdin: '',
|
13
|
+
stdout: $stdout,
|
14
|
+
stderr: $stderr
|
15
|
+
)
|
16
|
+
Open4.spawn(
|
17
|
+
@command_line,
|
18
|
+
stdin: stdin,
|
19
|
+
stdout: stdout,
|
20
|
+
stderr: stderr
|
21
|
+
)
|
18
22
|
end
|
19
23
|
|
20
24
|
def to_s
|
21
25
|
@command_line
|
22
26
|
end
|
23
27
|
end
|
24
|
-
end
|
28
|
+
end
|
@@ -1,26 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hamster'
|
2
4
|
require_relative 'utilities'
|
3
5
|
require_relative 'command_line'
|
4
6
|
require_relative 'subcommand_builder'
|
7
|
+
require_relative 'switches'
|
5
8
|
|
6
9
|
module Lino
|
10
|
+
# rubocop:disable Metrics/ClassLength
|
7
11
|
class CommandLineBuilder
|
8
12
|
include Lino::Utilities
|
13
|
+
include Lino::Switches
|
9
14
|
|
10
|
-
class <<self
|
15
|
+
class << self
|
11
16
|
def for_command(command)
|
12
17
|
CommandLineBuilder.new(command: command)
|
13
18
|
end
|
14
19
|
end
|
15
20
|
|
21
|
+
# rubocop:disable Metrics/ParameterLists
|
16
22
|
def initialize(
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
23
|
+
command: nil,
|
24
|
+
subcommands: [],
|
25
|
+
switches: [],
|
26
|
+
arguments: [],
|
27
|
+
environment_variables: [],
|
28
|
+
option_separator: ' ',
|
29
|
+
option_quoting: nil
|
30
|
+
)
|
24
31
|
@command = command
|
25
32
|
@subcommands = Hamster::Vector.new(subcommands)
|
26
33
|
@switches = Hamster::Vector.new(switches)
|
@@ -29,18 +36,16 @@ module Lino
|
|
29
36
|
@option_separator = option_separator
|
30
37
|
@option_quoting = option_quoting
|
31
38
|
end
|
39
|
+
# rubocop:enable Metrics/ParameterLists
|
32
40
|
|
33
41
|
def with_subcommand(subcommand, &block)
|
34
|
-
with(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
separator: separator,
|
42
|
-
quoting: quoting
|
43
|
-
}))
|
42
|
+
with(
|
43
|
+
subcommands: @subcommands.add(
|
44
|
+
(block || ->(sub) { sub }).call(
|
45
|
+
SubcommandBuilder.for_subcommand(subcommand)
|
46
|
+
)
|
47
|
+
)
|
48
|
+
)
|
44
49
|
end
|
45
50
|
|
46
51
|
def with_option_separator(option_separator)
|
@@ -51,55 +56,86 @@ module Lino
|
|
51
56
|
with(option_quoting: character)
|
52
57
|
end
|
53
58
|
|
54
|
-
def
|
55
|
-
with(
|
59
|
+
def with_argument(argument)
|
60
|
+
with(arguments: add_argument(argument))
|
56
61
|
end
|
57
62
|
|
58
|
-
def
|
59
|
-
|
63
|
+
def with_arguments(arguments)
|
64
|
+
arguments.each { |argument| add_argument(argument) }
|
65
|
+
with({})
|
60
66
|
end
|
61
67
|
|
62
68
|
def with_environment_variable(environment_variable, value)
|
63
|
-
with(
|
69
|
+
with(
|
70
|
+
environment_variables:
|
71
|
+
@environment_variables.add(
|
72
|
+
[
|
73
|
+
environment_variable, value
|
74
|
+
]
|
75
|
+
)
|
76
|
+
)
|
64
77
|
end
|
65
78
|
|
66
79
|
def build
|
67
80
|
components = [
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
&(quote_with(@option_quoting) >> join_with(@option_separator))),
|
74
|
-
map_and_join(@subcommands) { |sub|
|
75
|
-
sub.build(@option_separator, @option_quoting)
|
76
|
-
},
|
77
|
-
map_and_join(@arguments, &join_with(' '))
|
81
|
+
formatted_environment_variables,
|
82
|
+
@command,
|
83
|
+
formatted_switches,
|
84
|
+
formatted_subcommands,
|
85
|
+
formatted_arguments
|
78
86
|
]
|
79
87
|
|
80
|
-
command_string = components
|
81
|
-
.reject { |item| item.empty? }
|
82
|
-
.join(' ')
|
88
|
+
command_string = components.reject(&:empty?).join(' ')
|
83
89
|
|
84
90
|
CommandLine.new(command_string)
|
85
91
|
end
|
86
92
|
|
87
93
|
private
|
88
94
|
|
89
|
-
def
|
95
|
+
def formatted_environment_variables
|
96
|
+
map_and_join(@environment_variables) do |var|
|
97
|
+
"#{var[0]}=\"#{var[1].to_s.gsub(/"/, '\\"')}\""
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def formatted_switches
|
102
|
+
map_and_join(
|
103
|
+
@switches,
|
104
|
+
&(quote_with(@option_quoting) >> join_with(@option_separator))
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
def formatted_subcommands
|
109
|
+
map_and_join(@subcommands) do |sub|
|
110
|
+
sub.build(@option_separator, @option_quoting)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def formatted_arguments
|
115
|
+
map_and_join(@arguments, &join_with(' '))
|
116
|
+
end
|
117
|
+
|
118
|
+
def with(**replacements)
|
90
119
|
CommandLineBuilder.new(**state.merge(replacements))
|
91
120
|
end
|
92
121
|
|
93
122
|
def state
|
94
123
|
{
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
124
|
+
command: @command,
|
125
|
+
subcommands: @subcommands,
|
126
|
+
switches: @switches,
|
127
|
+
arguments: @arguments,
|
128
|
+
environment_variables: @environment_variables,
|
129
|
+
option_separator: @option_separator,
|
130
|
+
option_quoting: @option_quoting
|
102
131
|
}
|
103
132
|
end
|
133
|
+
|
134
|
+
def add_argument(argument)
|
135
|
+
return @arguments if missing?(argument)
|
136
|
+
|
137
|
+
@arguments = @arguments.add({ components: [argument] })
|
138
|
+
end
|
104
139
|
end
|
105
|
-
|
140
|
+
# rubocop:enable Metrics/ClassLength
|
141
|
+
end
|
@@ -1,58 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hamster'
|
2
4
|
require_relative 'utilities'
|
5
|
+
require_relative 'switches'
|
3
6
|
|
4
7
|
module Lino
|
5
8
|
class SubcommandBuilder
|
6
9
|
include Lino::Utilities
|
10
|
+
include Lino::Switches
|
7
11
|
|
8
12
|
class <<self
|
9
|
-
def for_subcommand
|
13
|
+
def for_subcommand(subcommand)
|
10
14
|
SubcommandBuilder.new(subcommand: subcommand)
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
14
|
-
def initialize(
|
15
|
-
subcommand: nil,
|
16
|
-
switches: [])
|
18
|
+
def initialize(subcommand: nil, switches: [])
|
17
19
|
@subcommand = subcommand
|
18
20
|
@switches = Hamster::Vector.new(switches)
|
19
21
|
end
|
20
22
|
|
21
|
-
def with_option(switch, value, separator: nil, quoting: nil)
|
22
|
-
with(switches: @switches.add({
|
23
|
-
components: [switch, value],
|
24
|
-
separator: separator,
|
25
|
-
quoting: quoting
|
26
|
-
}))
|
27
|
-
end
|
28
|
-
|
29
|
-
def with_flag(flag)
|
30
|
-
with(switches: @switches.add({components: [flag]}))
|
31
|
-
end
|
32
|
-
|
33
23
|
def build(option_separator, option_quoting)
|
34
24
|
components = [
|
35
|
-
|
36
|
-
|
37
|
-
|
25
|
+
@subcommand,
|
26
|
+
map_and_join(
|
27
|
+
@switches,
|
28
|
+
&(quote_with(option_quoting) >> join_with(option_separator))
|
29
|
+
)
|
38
30
|
]
|
39
|
-
|
40
|
-
components
|
41
|
-
.reject { |item| item.empty? }
|
42
|
-
.join(' ')
|
31
|
+
components.reject(&:empty?).join(' ')
|
43
32
|
end
|
44
33
|
|
45
34
|
private
|
46
35
|
|
47
|
-
def with
|
36
|
+
def with(**replacements)
|
48
37
|
SubcommandBuilder.new(**state.merge(replacements))
|
49
38
|
end
|
50
39
|
|
51
40
|
def state
|
52
41
|
{
|
53
|
-
|
54
|
-
|
42
|
+
subcommand: @subcommand,
|
43
|
+
switches: @switches
|
55
44
|
}
|
56
45
|
end
|
57
46
|
end
|
58
|
-
end
|
47
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
data/lib/lino/utilities.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pp'
|
2
4
|
|
3
5
|
module Lino
|
@@ -14,16 +16,30 @@ module Lino
|
|
14
16
|
|
15
17
|
def quote_with(global_character)
|
16
18
|
lambda do |item|
|
19
|
+
item.merge(
|
20
|
+
components: resolve_components(item, global_character)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def missing?(value)
|
26
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def resolve_components(item, global_character)
|
32
|
+
components = item[:components]
|
33
|
+
switch = components[0]
|
34
|
+
|
35
|
+
if components.count > 1
|
17
36
|
character = item[:quoting] || global_character
|
18
|
-
components = item[:components]
|
19
|
-
switch = components[0]
|
20
37
|
value = components[1]
|
21
38
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
components)
|
39
|
+
[switch, "#{character}#{value}#{character}"]
|
40
|
+
else
|
41
|
+
components
|
26
42
|
end
|
27
43
|
end
|
28
44
|
end
|
29
|
-
end
|
45
|
+
end
|
data/lib/lino/version.rb
CHANGED
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.
|
4
|
+
version: 1.10.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:
|
11
|
+
date: 2021-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hamster
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: gem-release
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,33 +109,33 @@ dependencies:
|
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0.5'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
112
|
+
name: rake_gpg
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0.
|
117
|
+
version: '0.12'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0.
|
124
|
+
version: '0.12'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
126
|
+
name: rake_ssh
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - "~>"
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version: '0.
|
131
|
+
version: '0.4'
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version: '0.
|
138
|
+
version: '0.4'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: rspec
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,19 +151,47 @@ dependencies:
|
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: '3.9'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
154
|
+
name: rubocop
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
157
|
- - "~>"
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
159
|
+
version: '1.12'
|
146
160
|
type: :development
|
147
161
|
prerelease: false
|
148
162
|
version_requirements: !ruby/object:Gem::Requirement
|
149
163
|
requirements:
|
150
164
|
- - "~>"
|
151
165
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
166
|
+
version: '1.12'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rubocop-rake
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.5'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0.5'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rubocop-rspec
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '2.2'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '2.2'
|
153
195
|
- !ruby/object:Gem::Dependency
|
154
196
|
name: simplecov
|
155
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -183,6 +225,7 @@ files:
|
|
183
225
|
- lib/lino/command_line.rb
|
184
226
|
- lib/lino/command_line_builder.rb
|
185
227
|
- lib/lino/subcommand_builder.rb
|
228
|
+
- lib/lino/switches.rb
|
186
229
|
- lib/lino/utilities.rb
|
187
230
|
- lib/lino/version.rb
|
188
231
|
homepage: https://github.com/infrablocks/lino
|