tomo 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/tomo/cli.rb +5 -1
- data/lib/tomo/cli/common_options.rb +1 -1
- data/lib/tomo/cli/completions.rb +4 -5
- data/lib/tomo/commands/default.rb +2 -2
- data/lib/tomo/commands/init.rb +2 -2
- data/lib/tomo/plugin/bundler.rb +1 -0
- data/lib/tomo/plugin/bundler/tasks.rb +5 -1
- data/lib/tomo/plugin/git/tasks.rb +1 -3
- data/lib/tomo/ssh/connection.rb +1 -1
- data/lib/tomo/testing.rb +7 -0
- data/lib/tomo/testing/cli_extensions.rb +9 -0
- data/lib/tomo/testing/cli_tester.rb +45 -0
- data/lib/tomo/testing/local.rb +7 -6
- data/lib/tomo/testing/log_capturing.rb +25 -0
- data/lib/tomo/testing/mocked_exit_error.rb +16 -0
- data/lib/tomo/testing/plugin_tester.rb +2 -18
- data/lib/tomo/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecf2cc8af9f664f1144c1b0c17975ecb87ec5f1345e7ffa0b4c919f46287780f
|
4
|
+
data.tar.gz: c805af8340d195a83a636735de9ea14fb630e335582513397ad2694318029725
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb100deafcaef09ed875c7d6100a133638884ca35298163b3621242ca33c178c27fbe6061ee9387f20ba50b5b089ddb0522b9b5184f6d8375b9835dc9d99c399
|
7
|
+
data.tar.gz: e8a67228094bbea79d492d4ab7666de8d1e4cffb902ae6c3c77acc6b6b8bc4d904ecbc1e90a046abc64b7bd81fc0a15be70f355925943bbc59d5cf028e94b2d1
|
data/README.md
CHANGED
@@ -150,7 +150,7 @@ And run it!
|
|
150
150
|
|
151
151
|
And just like that, you are now already familiar with the basics of tomo and how to extend it! Tomo is even more friendly and powerful with the help of bash completions. If you use bash, run `tomo completion-script` for instructions on setting them up.
|
152
152
|
|
153
|
-
To prepare your existing project for a real deploy, check out the sections of the reference documentation on [configuration](https://tomo-deploy.com/configuration/), [writing custom tasks](https://tomo-deploy.com/tutorials/writing-custom-tasks/)
|
153
|
+
To prepare your existing project for a real deploy, check out the sections of the reference documentation on [configuration](https://tomo-deploy.com/configuration/), [writing custom tasks](https://tomo-deploy.com/tutorials/writing-custom-tasks/), the [setup command](https://tomo-deploy.com/commands/setup/), and the [deploy command](https://tomo-deploy.com/commands/deploy/). There is also a tutorial that walks through [deploying a new Rails app from scratch](https://tomo-deploy.com/tutorials/deploying-rails-from-scratch/) [TODO]. If you have questions, check out the [FAQ](#faq) and [support](#support) notes below. Enjoy using tomo!
|
154
154
|
|
155
155
|
## Reference documentation
|
156
156
|
|
@@ -172,7 +172,7 @@ To prepare your existing project for a real deploy, check out the sections of th
|
|
172
172
|
- [rbenv](https://tomo-deploy.com/plugins/rbenv/)
|
173
173
|
- Tutorials
|
174
174
|
- [Deploying Rails From Scratch](https://tomo-deploy.com/tutorials/deploying-rails-from-scratch/) [TODO]
|
175
|
-
- [Writing Custom Tasks](https://tomo-deploy.com/tutorials/writing-custom-tasks/)
|
175
|
+
- [Writing Custom Tasks](https://tomo-deploy.com/tutorials/writing-custom-tasks/)
|
176
176
|
- [Publishing a Plugin](https://tomo-deploy.com/tutorials/publishing-a-plugin/) [TODO]
|
177
177
|
- API
|
178
178
|
- [Host](https://tomo-deploy.com/api/Host/)
|
data/lib/tomo/cli.rb
CHANGED
@@ -19,6 +19,10 @@ module Tomo
|
|
19
19
|
|
20
20
|
class << self
|
21
21
|
attr_accessor :show_backtrace
|
22
|
+
|
23
|
+
def exit(status=true)
|
24
|
+
Process.exit(status)
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
28
|
COMMANDS = {
|
@@ -74,7 +78,7 @@ module Tomo
|
|
74
78
|
error.command_name = command_name if error.respond_to?(:command_name=)
|
75
79
|
Tomo.logger.error(error.to_console)
|
76
80
|
status = error.respond_to?(:exit_status) ? error.exit_status : 1
|
77
|
-
exit(status) unless Tomo::CLI.show_backtrace
|
81
|
+
CLI.exit(status) unless Tomo::CLI.show_backtrace
|
78
82
|
|
79
83
|
raise error
|
80
84
|
end
|
data/lib/tomo/cli/completions.rb
CHANGED
@@ -9,22 +9,21 @@ module Tomo
|
|
9
9
|
defined?(@active) && @active
|
10
10
|
end
|
11
11
|
|
12
|
-
def initialize(literal: false, stdout: $stdout
|
12
|
+
def initialize(literal: false, stdout: $stdout)
|
13
13
|
@literal = literal
|
14
14
|
@stdout = stdout
|
15
|
-
@exit_proc = exit_proc || Kernel.method(:exit)
|
16
15
|
end
|
17
16
|
|
18
17
|
def print_completions_and_exit(rules, *args, state:)
|
19
18
|
completions = completions_for(rules, *args, state)
|
20
19
|
words = completions.map { |c| bash_word_for(c, args.last) }
|
21
|
-
|
22
|
-
|
20
|
+
Tomo.logger.info(words.join("\n")) unless words.empty?
|
21
|
+
CLI.exit
|
23
22
|
end
|
24
23
|
|
25
24
|
private
|
26
25
|
|
27
|
-
attr_reader :literal, :stdout
|
26
|
+
attr_reader :literal, :stdout
|
28
27
|
|
29
28
|
def completions_for(rules, *prefix_args, word, state)
|
30
29
|
all_candidates(rules, prefix_args, state).select do |cand|
|
@@ -5,7 +5,7 @@ module Tomo
|
|
5
5
|
|
6
6
|
option :version, "-v, --version", "Display tomo’s version and exit" do
|
7
7
|
Version.parse([])
|
8
|
-
exit
|
8
|
+
CLI.exit
|
9
9
|
end
|
10
10
|
|
11
11
|
include CLI::CommonOptions
|
@@ -56,7 +56,7 @@ module Tomo
|
|
56
56
|
|
57
57
|
def raise_unrecognized_command(command)
|
58
58
|
error = "#{yellow(command)} is not a recognized tomo command."
|
59
|
-
if command.match?(/\A\S
|
59
|
+
if command.match?(/\A\S+:/)
|
60
60
|
suggestion = "tomo run #{command}"
|
61
61
|
error << "\nMaybe you meant #{blue(suggestion)}?"
|
62
62
|
end
|
data/lib/tomo/commands/init.rb
CHANGED
@@ -46,14 +46,14 @@ module Tomo
|
|
46
46
|
return unless File.exist?(".tomo")
|
47
47
|
|
48
48
|
logger.error("Can't create .tomo directory; a file already exists")
|
49
|
-
exit(1)
|
49
|
+
CLI.exit(1)
|
50
50
|
end
|
51
51
|
|
52
52
|
def assert_no_tomo_project!
|
53
53
|
return unless File.exist?(DEFAULT_CONFIG_PATH)
|
54
54
|
|
55
55
|
logger.error("A #{DEFAULT_CONFIG_PATH} file already exists")
|
56
|
-
exit(1)
|
56
|
+
CLI.exit(1)
|
57
57
|
end
|
58
58
|
|
59
59
|
def current_dir_name
|
data/lib/tomo/plugin/bundler.rb
CHANGED
@@ -11,7 +11,7 @@ module Tomo::Plugin::Bundler
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def upgrade_bundler
|
14
|
-
needed_bundler_ver = extract_bundler_ver_from_lockfile
|
14
|
+
needed_bundler_ver = version_setting || extract_bundler_ver_from_lockfile
|
15
15
|
return if needed_bundler_ver.nil?
|
16
16
|
|
17
17
|
remote.run(
|
@@ -23,6 +23,10 @@ module Tomo::Plugin::Bundler
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
+
def version_setting
|
27
|
+
settings[:bundler_version]
|
28
|
+
end
|
29
|
+
|
26
30
|
def check_options
|
27
31
|
gemfile = settings[:bundler_gemfile]
|
28
32
|
path = paths.bundler
|
@@ -11,9 +11,7 @@ module Tomo::Plugin::Git
|
|
11
11
|
set_origin_url
|
12
12
|
else
|
13
13
|
remote.mkdir_p(paths.git_repo.dirname)
|
14
|
-
remote.git(
|
15
|
-
"clone", "--mirror", settings[:git_url], paths.git_repo
|
16
|
-
)
|
14
|
+
remote.git("clone", "--mirror", settings[:git_url], paths.git_repo)
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
data/lib/tomo/ssh/connection.rb
CHANGED
data/lib/tomo/testing.rb
CHANGED
@@ -2,12 +2,16 @@ require "tomo"
|
|
2
2
|
|
3
3
|
module Tomo
|
4
4
|
module Testing
|
5
|
+
autoload :CLIExtensions, "tomo/testing/cli_extensions"
|
6
|
+
autoload :CLITester, "tomo/testing/cli_tester"
|
5
7
|
autoload :Connection, "tomo/testing/connection"
|
6
8
|
autoload :DockerImage, "tomo/testing/docker_image"
|
7
9
|
autoload :DockerPluginTester, "tomo/testing/docker_plugin_tester"
|
8
10
|
autoload :HostExtensions, "tomo/testing/host_extensions"
|
9
11
|
autoload :Local, "tomo/testing/local"
|
12
|
+
autoload :LogCapturing, "tomo/testing/log_capturing"
|
10
13
|
autoload :MockedExecError, "tomo/testing/mocked_exec_error"
|
14
|
+
autoload :MockedExitError, "tomo/testing/mocked_exit_error"
|
11
15
|
autoload :MockPluginTester, "tomo/testing/mock_plugin_tester"
|
12
16
|
autoload :PluginTester, "tomo/testing/plugin_tester"
|
13
17
|
autoload :RemoteExtensions, "tomo/testing/remote_extensions"
|
@@ -31,6 +35,9 @@ end
|
|
31
35
|
Tomo.logger = Tomo::Logger.new(
|
32
36
|
stdout: File.open(File::NULL, "w"), stderr: File.open(File::NULL, "w")
|
33
37
|
)
|
38
|
+
class << Tomo::CLI
|
39
|
+
prepend Tomo::Testing::CLIExtensions
|
40
|
+
end
|
34
41
|
Tomo::Colors.enabled = false
|
35
42
|
Tomo::Host.prepend Tomo::Testing::HostExtensions
|
36
43
|
Tomo::Remote.prepend Tomo::Testing::RemoteExtensions
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "securerandom"
|
2
|
+
|
3
|
+
module Tomo
|
4
|
+
module Testing
|
5
|
+
class CLITester
|
6
|
+
include Local
|
7
|
+
include LogCapturing
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@token = SecureRandom.hex(8)
|
11
|
+
end
|
12
|
+
|
13
|
+
def run(*args, raise_on_error: true)
|
14
|
+
in_temp_dir(token) do
|
15
|
+
restoring_defaults do
|
16
|
+
capturing_logger_output do
|
17
|
+
handling_exit(raise_on_error) do
|
18
|
+
CLI.new.call(args.flatten)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :token
|
28
|
+
|
29
|
+
def restoring_defaults
|
30
|
+
yield
|
31
|
+
ensure
|
32
|
+
Tomo.debug = false
|
33
|
+
Tomo.dry_run = false
|
34
|
+
Tomo::CLI.show_backtrace = false
|
35
|
+
Tomo::CLI::Completions.instance_variable_set(:@active, false)
|
36
|
+
end
|
37
|
+
|
38
|
+
def handling_exit(raise_on_error)
|
39
|
+
yield
|
40
|
+
rescue Tomo::Testing::MockedExitError => e
|
41
|
+
raise if raise_on_error && !e.success?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/tomo/testing/local.rb
CHANGED
@@ -8,14 +8,14 @@ require "tmpdir"
|
|
8
8
|
module Tomo
|
9
9
|
module Testing
|
10
10
|
module Local
|
11
|
-
def in_temp_dir(&block)
|
12
|
-
Local.in_temp_dir(&block)
|
13
|
-
end
|
14
|
-
|
15
11
|
def with_tomo_gemfile(&block)
|
16
12
|
Local.with_tomo_gemfile(&block)
|
17
13
|
end
|
18
14
|
|
15
|
+
def in_temp_dir(token=nil, &block)
|
16
|
+
Local.in_temp_dir(token, &block)
|
17
|
+
end
|
18
|
+
|
19
19
|
def capture(*command, raise_on_error: true)
|
20
20
|
Local.capture(*command, raise_on_error: raise_on_error)
|
21
21
|
end
|
@@ -29,8 +29,9 @@ module Tomo
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def in_temp_dir(&block)
|
33
|
-
|
32
|
+
def in_temp_dir(token=nil, &block)
|
33
|
+
token ||= SecureRandom.hex(8)
|
34
|
+
dir = File.join(Dir.tmpdir, "tomo_test_#{token}")
|
34
35
|
FileUtils.mkdir_p(dir)
|
35
36
|
Dir.chdir(dir, &block)
|
36
37
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Tomo
|
2
|
+
module Testing
|
3
|
+
module LogCapturing
|
4
|
+
def stdout
|
5
|
+
@stdout_io&.string
|
6
|
+
end
|
7
|
+
|
8
|
+
def stderr
|
9
|
+
@stderr_io&.string
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def capturing_logger_output
|
15
|
+
orig_logger = Tomo.logger
|
16
|
+
@stdout_io = StringIO.new
|
17
|
+
@stderr_io = StringIO.new
|
18
|
+
Tomo.logger = Tomo::Logger.new(stdout: @stdout_io, stderr: @stderr_io)
|
19
|
+
yield
|
20
|
+
ensure
|
21
|
+
Tomo.logger = orig_logger
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Tomo
|
2
|
+
module Testing
|
3
|
+
class MockedExitError < Exception # rubocop:disable Lint/InheritException
|
4
|
+
attr_reader :status
|
5
|
+
|
6
|
+
def initialize(status)
|
7
|
+
@status = status
|
8
|
+
super("tomo exited with status #{status}")
|
9
|
+
end
|
10
|
+
|
11
|
+
def success?
|
12
|
+
status == true || status == 0 # rubocop:disable Style/NumericPredicate
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Tomo
|
2
2
|
module Testing
|
3
3
|
class PluginTester
|
4
|
+
include LogCapturing
|
5
|
+
|
4
6
|
def initialize(*plugin_names, settings: {}, host:)
|
5
7
|
@host = host
|
6
8
|
config = Configuration.new
|
@@ -23,27 +25,9 @@ module Tomo
|
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
def stdout
|
27
|
-
@stdout_io&.string
|
28
|
-
end
|
29
|
-
|
30
|
-
def stderr
|
31
|
-
@stderr_io&.string
|
32
|
-
end
|
33
|
-
|
34
28
|
private
|
35
29
|
|
36
30
|
attr_reader :host, :runtime
|
37
|
-
|
38
|
-
def capturing_logger_output
|
39
|
-
orig_logger = Tomo.logger
|
40
|
-
@stdout_io = StringIO.new
|
41
|
-
@stderr_io = StringIO.new
|
42
|
-
Tomo.logger = Tomo::Logger.new(stdout: @stdout_io, stderr: @stderr_io)
|
43
|
-
yield
|
44
|
-
ensure
|
45
|
-
Tomo.logger = orig_logger
|
46
|
-
end
|
47
31
|
end
|
48
32
|
end
|
49
33
|
end
|
data/lib/tomo/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tomo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Brictson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -264,13 +264,17 @@ files:
|
|
264
264
|
- lib/tomo/templates/config.rb.erb
|
265
265
|
- lib/tomo/testing.rb
|
266
266
|
- lib/tomo/testing/Dockerfile
|
267
|
+
- lib/tomo/testing/cli_extensions.rb
|
268
|
+
- lib/tomo/testing/cli_tester.rb
|
267
269
|
- lib/tomo/testing/connection.rb
|
268
270
|
- lib/tomo/testing/docker_image.rb
|
269
271
|
- lib/tomo/testing/docker_plugin_tester.rb
|
270
272
|
- lib/tomo/testing/host_extensions.rb
|
271
273
|
- lib/tomo/testing/local.rb
|
274
|
+
- lib/tomo/testing/log_capturing.rb
|
272
275
|
- lib/tomo/testing/mock_plugin_tester.rb
|
273
276
|
- lib/tomo/testing/mocked_exec_error.rb
|
277
|
+
- lib/tomo/testing/mocked_exit_error.rb
|
274
278
|
- lib/tomo/testing/plugin_tester.rb
|
275
279
|
- lib/tomo/testing/remote_extensions.rb
|
276
280
|
- lib/tomo/testing/ssh_extensions.rb
|