tomo 0.2.2 → 0.3.0

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: 5f82eed57d49c1c93977def7e9a8074645470fe6066e73eb9882b5f9bd264020
4
- data.tar.gz: 7c5813c23a7b4c26d8a3f0398b8c340d8efb587fde4f187176a3d1d8d4e08114
3
+ metadata.gz: 5df4b79a1c4cb50739874de698f09346f009a47c11fa99f51d79c6604adb93e4
4
+ data.tar.gz: 7c02ea4319e293ec156b4cf54bad2b06f4c43bbe7f4872d93c24c5b1a75d3f24
5
5
  SHA512:
6
- metadata.gz: 01d1b2909f0aaf19cf0236e300a2817e2f654e8b95cf29f9a3fad6545b943d793b1d33dbf1ecd5df60ae7aa7a7f816874b3d821ebbd39046b9f7ce8ab216bc8f
7
- data.tar.gz: 280ba8250c6c5f0b17f23147862c4245e639d175288fef07abe18fa250d1ee4da31a13cc67963519128b51edca4ed34906da99c244970c5520d362d56849c4b7
6
+ metadata.gz: b803e5bf13962a2ecc92dfd61e332554ec72d45883d99255f4ef2e7464a668653e2579758e013527761ef6f7aa7a2a62e8750dd00883b97640732b914258a37a
7
+ data.tar.gz: a1c0c54ccf105d274c92a6ac84040c7682c7e3c5aae9c0719c7f2e75a202f8c2e6353afed9b483dc3f39e7ee63117ada23ea937fe88f374b24389b41e5bd9222
@@ -6,7 +6,7 @@ module Tomo
6
6
  end
7
7
 
8
8
  def self.active?
9
- !!@active
9
+ defined?(@active) && @active
10
10
  end
11
11
 
12
12
  def initialize(literal: false, stdout: $stdout, exit_proc: nil)
data/lib/tomo/cli.rb CHANGED
@@ -51,14 +51,21 @@ module Tomo
51
51
  argv << "" if argv.shift == "--complete"
52
52
  end
53
53
 
54
+ # rubocop:disable Metrics/CyclomaticComplexity
54
55
  def lookup_command(argv)
55
56
  command_name = argv.first unless Completions.active? && argv.length == 1
56
57
  command_name = Abbrev.abbrev(COMMANDS.keys)[command_name]
57
58
  argv.shift if command_name
58
59
 
60
+ command_name = "run" if command_name.nil? && task_format?(argv.first)
59
61
  command = COMMANDS[command_name] || Tomo::Commands::Default
60
62
  [command, command_name]
61
63
  end
64
+ # rubocop:enable Metrics/CyclomaticComplexity
65
+
66
+ def task_format?(arg)
67
+ arg.to_s.match?(/\A\S+:\S*\z/)
68
+ end
62
69
 
63
70
  def handle_error(error, command_name)
64
71
  return if Completions.active?
@@ -10,6 +10,7 @@ module Tomo
10
10
 
11
11
  include CLI::CommonOptions
12
12
 
13
+ # rubocop:disable Metrics/AbcSize
13
14
  def banner
14
15
  <<~BANNER
15
16
  Usage: #{green('tomo')} #{yellow('COMMAND [options]')}
@@ -19,9 +20,13 @@ module Tomo
19
20
 
20
21
  #{commands.map { |name, help| " #{yellow(name.ljust(10))} #{help}" }.join("\n")}
21
22
 
22
- Tomo accepts abbreviations for its commands. For example, #{blue('tomo deploy')}
23
- can be shortened to #{blue('tomo d')}. You can use bash completions as well!
24
- Run #{blue('tomo completion-script')} for installation instructions.
23
+ The tomo CLI also provides some convenient shortcuts:
24
+
25
+ - Commands can be abbreviated, like #{blue('tomo d')} to run #{blue('tomo deploy')}.
26
+ - When running tasks, the #{yellow('run')} command is implied and can be omitted.
27
+ E.g., #{blue('tomo run rails:console')} can be shortened to #{blue('tomo rails:console')}.
28
+ - Bash completions are also available. Run #{blue('tomo completion-script')} for
29
+ installation instructions.
25
30
 
26
31
  For help with any command, add #{blue('-h')} to the command, like this:
27
32
 
@@ -32,6 +37,7 @@ module Tomo
32
37
  #{blue('https://tomo-deploy.com/')}
33
38
  BANNER
34
39
  end
40
+ # rubocop:enable Metrics/AbcSize
35
41
 
36
42
  def call(*args, options)
37
43
  # The bare `tomo` command (i.e. without `--help` or `--version`) doesn't
@@ -34,6 +34,11 @@ module Tomo
34
34
 
35
35
  #{blue('tomo run core:clean_releases')}
36
36
 
37
+ When you specify a task name, the #{blue('run')} command is implied and can be
38
+ omitted, so this works as well:
39
+
40
+ #{blue('tomo core:clean_releases')}
41
+
37
42
  You can run any task defined by plugins loaded in #{DEFAULT_CONFIG_PATH}.
38
43
  To see a list of available tasks, run #{blue('tomo tasks')}.
39
44
 
@@ -8,24 +8,20 @@ module Tomo::Plugin
8
8
  helpers Tomo::Plugin::Core::Helpers
9
9
  tasks Tomo::Plugin::Core::Tasks
10
10
 
11
- defaults application: "default",
12
- concurrency: 10,
13
- current_path: "%<deploy_to>/current",
14
- deploy_to: "/var/www/%<application>",
15
- keep_releases: 10,
16
- linked_dirs: [],
17
- linked_files: [],
18
- release_json_path: "%<release_path>/.tomo_release.json",
19
- releases_path: "%<deploy_to>/releases",
20
- revision_log_path: "%<deploy_to>/revisions.log",
21
- shared_path: "%<deploy_to>/shared",
22
- tmp_path: "/tmp/tomo",
23
- run_args: [],
24
- ssh_connect_timeout: 5,
25
- ssh_executable: "ssh",
26
- ssh_extra_opts: %w[-o PasswordAuthentication=no],
27
- ssh_forward_agent: true,
28
- ssh_reuse_connections: true,
29
- ssh_strict_host_key_checking: "accept-new"
11
+ defaults Tomo::SSH::Options::DEFAULTS.merge(
12
+ application: "default",
13
+ concurrency: 10,
14
+ current_path: "%<deploy_to>/current",
15
+ deploy_to: "/var/www/%<application>",
16
+ keep_releases: 10,
17
+ linked_dirs: [],
18
+ linked_files: [],
19
+ release_json_path: "%<release_path>/.tomo_release.json",
20
+ releases_path: "%<deploy_to>/releases",
21
+ revision_log_path: "%<deploy_to>/revisions.log",
22
+ shared_path: "%<deploy_to>/shared",
23
+ tmp_path: "/tmp/tomo",
24
+ run_args: []
25
+ )
30
26
  end
31
27
  end
@@ -13,7 +13,7 @@ module Tomo::Plugin::Puma
13
13
 
14
14
  def try_restart
15
15
  ctl_result = remote.chdir(paths.current) do
16
- ctl_result = remote.bundle(
16
+ remote.bundle(
17
17
  "exec", "pumactl", *control_options, "restart",
18
18
  raise_on_error: false,
19
19
  silent: true
@@ -36,7 +36,7 @@ module Tomo
36
36
 
37
37
  def connect(host)
38
38
  Current.with(host: host) do
39
- conn = SSH.connect(host: host, options: SSH::Options.new(settings))
39
+ conn = SSH.connect(host: host, options: ssh_options)
40
40
  remote = Remote.new(conn, context, helper_modules)
41
41
  return remote unless block_given?
42
42
 
@@ -51,6 +51,11 @@ module Tomo
51
51
  private
52
52
 
53
53
  attr_reader :helper_modules, :tasks_by_name
54
+
55
+ def ssh_options
56
+ # TODO: replace with Hash#slice after dropping Ruby 2.4 support
57
+ settings.select { |key| SSH::Options::DEFAULTS.key?(key) }
58
+ end
54
59
  end
55
60
  end
56
61
  end
@@ -1,17 +1,22 @@
1
1
  module Tomo
2
2
  module SSH
3
3
  class Options
4
+ DEFAULTS = {
5
+ ssh_connect_timeout: 5,
6
+ ssh_executable: "ssh".freeze,
7
+ ssh_extra_opts: %w[-o PasswordAuthentication=no].map(&:freeze),
8
+ ssh_forward_agent: true,
9
+ ssh_reuse_connections: true,
10
+ ssh_strict_host_key_checking: "accept-new".freeze
11
+ }.freeze
12
+
4
13
  attr_reader :executable
5
14
 
6
- def initialize(settings)
7
- @executable = settings.fetch(:ssh_executable)
8
- @extra_opts = settings.fetch(:ssh_extra_opts)
9
- @forward_agent = settings.fetch(:ssh_forward_agent)
10
- @reuse_connections = settings.fetch(:ssh_reuse_connections)
11
- @connect_timeout = settings.fetch(:ssh_connect_timeout)
12
- @strict_host_key_checking = settings.fetch(
13
- :ssh_strict_host_key_checking
14
- )
15
+ def initialize(options)
16
+ DEFAULTS.merge(options).each do |attr, value|
17
+ unprefixed_attr = attr.to_s.sub(/^ssh_/, "")
18
+ send(:"#{unprefixed_attr}=", value)
19
+ end
15
20
  freeze
16
21
  end
17
22
 
@@ -33,8 +38,9 @@ module Tomo
33
38
 
34
39
  private
35
40
 
36
- attr_reader :connect_timeout, :extra_opts, :forward_agent,
37
- :reuse_connections, :strict_host_key_checking
41
+ attr_writer :executable
42
+ attr_accessor :connect_timeout, :extra_opts, :forward_agent,
43
+ :reuse_connections, :strict_host_key_checking
38
44
 
39
45
  def control_opts(path, verbose)
40
46
  opts = [
data/lib/tomo/ssh.rb CHANGED
@@ -13,7 +13,9 @@ module Tomo
13
13
  autoload :UnsupportedVersionError, "tomo/ssh/unsupported_version_error"
14
14
 
15
15
  class << self
16
- def connect(host:, options:)
16
+ def connect(host:, options: {})
17
+ options = Options.new(options) unless options.is_a?(Options)
18
+
17
19
  Tomo.logger.connect(host)
18
20
  return Connection.dry_run(host, options) if Tomo.dry_run?
19
21
 
@@ -8,6 +8,18 @@ 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
+ def with_tomo_gemfile(&block)
16
+ Local.with_tomo_gemfile(&block)
17
+ end
18
+
19
+ def capture(*command, raise_on_error: true)
20
+ Local.capture(*command, raise_on_error: raise_on_error)
21
+ end
22
+
11
23
  class << self
12
24
  def with_tomo_gemfile
13
25
  Bundler.with_original_env do
@@ -23,12 +35,13 @@ module Tomo
23
35
  Dir.chdir(dir, &block)
24
36
  end
25
37
 
26
- def capture(command, raise_on_error: true)
27
- progress(command) do
28
- output, status = Open3.capture2e(command)
38
+ def capture(*command, raise_on_error: true)
39
+ command_str = command.join(" ")
40
+ progress(command_str) do
41
+ output, status = Open3.capture2e(*command)
29
42
 
30
43
  if raise_on_error && !status.success?
31
- raise "Command failed: #{command}\n#{output}"
44
+ raise "Command failed: #{command_str}\n#{output}"
32
45
  end
33
46
 
34
47
  output
data/lib/tomo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tomo
2
- VERSION = "0.2.2".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
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.2.2
4
+ version: 0.3.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-09 00:00:00.000000000 Z
11
+ date: 2019-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 0.72.0
117
+ version: 0.73.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 0.72.0
124
+ version: 0.73.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rubocop-performance
127
127
  requirement: !ruby/object:Gem::Requirement