ruby_git_crypt 0.1.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 58708bdc311759486fd4d818881b53f5cda5f6d535f8e5c00eb53c54e3a1ac55
4
+ data.tar.gz: e00ce54737466951c462d0753cbbe3afac084d1241516c3ace18c324e4bccc22
5
+ SHA512:
6
+ metadata.gz: 803e63d5587c07eb79f138fb17332291f0074616b1b734bd3026446bc19ffa47c6081beb7565f9fffae2d0cf28ea7c8bc61338be1cbf78f124e2890c5a8c43da
7
+ data.tar.gz: e65a13db1734ae9f3e862227e60d8c5fda052a50e42ff0e68956e628cad9b877954d20e7aad3956a4b75a1d8d729ea4a18f6b84ba4aa50650edb82b114026374
@@ -0,0 +1,76 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of
9
+ experience, nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or reject
41
+ comments, commits, code, wiki edits, issues, and other contributions that are
42
+ not aligned to this Code of Conduct, or to ban temporarily or permanently any
43
+ contributor for other behaviors that they deem inappropriate, threatening,
44
+ offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at maintainers@infrablocks.io. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an
62
+ incident. Further details of specific enforcement policies may be posted
63
+ separately.
64
+
65
+ Project maintainers who do not follow or enforce the Code of Conduct in good
66
+ faith may face temporary or permanent repercussions as determined by other
67
+ members of the project's leadership.
68
+
69
+ ## Attribution
70
+
71
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
72
+ version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
73
+
74
+ [homepage]: http://contributor-covenant.org
75
+
76
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in ruby_git_crypt.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,185 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby_git_crypt (0.1.0.pre.1)
5
+ immutable-struct (~> 2.4)
6
+ lino (~> 3.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (7.0.4)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ addressable (2.8.1)
17
+ public_suffix (>= 2.0.2, < 6.0)
18
+ ast (2.4.2)
19
+ coderay (1.1.3)
20
+ colored2 (3.1.2)
21
+ concurrent-ruby (1.1.10)
22
+ diff-lcs (1.5.0)
23
+ docile (1.4.0)
24
+ excon (0.95.0)
25
+ faker (3.1.0)
26
+ i18n (>= 1.8.11, < 2)
27
+ faraday (2.7.2)
28
+ faraday-net_http (>= 2.0, < 3.1)
29
+ ruby2_keywords (>= 0.0.4)
30
+ faraday-net_http (3.0.2)
31
+ ffi (1.15.5)
32
+ formatador (1.1.0)
33
+ gem-release (2.2.2)
34
+ guard (2.18.0)
35
+ formatador (>= 0.2.4)
36
+ listen (>= 2.7, < 4.0)
37
+ lumberjack (>= 1.0.12, < 2.0)
38
+ nenv (~> 0.1)
39
+ notiffany (~> 0.0)
40
+ pry (>= 0.13.0)
41
+ shellany (~> 0.0)
42
+ thor (>= 0.18.1)
43
+ guard-compat (1.2.1)
44
+ guard-rspec (4.7.3)
45
+ guard (~> 2.1)
46
+ guard-compat (~> 1.1)
47
+ rspec (>= 2.99.0, < 4.0)
48
+ hamster (3.0.0)
49
+ concurrent-ruby (~> 1.0)
50
+ i18n (1.12.0)
51
+ concurrent-ruby (~> 1.0)
52
+ immutable-struct (2.4.1)
53
+ json (2.6.3)
54
+ lino (3.1.0)
55
+ hamster (~> 3.0)
56
+ open4 (~> 1.3)
57
+ listen (3.7.1)
58
+ rb-fsevent (~> 0.10, >= 0.10.3)
59
+ rb-inotify (~> 0.9, >= 0.9.10)
60
+ lumberjack (1.2.8)
61
+ method_source (1.0.0)
62
+ minitest (5.17.0)
63
+ nenv (0.3.0)
64
+ notiffany (0.1.3)
65
+ nenv (~> 0.1)
66
+ shellany (~> 0.0)
67
+ octokit (6.0.1)
68
+ faraday (>= 1, < 3)
69
+ sawyer (~> 0.9)
70
+ open4 (1.3.4)
71
+ parallel (1.22.1)
72
+ parser (3.1.3.0)
73
+ ast (~> 2.4.1)
74
+ pry (0.14.1)
75
+ coderay (~> 1.1)
76
+ method_source (~> 1.0)
77
+ public_suffix (5.0.1)
78
+ rainbow (3.1.1)
79
+ rake (13.0.6)
80
+ rake_circle_ci (0.11.0)
81
+ colored2 (~> 3.1)
82
+ excon (~> 0.72)
83
+ rake_factory (~> 0.23)
84
+ sshkey (~> 2.0)
85
+ rake_factory (0.31.0)
86
+ activesupport (>= 4)
87
+ rake (~> 13.0)
88
+ rake_github (0.11.0)
89
+ colored2 (~> 3.1)
90
+ octokit (>= 4.16, < 7.0)
91
+ rake_factory (~> 0.23)
92
+ sshkey (~> 2.0)
93
+ rake_gpg (0.18.0)
94
+ rake_factory (~> 0.23)
95
+ ruby_gpg2 (~> 0.6)
96
+ rake_ssh (0.8.0)
97
+ colored2 (~> 3.1)
98
+ rake_factory (~> 0.23)
99
+ sshkey (~> 2.0)
100
+ rb-fsevent (0.11.2)
101
+ rb-inotify (0.10.1)
102
+ ffi (~> 1.0)
103
+ regexp_parser (2.6.1)
104
+ rexml (3.2.5)
105
+ rspec (3.12.0)
106
+ rspec-core (~> 3.12.0)
107
+ rspec-expectations (~> 3.12.0)
108
+ rspec-mocks (~> 3.12.0)
109
+ rspec-core (3.12.0)
110
+ rspec-support (~> 3.12.0)
111
+ rspec-expectations (3.12.1)
112
+ diff-lcs (>= 1.2.0, < 2.0)
113
+ rspec-support (~> 3.12.0)
114
+ rspec-mocks (3.12.1)
115
+ diff-lcs (>= 1.2.0, < 2.0)
116
+ rspec-support (~> 3.12.0)
117
+ rspec-support (3.12.0)
118
+ rubocop (1.42.0)
119
+ json (~> 2.3)
120
+ parallel (~> 1.10)
121
+ parser (>= 3.1.2.1)
122
+ rainbow (>= 2.2.2, < 4.0)
123
+ regexp_parser (>= 1.8, < 3.0)
124
+ rexml (>= 3.2.5, < 4.0)
125
+ rubocop-ast (>= 1.24.1, < 2.0)
126
+ ruby-progressbar (~> 1.7)
127
+ unicode-display_width (>= 1.4.0, < 3.0)
128
+ rubocop-ast (1.24.1)
129
+ parser (>= 3.1.1.0)
130
+ rubocop-rake (0.6.0)
131
+ rubocop (~> 1.0)
132
+ rubocop-rspec (2.16.0)
133
+ rubocop (~> 1.33)
134
+ ruby-progressbar (1.11.0)
135
+ ruby2_keywords (0.0.5)
136
+ ruby_gpg2 (0.10.0)
137
+ lino (~> 3.0)
138
+ sawyer (0.9.2)
139
+ addressable (>= 2.3.5)
140
+ faraday (>= 0.17.3, < 3)
141
+ shellany (0.0.1)
142
+ simplecov (0.22.0)
143
+ docile (~> 1.1)
144
+ simplecov-html (~> 0.11)
145
+ simplecov_json_formatter (~> 0.1)
146
+ simplecov-html (0.12.3)
147
+ simplecov_json_formatter (0.1.4)
148
+ sshkey (2.0.0)
149
+ terminal-notifier-guard (1.7.0)
150
+ thor (1.2.1)
151
+ tzinfo (2.0.5)
152
+ concurrent-ruby (~> 1.0)
153
+ unicode-display_width (2.3.0)
154
+ webrick (1.7.0)
155
+ yard (0.9.28)
156
+ webrick (~> 1.7.0)
157
+
158
+ PLATFORMS
159
+ arm64-darwin-21
160
+ ruby
161
+ x86_64-darwin-19
162
+ x86_64-linux
163
+
164
+ DEPENDENCIES
165
+ bundler
166
+ faker
167
+ gem-release
168
+ guard
169
+ guard-rspec
170
+ rake
171
+ rake_circle_ci
172
+ rake_github
173
+ rake_gpg
174
+ rake_ssh
175
+ rspec
176
+ rubocop
177
+ rubocop-rake
178
+ rubocop-rspec
179
+ ruby_git_crypt!
180
+ simplecov
181
+ terminal-notifier-guard
182
+ yard
183
+
184
+ BUNDLED WITH
185
+ 2.4.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 InfraBlocks Maintainers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # RubyGitCrypt
2
+
3
+ A simple wrapper around the `git-crypt` binary to allow execution from within
4
+ a Ruby program, RSpec test or Rakefile.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'ruby_git_crypt'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install ruby_git_crypt
21
+
22
+ ## Usage
23
+
24
+ To require `RubyGitCrypt`:
25
+
26
+ ```ruby
27
+ require 'ruby_git_crypt'
28
+ ```
29
+
30
+ ## Documentation
31
+
32
+ * [API docs](https://infrablocks.github.io/ruby_git_crypt/index.html)
33
+
34
+ ## Development
35
+
36
+ To install dependencies and run the build, run the pre-commit build:
37
+
38
+ ```shell
39
+ ./go
40
+ ```
41
+
42
+ This runs all unit tests and other checks including coverage and code linting /
43
+ formatting.
44
+
45
+ To run only the unit tests, including coverage:
46
+
47
+ ```shell
48
+ ./go test:unit
49
+ ```
50
+
51
+ To attempt to fix any code linting / formatting issues:
52
+
53
+ ```shell
54
+ ./go library:fix
55
+ ```
56
+
57
+ To check for code linting / formatting issues without fixing:
58
+
59
+ ```shell
60
+ ./go library:check
61
+ ```
62
+
63
+ You can also run `bin/console` for an interactive prompt that will allow you to
64
+ experiment.
65
+
66
+ ### Managing CircleCI keys
67
+
68
+ To encrypt a GPG key for use by CircleCI:
69
+
70
+ ```shell
71
+ openssl aes-256-cbc \
72
+ -e \
73
+ -md sha1 \
74
+ -in ./config/secrets/ci/gpg.private \
75
+ -out ./.circleci/gpg.private.enc \
76
+ -k "<passphrase>"
77
+ ```
78
+
79
+ To check decryption is working correctly:
80
+
81
+ ```shell
82
+ openssl aes-256-cbc \
83
+ -d \
84
+ -md sha1 \
85
+ -in ./.circleci/gpg.private.enc \
86
+ -k "<passphrase>"
87
+ ```
88
+
89
+ ## Contributing
90
+
91
+ Bug reports and pull requests are welcome on GitHub at
92
+ https://github.com/infrablocks/ruby_git_crypt. This project is intended to be a
93
+ safe, welcoming space for collaboration, and contributors are expected to adhere
94
+ to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
95
+
96
+ ## License
97
+
98
+ The gem is available as open source under the terms of the
99
+ [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,168 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'yard'
5
+ require 'rake_circle_ci'
6
+ require 'rake_github'
7
+ require 'rake_ssh'
8
+ require 'rake_gpg'
9
+ require 'securerandom'
10
+ require 'rspec/core/rake_task'
11
+ require 'rubocop/rake_task'
12
+
13
+ task default: %i[
14
+ library:fix
15
+ test:unit
16
+ ]
17
+
18
+ namespace :encryption do
19
+ namespace :directory do
20
+ desc 'Ensure CI secrets directory exists.'
21
+ task :ensure do
22
+ FileUtils.mkdir_p('config/secrets/ci')
23
+ end
24
+ end
25
+
26
+ namespace :passphrase do
27
+ desc 'Generate encryption passphrase used by CI.'
28
+ task generate: ['directory:ensure'] do
29
+ File.write('config/secrets/ci/encryption.passphrase',
30
+ SecureRandom.base64(36))
31
+ end
32
+ end
33
+ end
34
+
35
+ namespace :keys do
36
+ namespace :deploy do
37
+ RakeSSH.define_key_tasks(
38
+ path: 'config/secrets/ci/',
39
+ comment: 'maintainers@infrablocks.io'
40
+ )
41
+ end
42
+
43
+ namespace :gpg do
44
+ RakeGPG.define_generate_key_task(
45
+ output_directory: 'config/secrets/ci',
46
+ name_prefix: 'gpg',
47
+ owner_name: 'InfraBlocks Maintainers',
48
+ owner_email: 'maintainers@infrablocks.io',
49
+ owner_comment: 'ruby_git_crypt CI Key'
50
+ )
51
+ end
52
+ end
53
+
54
+ namespace :secrets do
55
+ desc 'Regenerate all generatable secrets.'
56
+ task regenerate: %w[
57
+ encryption:passphrase:generate
58
+ keys:deploy:generate
59
+ keys:gpg:generate
60
+ ]
61
+ end
62
+
63
+ RuboCop::RakeTask.new
64
+
65
+ YARD::Rake::YardocTask.new do |t|
66
+ t.files = ['lib/**/*.rb']
67
+ t.options = %w[--embed-mixins --output-dir docs]
68
+ end
69
+
70
+ namespace :library do
71
+ desc 'Run all checks of the library'
72
+ task check: [:rubocop]
73
+
74
+ desc 'Attempt to automatically fix issues with the library'
75
+ task fix: [:'rubocop:autocorrect_all']
76
+ end
77
+
78
+ namespace :documentation do
79
+ desc 'Generate documentation'
80
+ task generate: [:yard]
81
+
82
+ desc 'Commit documentation'
83
+ task :commit, [:skip] do |_, args|
84
+ args.with_defaults(skip: 'true')
85
+
86
+ skip_ci = args.skip == 'true'
87
+
88
+ sh('git', 'commit',
89
+ '-a',
90
+ '-m', "Generate latest documentation#{skip_ci ? ' [ci skip]' : ''}")
91
+ end
92
+
93
+ desc 'Update documentation'
94
+ task update: %i[generate commit]
95
+ end
96
+
97
+ namespace :test do
98
+ RSpec::Core::RakeTask.new(:unit)
99
+ end
100
+
101
+ RakeCircleCI.define_project_tasks(
102
+ namespace: :circle_ci,
103
+ project_slug: 'github/infrablocks/ruby_git_crypt'
104
+ ) do |t|
105
+ circle_ci_config =
106
+ YAML.load_file('config/secrets/circle_ci/config.yaml')
107
+
108
+ t.api_token = circle_ci_config['circle_ci_api_token']
109
+ t.environment_variables = {
110
+ ENCRYPTION_PASSPHRASE:
111
+ File.read('config/secrets/ci/encryption.passphrase')
112
+ .chomp
113
+ }
114
+ t.checkout_keys = []
115
+ t.ssh_keys = [
116
+ {
117
+ hostname: 'github.com',
118
+ private_key: File.read('config/secrets/ci/ssh.private')
119
+ }
120
+ ]
121
+ end
122
+
123
+ RakeGithub.define_repository_tasks(
124
+ namespace: :github,
125
+ repository: 'infrablocks/ruby_git_crypt'
126
+ ) do |t, args|
127
+ github_config =
128
+ YAML.load_file('config/secrets/github/config.yaml')
129
+
130
+ t.access_token = github_config['github_personal_access_token']
131
+ t.deploy_keys = [
132
+ {
133
+ title: 'CircleCI',
134
+ public_key: File.read('config/secrets/ci/ssh.public')
135
+ }
136
+ ]
137
+ t.branch_name = args.branch_name
138
+ t.commit_message = args.commit_message
139
+ end
140
+
141
+ namespace :pipeline do
142
+ desc 'Prepare CircleCI Pipeline'
143
+ task prepare: %i[
144
+ circle_ci:env_vars:ensure
145
+ circle_ci:checkout_keys:ensure
146
+ circle_ci:ssh_keys:ensure
147
+ github:deploy_keys:ensure
148
+ ]
149
+ end
150
+
151
+ namespace :version do
152
+ desc 'Bump version for specified type (pre, major, minor, patch)'
153
+ task :bump, [:type] do |_, args|
154
+ bump_version_for(args.type)
155
+ end
156
+ end
157
+
158
+ desc 'Release gem'
159
+ task :release do
160
+ sh 'gem release --tag --push'
161
+ end
162
+
163
+ def bump_version_for(version_type)
164
+ sh "gem bump --version #{version_type} " \
165
+ '&& bundle install ' \
166
+ '&& export LAST_MESSAGE="$(git log -1 --pretty=%B)" ' \
167
+ '&& git commit -a --amend -m "${LAST_MESSAGE} [ci skip]"'
168
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'ruby_git_crypt'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'lino'
4
+
5
+ require_relative '../errors'
6
+
7
+ module RubyGitCrypt
8
+ module Commands
9
+ class Base
10
+ # rubocop:disable Metrics/AbcSize
11
+
12
+ # Constructs an instance of the command.
13
+ #
14
+ def initialize(**opts)
15
+ @binary = opts[:binary] || RubyGitCrypt.configuration.binary
16
+ @logger = opts[:logger] || RubyGitCrypt.configuration.logger
17
+ @options = opts[:options] || RubyGitCrypt.configuration.options
18
+ @stdin = opts[:stdin] || RubyGitCrypt.configuration.stdin
19
+ @stdout = opts[:stdout] || RubyGitCrypt.configuration.stdout
20
+ @stderr = opts[:stderr] || RubyGitCrypt.configuration.stderr
21
+ end
22
+
23
+ # rubocop:enable Metrics/AbcSize
24
+
25
+ # Executes the command instance.
26
+ #
27
+ # @param [Hash<String, Object>] parameters The parameters used to
28
+ # invoke the command. See subclass documentation for details of
29
+ # supported options.
30
+ # @param [Hash<String, Object>] invocation_options Additional options
31
+ # controlling the invocation of the command.
32
+ # @option invocation_options [Hash<String, String>] :environment A map
33
+ # of environment variables to expose at command invocation time.
34
+ def execute(parameters = {}, invocation_options = {})
35
+ do_before(parameters)
36
+ build_and_execute_command(parameters, invocation_options)
37
+ do_after(parameters)
38
+ rescue Open4::SpawnError
39
+ message = "Failed while running '#{command_name}'."
40
+ logger.error(message)
41
+ raise Errors::ExecutionError, message
42
+ end
43
+
44
+ protected
45
+
46
+ attr_reader :binary, :logger, :stdin, :stdout, :stderr
47
+
48
+ def build_and_execute_command(parameters, invocation_options)
49
+ command = build_command(parameters, invocation_options)
50
+
51
+ logger.debug("Running '#{command}'.")
52
+ command.execute(
53
+ stdin: stdin,
54
+ stdout: stdout,
55
+ stderr: stderr
56
+ )
57
+ end
58
+
59
+ def command_name
60
+ self.class.to_s.split('::')[-1].downcase
61
+ end
62
+
63
+ def do_before(_parameters); end
64
+
65
+ def do_after(_parameters); end
66
+
67
+ private
68
+
69
+ def build_command(parameters, invocation_options)
70
+ parameters = resolve_parameters(parameters)
71
+ environment = invocation_options[:environment] || {}
72
+
73
+ Lino::CommandLineBuilder
74
+ .for_command(@binary)
75
+ .with_environment_variables(environment)
76
+ .with_options_after_subcommands
77
+ .with_option_separator(' ')
78
+ .with_appliables(@options.resolve(options, parameters))
79
+ .with_subcommands(subcommands)
80
+ .with_arguments(arguments(parameters).compact.flatten).build
81
+ end
82
+
83
+ def resolve_parameters(parameters)
84
+ parameter_defaults(parameters)
85
+ .merge(parameters)
86
+ .merge(parameter_overrides(parameters))
87
+ end
88
+
89
+ def parameter_defaults(_parameters)
90
+ {}
91
+ end
92
+
93
+ def parameter_overrides(_parameters)
94
+ {}
95
+ end
96
+
97
+ def subcommands
98
+ []
99
+ end
100
+
101
+ def options
102
+ []
103
+ end
104
+
105
+ def arguments(_parameters)
106
+ []
107
+ end
108
+ end
109
+ end
110
+ end