bard 0.64.1 → 0.66.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9d061d17e01a9c194b56cbc5c86ed626e390048c939453f6af87a7b9a136f24
4
- data.tar.gz: 89cbc27d550599e4a8c2eb5287969d19dafdb2176f37d0f65c606966d77542a8
3
+ metadata.gz: 1b9f7c09700f669c4d27c2d9dfa5661fc3b7eab6bb38f80fa09387af65dbfaa3
4
+ data.tar.gz: de2789065284a2506f3951f7d957b6e798d5af2ef03891540c3371ae9629e961
5
5
  SHA512:
6
- metadata.gz: 468913ca2b377d72a317fa44c73a7602445f4a9479d260326be1044598feb727aa13a2d35bebd65d06120eb50ade5960e767ff292f664e602ad394f96a996130
7
- data.tar.gz: d322765c29287237823708b6cb71887d8662445826e61d726c0acfd819526062ffec20a5e79a33f404f959969d8b45ecc9d70f21506f2f9312027c16eab85111
6
+ metadata.gz: 3fa281ed15c4befefce3ee6035ccab28831c8ea2e619b108187c5cb94eb6da29ba53a7df6c50bd4910df50a0bd029d1734daf58de666bff7920c64a93f6f5d38
7
+ data.tar.gz: c7988b2f2f7287a4b74e6b1fb3f5d37aacb91c94741276d252df465213641056edb1906964c17368792b96d5a10b143658949a176b81e3dd2d8bb6bc54bc5ee9
data/lib/bard/base.rb CHANGED
@@ -2,6 +2,7 @@ require "thor"
2
2
  require "term/ansicolor"
3
3
  require "open3"
4
4
  require "uri"
5
+ require "bard/remote_command"
5
6
 
6
7
  class Bard::CLI < Thor
7
8
  include Term::ANSIColor
@@ -34,16 +35,7 @@ class Bard::CLI < Thor
34
35
 
35
36
  def ssh_command server_name, command, home: false
36
37
  server = @config.servers.fetch(server_name.to_sym)
37
- uri = URI.parse("ssh://#{server.ssh}")
38
- ssh_key = server.ssh_key ? "-i #{server.ssh_key} " : ""
39
- command = "#{server.env} #{command}" if server.env
40
- command = "cd #{server.path} && #{command}" unless home
41
- command = "ssh -tt #{ssh_key}#{"-p#{uri.port} " if uri.port}#{uri.user}@#{uri.host} '#{command}'"
42
- if server.gateway
43
- uri = URI.parse("ssh://#{server.gateway}")
44
- command = "ssh -tt #{" -p#{uri.port} " if uri.port}#{uri.user}@#{uri.host} \"#{command}\""
45
- end
46
- command
38
+ Bard::RemoteCommand.new(server, command, home).local_command
47
39
  end
48
40
 
49
41
  def copy direction, server_name, path, verbose: false
data/lib/bard/config.rb CHANGED
@@ -45,10 +45,10 @@ module Bard
45
45
  instance_eval source
46
46
  end
47
47
 
48
- attr_reader :servers
48
+ attr_reader :project_name, :servers
49
49
 
50
50
  def server key, &block
51
- @servers[key] ||= Server.new(@project_name, key)
51
+ @servers[key] ||= Server.new(project_name, key)
52
52
  @servers[key].instance_eval &block if block_given?
53
53
  @servers[key]
54
54
  end
@@ -81,12 +81,10 @@ module Bard
81
81
  setting :ssh, :path, :ping, :gateway, :ssh_key, :env
82
82
 
83
83
  def ping(*args)
84
- if args.length == 1
85
- self.ping = args.first
86
- elsif args.length == 0
87
- normalize_ping(super())
84
+ if args.length == 0
85
+ (super() || [nil]).map(&method(:normalize_ping))
88
86
  else
89
- raise ArgumentError
87
+ self.ping = args
90
88
  end
91
89
  end
92
90
 
data/lib/bard/data.rb CHANGED
@@ -3,7 +3,7 @@ class Bard::CLI < Thor
3
3
  def call
4
4
  if to == "production"
5
5
  server = bard.instance_variable_get(:@config).servers[to.to_sym]
6
- url = server.ping
6
+ url = server.ping.first
7
7
  puts bard.yellow("WARNING: You are about to push data to production, overwriting everything that is there!")
8
8
  answer = bard.ask("If you really want to do this, please type in the full HTTPS url of the production server:")
9
9
  if answer != url
data/lib/bard/ping.rb CHANGED
@@ -8,9 +8,11 @@ module Bard
8
8
  end
9
9
 
10
10
  def call
11
- return true if server.ping == false
12
- response = get_response_with_redirect(server.ping)
13
- response.is_a?(Net::HTTPSuccess)
11
+ server.ping.reject do |url|
12
+ next true if url == false
13
+ response = get_response_with_redirect(url) rescue nil
14
+ response.is_a?(Net::HTTPSuccess)
15
+ end
14
16
  end
15
17
 
16
18
  private
@@ -0,0 +1,22 @@
1
+ module Bard
2
+ class RemoteCommand < Struct.new(:server, :command, :home)
3
+ def local_command
4
+ uri = URI.parse("ssh://#{server.ssh}")
5
+ ssh_key = server.ssh_key ? "-i #{server.ssh_key} " : ""
6
+ cmd = command
7
+ if server.env
8
+ cmd = "#{server.env} #{command}"
9
+ end
10
+ unless home
11
+ cmd = "cd #{server.path} && #{cmd}"
12
+ end
13
+ cmd = "ssh -tt #{ssh_key}#{"-p#{uri.port} " if uri.port}#{uri.user}@#{uri.host} '#{cmd}'"
14
+ if server.gateway
15
+ uri = URI.parse("ssh://#{server.gateway}")
16
+ cmd = "ssh -tt #{" -p#{uri.port} " if uri.port}#{uri.user}@#{uri.host} \"#{cmd}\""
17
+ end
18
+ cmd
19
+ end
20
+ end
21
+ end
22
+
data/lib/bard/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Bard
2
- VERSION = "0.64.1"
2
+ VERSION = "0.66.0"
3
3
  end
4
4
 
data/lib/bard.rb CHANGED
@@ -7,6 +7,7 @@ require "bard/data"
7
7
  require "bard/github"
8
8
  require "bard/ping"
9
9
  require "bard/config"
10
+ require "bard/remote_command"
10
11
 
11
12
  class Bard::CLI < Thor
12
13
  include Thor::Actions
@@ -138,7 +139,7 @@ class Bard::CLI < Thor
138
139
  def open server=nil
139
140
  server ||= @config.servers.key?(:production) ? :production : :staging
140
141
  server = @config.servers[server.to_sym]
141
- exec "xdg-open #{server.default_ping}"
142
+ exec "xdg-open #{server.ping.first}"
142
143
  end
143
144
 
144
145
  desc "hurt", "reruns a command until it fails"
@@ -208,10 +209,19 @@ class Bard::CLI < Thor
208
209
  desc "ping [SERVER=production]", "hits the server over http to verify that its up."
209
210
  def ping server=:production
210
211
  server = @config.servers[server.to_sym]
211
- unless Bard::Ping.call(server)
212
- puts "#{server.key.to_s.capitalize} is down!"
213
- exit 1
214
- end
212
+ down_urls = Bard::Ping.call(server)
213
+ down_urls.each { |url| puts "#{url} is down!" }
214
+ exit 1 if down_urls.any?
215
+ end
216
+
217
+ desc "command <command> --on=production", "run the given command on the remote server"
218
+ method_options %w[on] => :string
219
+ def command command
220
+ default_from = @config.servers.key?(:production) ? "production" : "staging"
221
+ on = options.fetch(:on, default_from)
222
+ server = @config.servers[on.to_sym]
223
+ remote_command = Bard::RemoteCommand.new(server, command).local_command
224
+ run_crucial remote_command, verbose: true
215
225
  end
216
226
 
217
227
  desc "master_key --from=production --to=local", "copy master key from from to to"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.64.1
4
+ version: 0.66.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-14 00:00:00.000000000 Z
11
+ date: 2024-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -157,6 +157,7 @@ files:
157
157
  - lib/bard/git.rb
158
158
  - lib/bard/github.rb
159
159
  - lib/bard/ping.rb
160
+ - lib/bard/remote_command.rb
160
161
  - lib/bard/version.rb
161
162
  - spec/bard/ci/github_actions_spec.rb
162
163
  - spec/bard_spec.rb