geordi 2.12.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +8 -2
- data/CHANGELOG.md +8 -0
- data/Gemfile +2 -6
- data/Gemfile.lock +20 -25
- data/README.md +8 -28
- data/Rakefile +6 -10
- data/{bin → exe}/b +0 -0
- data/{bin → exe}/cap-all +0 -0
- data/{bin → exe}/console-for +0 -0
- data/{bin → exe}/cuc +0 -0
- data/{bin → exe}/cuc-show +0 -0
- data/{bin → exe}/cuc-vnc-setup +0 -0
- data/{bin → exe}/deploy-to-production +0 -0
- data/{bin → exe}/dump-for +0 -0
- data/{bin → exe}/dumple +0 -0
- data/{bin → exe}/geordi +0 -2
- data/{bin → exe}/gitpt +0 -0
- data/{bin → exe}/launchy_browser +0 -0
- data/{bin → exe}/load-dump +0 -0
- data/{bin → exe}/migrate-all +0 -0
- data/{bin → exe}/rs +0 -0
- data/{bin → exe}/run_tests +0 -0
- data/{bin → exe}/shell-for +0 -0
- data/{bin → exe}/tests +0 -0
- data/geordi.gemspec +23 -20
- data/lib/geordi/COMMAND_TEMPLATE +2 -3
- data/lib/geordi/capistrano_config.rb +7 -7
- data/lib/geordi/chromedriver_updater.rb +7 -7
- data/lib/geordi/cli.rb +1 -6
- data/lib/geordi/commands/_setup_vnc.rb +1 -1
- data/lib/geordi/commands/apache_site.rb +3 -3
- data/lib/geordi/commands/bundle_install.rb +2 -2
- data/lib/geordi/commands/capistrano.rb +2 -3
- data/lib/geordi/commands/chromedriver_update.rb +0 -9
- data/lib/geordi/commands/clean.rb +2 -4
- data/lib/geordi/commands/commit.rb +0 -1
- data/lib/geordi/commands/console.rb +2 -2
- data/lib/geordi/commands/create_database_yml.rb +2 -2
- data/lib/geordi/commands/create_databases.rb +2 -2
- data/lib/geordi/commands/cucumber.rb +20 -20
- data/lib/geordi/commands/delete_dumps.rb +9 -9
- data/lib/geordi/commands/deploy.rb +12 -13
- data/lib/geordi/commands/drop_databases.rb +12 -14
- data/lib/geordi/commands/dump.rb +5 -6
- data/lib/geordi/commands/eurest.rb +2 -2
- data/lib/geordi/commands/firefox.rb +3 -3
- data/lib/geordi/commands/png_optimize.rb +13 -12
- data/lib/geordi/commands/rake.rb +2 -2
- data/lib/geordi/commands/remove_executable_flags.rb +1 -1
- data/lib/geordi/commands/rspec.rb +6 -6
- data/lib/geordi/commands/security_update.rb +12 -12
- data/lib/geordi/commands/server.rb +5 -5
- data/lib/geordi/commands/setup.rb +5 -5
- data/lib/geordi/commands/shell.rb +2 -2
- data/lib/geordi/commands/unit.rb +1 -1
- data/lib/geordi/commands/update.rb +5 -5
- data/lib/geordi/commands/vnc.rb +1 -1
- data/lib/geordi/commands/with_rake.rb +1 -1
- data/lib/geordi/commands/yarn_install.rb +2 -2
- data/lib/geordi/cucumber.rb +28 -29
- data/lib/geordi/db_cleaner.rb +28 -28
- data/lib/geordi/dump_loader.rb +3 -3
- data/lib/geordi/firefox_for_selenium.rb +11 -12
- data/lib/geordi/gitpt.rb +13 -13
- data/lib/geordi/remote.rb +6 -6
- data/lib/geordi/util.rb +18 -24
- data/lib/geordi/version.rb +1 -1
- metadata +25 -42
- data/features/commit.feature +0 -17
- data/features/console.feature +0 -7
- data/features/cucumber.feature +0 -261
- data/features/deploy.feature +0 -66
- data/features/docker.feature +0 -86
- data/features/dump.feature +0 -34
- data/features/firefox.feature +0 -44
- data/features/server.feature +0 -31
- data/features/setup.feature +0 -11
- data/features/shell.feature +0 -78
- data/features/step_definitions/docker_command_steps.rb +0 -21
- data/features/step_definitions/miscellaneous_steps.rb +0 -11
- data/features/support/aruba.rb +0 -60
- data/features/support/env.rb +0 -9
- data/features/support/step_definitions/aruba_backport_steps.rb +0 -5
- data/lib/geordi/commands/docker.rb +0 -42
- data/lib/geordi/docker.rb +0 -116
data/lib/geordi/db_cleaner.rb
CHANGED
@@ -11,10 +11,10 @@ module Geordi
|
|
11
11
|
puts "We're going to run `sudo -u postgres psql` for PostgreSQL"
|
12
12
|
puts ' and `sudo mysql` for MariaDB (which uses PAM auth)'
|
13
13
|
`sudo true`
|
14
|
-
|
14
|
+
raise 'sudo access is required for database operations as database users' if $CHILD_STATUS != 0
|
15
15
|
@derivative_dbname = /_(test\d*|development|cucumber)$/
|
16
16
|
base_directory = ENV['XDG_CONFIG_HOME']
|
17
|
-
base_directory =
|
17
|
+
base_directory = Dir.home.to_s if base_directory.nil?
|
18
18
|
@whitelist_directory = File.join(base_directory, '.config', 'geordi', 'whitelists')
|
19
19
|
FileUtils.mkdir_p(@whitelist_directory) unless File.directory? @whitelist_directory
|
20
20
|
@mysql_command = decide_mysql_command(extra_flags['mysql'])
|
@@ -23,11 +23,11 @@ module Geordi
|
|
23
23
|
|
24
24
|
def edit_whitelist(dbtype)
|
25
25
|
whitelist = whitelist_fname(dbtype)
|
26
|
-
if File.exist? whitelist
|
27
|
-
|
26
|
+
whitelisted_dbs = if File.exist? whitelist
|
27
|
+
Geordi::Util.stripped_lines(File.read(whitelist))\
|
28
28
|
.delete_if { |l| l.start_with? '#' }
|
29
29
|
else
|
30
|
-
|
30
|
+
[]
|
31
31
|
end
|
32
32
|
all_dbs = list_all_dbs(dbtype)
|
33
33
|
tmp = Tempfile.open("geordi_whitelist_#{dbtype}")
|
@@ -82,16 +82,16 @@ HEREDOC
|
|
82
82
|
texteditor = Geordi::Util.decide_texteditor
|
83
83
|
system("#{texteditor} #{tmp.path}")
|
84
84
|
File.open(tmp.path, 'r') do |wl_edited|
|
85
|
-
whitelisted_dbs =
|
85
|
+
whitelisted_dbs = []
|
86
86
|
whitelist_storage = File.open(whitelist, 'w')
|
87
87
|
lines = Geordi::Util.stripped_lines(wl_edited.read)
|
88
88
|
lines.each do |line|
|
89
89
|
next if line.start_with?('#')
|
90
90
|
unless line.split.length == 2
|
91
|
-
|
91
|
+
raise "Invalid edit to whitelist file: \`#{line}\` - Syntax is: ^[keep|drop] dbname$"
|
92
92
|
end
|
93
93
|
unless %w[keep drop k d].include? line.split.first
|
94
|
-
|
94
|
+
raise "Invalid edit to whitelist file: \`#{line}\` - must start with either drop or keep."
|
95
95
|
end
|
96
96
|
db_status, db_name = line.split
|
97
97
|
if db_status == 'keep'
|
@@ -107,32 +107,32 @@ HEREDOC
|
|
107
107
|
cmd = 'sudo mysql'
|
108
108
|
unless extra_flags.nil?
|
109
109
|
if extra_flags.include? 'port'
|
110
|
-
port = Integer(extra_flags.split('=')[1].split
|
111
|
-
|
110
|
+
port = Integer(extra_flags.split('=')[1].split[0])
|
111
|
+
raise "Port #{port} is not open" unless Geordi::Util.is_port_open? port
|
112
112
|
end
|
113
113
|
cmd << " #{extra_flags}"
|
114
114
|
end
|
115
|
-
Open3.popen3("#{cmd} -e 'QUIT'") do |
|
115
|
+
Open3.popen3("#{cmd} -e 'QUIT'") do |_stdin, _stdout, stderr, thread|
|
116
116
|
break if thread.value.exitstatus == 0
|
117
117
|
# sudo mysql was not successful, switching to mysql-internal user management
|
118
118
|
mysql_error = stderr.read.lines[0].chomp.strip.split[1]
|
119
|
-
if %w[1045 1698].include? mysql_error
|
119
|
+
if %w[1045 1698].include? mysql_error # authentication failed
|
120
120
|
cmd = 'mysql -uroot'
|
121
121
|
cmd << " #{extra_flags}" unless extra_flags.nil?
|
122
122
|
unless File.exist? File.join(Dir.home, '.my.cnf')
|
123
123
|
puts "Please enter your MySQL/MariaDB password for account 'root'."
|
124
124
|
warn "You should create a ~/.my.cnf file instead, or you'll need to enter your MySQL root password for each db."
|
125
|
-
warn
|
126
|
-
cmd << ' -p'
|
125
|
+
warn 'See https://makandracards.com/makandra/50813-store-mysql-passwords-for-development for more information.'
|
126
|
+
cmd << ' -p' # need to ask for password now
|
127
127
|
end
|
128
|
-
Open3.popen3("#{cmd} -e 'QUIT'") do |
|
129
|
-
|
128
|
+
Open3.popen3("#{cmd} -e 'QUIT'") do |_stdin_2, _stdout_2, _stderr_2, thread_2|
|
129
|
+
raise 'Could not connect to MySQL/MariaDB' unless thread_2.value.exitstatus == 0
|
130
130
|
end
|
131
|
-
elsif mysql_error == '2013'
|
132
|
-
|
131
|
+
elsif mysql_error == '2013' # connection to port or socket failed
|
132
|
+
raise 'MySQL/MariaDB connection failed, is this the correct port?'
|
133
133
|
end
|
134
134
|
end
|
135
|
-
|
135
|
+
cmd
|
136
136
|
end
|
137
137
|
private :decide_mysql_command
|
138
138
|
|
@@ -141,22 +141,22 @@ HEREDOC
|
|
141
141
|
unless extra_flags.nil?
|
142
142
|
begin
|
143
143
|
port = Integer(extra_flags.split('=')[1])
|
144
|
-
|
144
|
+
raise "Port #{port} is not open" unless Geordi::Util.is_port_open? port
|
145
145
|
rescue ArgumentError
|
146
146
|
socket = extra_flags.split('=')[1]
|
147
|
-
|
147
|
+
raise "Socket #{socket} does not exist" unless File.exist? socket
|
148
148
|
end
|
149
149
|
cmd << " #{extra_flags}"
|
150
150
|
end
|
151
|
-
|
151
|
+
cmd
|
152
152
|
end
|
153
153
|
private :decide_postgres_command
|
154
154
|
|
155
155
|
def list_all_dbs(dbtype)
|
156
156
|
if dbtype == 'postgres'
|
157
|
-
|
157
|
+
list_all_postgres_dbs
|
158
158
|
else
|
159
|
-
|
159
|
+
list_all_mysql_dbs
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
@@ -224,7 +224,7 @@ HEREDOC
|
|
224
224
|
end
|
225
225
|
case proceed
|
226
226
|
when 'e'
|
227
|
-
proceed = ''
|
227
|
+
proceed = '' # reset user selection
|
228
228
|
edit_whitelist dbtype
|
229
229
|
when 'n'
|
230
230
|
success 'Not deleting anything'
|
@@ -245,10 +245,10 @@ HEREDOC
|
|
245
245
|
end
|
246
246
|
|
247
247
|
def is_whitelisted?(dbtype, database_name)
|
248
|
-
if File.exist? whitelist_fname(dbtype)
|
249
|
-
|
248
|
+
whitelist_content = if File.exist? whitelist_fname(dbtype)
|
249
|
+
Geordi::Util.stripped_lines(File.open(whitelist_fname(dbtype), 'r').read)
|
250
250
|
else
|
251
|
-
|
251
|
+
[]
|
252
252
|
end
|
253
253
|
# Allow explicit whitelisting of derivative databases like projectname_test2
|
254
254
|
if whitelist_content.include? database_name
|
data/lib/geordi/dump_loader.rb
CHANGED
@@ -14,7 +14,7 @@ module Geordi
|
|
14
14
|
def development_database_config
|
15
15
|
require 'yaml'
|
16
16
|
|
17
|
-
@config ||= YAML
|
17
|
+
@config ||= YAML.safe_load(ERB.new(File.read('config/database.yml')).result)
|
18
18
|
@config['development']
|
19
19
|
end
|
20
20
|
alias_method :config, :development_database_config
|
@@ -47,7 +47,7 @@ module Geordi
|
|
47
47
|
available_dumps = Dir.glob(dumps_glob).sort
|
48
48
|
|
49
49
|
HighLine.new.choose(*available_dumps) do |menu|
|
50
|
-
menu.hidden('') {
|
50
|
+
menu.hidden('') { raise 'Abort.' }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -56,7 +56,7 @@ module Geordi
|
|
56
56
|
note 'Source file: ' + dump_file
|
57
57
|
|
58
58
|
source_command = send("#{config['adapter']}_command")
|
59
|
-
Util.system! source_command, :
|
59
|
+
Util.system! source_command, fail_message: "An error occured loading #{File.basename(dump_file)}"
|
60
60
|
end
|
61
61
|
|
62
62
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'tempfile'
|
3
|
-
require File.expand_path('
|
3
|
+
require File.expand_path('interaction', __dir__)
|
4
4
|
|
5
5
|
module Geordi
|
6
6
|
module FirefoxForSelenium
|
7
7
|
extend Geordi::Interaction
|
8
8
|
|
9
9
|
FIREFOX_FOR_SELENIUM_BASE_PATH = Pathname.new('~/bin/firefoxes').expand_path
|
10
|
-
FIREFOX_FOR_SELENIUM_PROFILE_NAME = 'firefox-for-selenium'
|
10
|
+
FIREFOX_FOR_SELENIUM_PROFILE_NAME = 'firefox-for-selenium'.freeze
|
11
11
|
FIREFOX_VERSION_FILE = Pathname.new('.firefox-version')
|
12
12
|
|
13
13
|
def self.install(version)
|
@@ -17,16 +17,16 @@ module Geordi
|
|
17
17
|
def self.path_from_config
|
18
18
|
version = FIREFOX_VERSION_FILE.exist? && File.read(FIREFOX_VERSION_FILE).strip
|
19
19
|
|
20
|
-
if version
|
20
|
+
if version && (version != 'system')
|
21
21
|
unless FirefoxForSelenium.binary(version).exist?
|
22
|
-
warn "Firefox #{
|
22
|
+
warn "Firefox #{version} not found"
|
23
23
|
|
24
24
|
note strip_heredoc(<<-INSTRUCTIONS)
|
25
25
|
Install it with
|
26
|
-
geordi firefox --setup #{
|
26
|
+
geordi firefox --setup #{version}
|
27
27
|
INSTRUCTIONS
|
28
28
|
|
29
|
-
prompt
|
29
|
+
prompt('Run tests anyway?', 'n', /y|yes/) || raise('Cancelled.')
|
30
30
|
end
|
31
31
|
|
32
32
|
path(version)
|
@@ -37,7 +37,7 @@ module Geordi
|
|
37
37
|
FIREFOX_FOR_SELENIUM_BASE_PATH.join(version)
|
38
38
|
end
|
39
39
|
|
40
|
-
def self.binary(version, name =
|
40
|
+
def self.binary(version, name = 'firefox')
|
41
41
|
path(version).join(name)
|
42
42
|
end
|
43
43
|
|
@@ -72,7 +72,7 @@ module Geordi
|
|
72
72
|
private
|
73
73
|
|
74
74
|
def execute_command(cmd)
|
75
|
-
system(cmd)
|
75
|
+
system(cmd) || raise("Error while executing command: #{cmd}")
|
76
76
|
end
|
77
77
|
|
78
78
|
def run_firefox_for_selenium(args = '')
|
@@ -92,7 +92,7 @@ module Geordi
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def original_binary
|
95
|
-
FirefoxForSelenium.binary(@version,
|
95
|
+
FirefoxForSelenium.binary(@version, 'firefox-original')
|
96
96
|
end
|
97
97
|
|
98
98
|
def say_hello
|
@@ -137,7 +137,7 @@ module Geordi
|
|
137
137
|
INSTRUCTION
|
138
138
|
prompt 'Continue?'
|
139
139
|
|
140
|
-
File.file?(binary)
|
140
|
+
File.file?(binary) || raise("Could not find #{binary}")
|
141
141
|
end
|
142
142
|
|
143
143
|
def create_separate_profile
|
@@ -156,7 +156,7 @@ module Geordi
|
|
156
156
|
patched_binary.write strip_heredoc(<<-PATCH)
|
157
157
|
#!/usr/bin/env ruby
|
158
158
|
exec('#{original_binary}', '-no-remote', '-P', '#{FIREFOX_FOR_SELENIUM_PROFILE_NAME}', *ARGV)
|
159
|
-
|
159
|
+
PATCH
|
160
160
|
patched_binary.close
|
161
161
|
execute_command("mv #{patched_binary.path} #{binary}")
|
162
162
|
execute_command("chmod +x #{binary}")
|
@@ -200,4 +200,3 @@ module Geordi
|
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|
203
|
-
|
data/lib/geordi/gitpt.rb
CHANGED
@@ -4,8 +4,8 @@ class Gitpt
|
|
4
4
|
require 'highline'
|
5
5
|
require 'tracker_api'
|
6
6
|
|
7
|
-
SETTINGS_FILE_NAME = '.gitpt'
|
8
|
-
PROJECT_IDS_FILE_NAME = '.pt_project_id'
|
7
|
+
SETTINGS_FILE_NAME = '.gitpt'.freeze
|
8
|
+
PROJECT_IDS_FILE_NAME = '.pt_project_id'.freeze
|
9
9
|
|
10
10
|
def initialize
|
11
11
|
self.highline = HighLine.new
|
@@ -13,7 +13,7 @@ class Gitpt
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def run(git_args)
|
16
|
-
warn <<-WARNING
|
16
|
+
warn <<-WARNING unless Geordi::Util.staged_changes?
|
17
17
|
No staged changes. Will create an empty commit.
|
18
18
|
WARNING
|
19
19
|
|
@@ -30,16 +30,16 @@ No staged changes. Will create an empty commit.
|
|
30
30
|
def read_settings
|
31
31
|
file_path = File.join(ENV['HOME'], SETTINGS_FILE_NAME)
|
32
32
|
|
33
|
-
unless File.
|
33
|
+
unless File.exist?(file_path)
|
34
34
|
highline.say HighLine::RESET
|
35
35
|
highline.say "Welcome to #{bold 'gitpt'}.\n\n"
|
36
36
|
|
37
37
|
highline.say highlight('Your settings are missing or invalid.')
|
38
38
|
highline.say "Please configure your Pivotal Tracker access.\n\n"
|
39
|
-
token = highline.ask bold(
|
39
|
+
token = highline.ask bold('Your API key:') + ' '
|
40
40
|
highline.say "\n"
|
41
41
|
|
42
|
-
settings = { :
|
42
|
+
settings = { token: token }
|
43
43
|
File.open(file_path, 'w') do |file|
|
44
44
|
file.write settings.to_yaml
|
45
45
|
end
|
@@ -49,7 +49,7 @@ No staged changes. Will create an empty commit.
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def build_client(settings)
|
52
|
-
TrackerApi::Client.new(:
|
52
|
+
TrackerApi::Client.new(token: settings.fetch(:token))
|
53
53
|
end
|
54
54
|
|
55
55
|
def load_projects
|
@@ -60,11 +60,11 @@ No staged changes. Will create an empty commit.
|
|
60
60
|
def read_project_ids
|
61
61
|
file_path = PROJECT_IDS_FILE_NAME
|
62
62
|
|
63
|
-
if File.
|
63
|
+
if File.exist?(file_path)
|
64
64
|
project_ids = File.read('.pt_project_id').split(/[\s]+/).map(&:to_i)
|
65
65
|
end
|
66
66
|
|
67
|
-
if project_ids
|
67
|
+
if project_ids && (project_ids.size > 0)
|
68
68
|
project_ids
|
69
69
|
else
|
70
70
|
warn "Sorry, I could not find a project ID in #{file_path} :("
|
@@ -79,19 +79,19 @@ No staged changes. Will create an empty commit.
|
|
79
79
|
def applicable_stories
|
80
80
|
projects = load_projects
|
81
81
|
projects.collect do |project|
|
82
|
-
project.stories(:
|
82
|
+
project.stories(filter: 'state:started,finished,rejected')
|
83
83
|
end.flatten
|
84
84
|
end
|
85
85
|
|
86
86
|
def choose_story
|
87
87
|
if Geordi::Util.testing?
|
88
|
-
return OpenStruct.new(:
|
88
|
+
return OpenStruct.new(id: 12, name: 'Test Story')
|
89
89
|
end
|
90
90
|
|
91
91
|
loading_message = 'Connecting to Pivotal Tracker ...'
|
92
92
|
print(loading_message)
|
93
93
|
stories = applicable_stories
|
94
|
-
reset_loading_message = "\r#{
|
94
|
+
reset_loading_message = "\r#{' ' * (loading_message.length + stories.length)}\r"
|
95
95
|
|
96
96
|
highline.choose do |menu|
|
97
97
|
menu.header = 'Choose a story'
|
@@ -126,7 +126,7 @@ No staged changes. Will create an empty commit.
|
|
126
126
|
|
127
127
|
def create_commit(message, *git_args)
|
128
128
|
extra = highline.ask("\nAdd an optional message").strip
|
129
|
-
message << ' - ' << extra if
|
129
|
+
message << ' - ' << extra if extra != ''
|
130
130
|
|
131
131
|
Geordi::Util.system! 'git', 'commit', '--allow-empty', '-m', message, *git_args
|
132
132
|
end
|
data/lib/geordi/remote.rb
CHANGED
@@ -8,7 +8,7 @@ module Geordi
|
|
8
8
|
class Remote
|
9
9
|
include Geordi::Interaction
|
10
10
|
|
11
|
-
REMOTE_DUMP_PATH = '~/dumps/dump_for_download.dump'
|
11
|
+
REMOTE_DUMP_PATH = '~/dumps/dump_for_download.dump'.freeze
|
12
12
|
|
13
13
|
def initialize(stage)
|
14
14
|
@stage = stage
|
@@ -34,8 +34,8 @@ module Geordi
|
|
34
34
|
def dump(options = {})
|
35
35
|
# Generate dump on the server
|
36
36
|
shell options.merge({
|
37
|
-
:
|
38
|
-
:
|
37
|
+
remote_command: "dumple #{@config.env} --for_download",
|
38
|
+
select_server: nil, # Dump must be generated on the primary server
|
39
39
|
})
|
40
40
|
|
41
41
|
destination_directory = File.join(@config.root, 'tmp')
|
@@ -45,7 +45,7 @@ module Geordi
|
|
45
45
|
|
46
46
|
note "Downloading remote dump to #{relative_destination} ..."
|
47
47
|
server = @config.primary_server
|
48
|
-
Util.system! "scp -C #{
|
48
|
+
Util.system! "scp -C #{@config.user(server)}@#{server}:#{REMOTE_DUMP_PATH} #{destination_path}"
|
49
49
|
|
50
50
|
success "Dumped the #{@stage} database to #{relative_destination}."
|
51
51
|
|
@@ -53,7 +53,7 @@ module Geordi
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def console(options = {})
|
56
|
-
shell(options.merge
|
56
|
+
shell(options.merge(remote_command: Util.console_command(@config.env)))
|
57
57
|
end
|
58
58
|
|
59
59
|
def shell(options = {})
|
@@ -63,7 +63,7 @@ module Geordi
|
|
63
63
|
remote_command << " -c '#{options[:remote_command]}'" if options[:remote_command]
|
64
64
|
|
65
65
|
note 'Connecting to ' + server.to_s
|
66
|
-
Util.system! 'ssh', "#{
|
66
|
+
Util.system! 'ssh', "#{@config.user(server)}@#{server}", '-t', remote_command
|
67
67
|
end
|
68
68
|
|
69
69
|
end
|
data/lib/geordi/util.rb
CHANGED
@@ -10,19 +10,19 @@ module Geordi
|
|
10
10
|
# all employed gems as runtime dependencies because that would
|
11
11
|
# unnecessarily slow down all commands.
|
12
12
|
# Thus, we have this handy method here.
|
13
|
-
def installing_missing_gems
|
13
|
+
def installing_missing_gems
|
14
14
|
yield
|
15
15
|
rescue LoadError => error
|
16
16
|
error.message =~ /-- (\S+)\Z/
|
17
|
-
|
17
|
+
Regexp.last_match(1) || raise # could not extract a gem name from the error message, re-raise the error
|
18
18
|
|
19
|
-
gem_name =
|
19
|
+
gem_name = Regexp.last_match(1).strip.split('/').first
|
20
20
|
install_command = 'gem install ' + gem_name
|
21
21
|
|
22
22
|
# install missing gem
|
23
23
|
warn 'Probably missing gem: ' + gem_name
|
24
|
-
prompt('Install it now?', 'y', /y|yes/)
|
25
|
-
system! install_command, :
|
24
|
+
prompt('Install it now?', 'y', /y|yes/) || raise('Missing Gems.')
|
25
|
+
system! install_command, show_cmd: true
|
26
26
|
|
27
27
|
# retry
|
28
28
|
Gem.clear_paths
|
@@ -42,16 +42,16 @@ module Geordi
|
|
42
42
|
note_cmd commands.join(' ') if options[:show_cmd]
|
43
43
|
|
44
44
|
if options[:confirm]
|
45
|
-
prompt('Run this now?', 'n', /y|yes/)
|
45
|
+
prompt('Run this now?', 'n', /y|yes/) || raise('Cancelled.')
|
46
46
|
end
|
47
47
|
|
48
48
|
if testing?
|
49
|
-
puts "Util.system! #{
|
49
|
+
puts "Util.system! #{commands.join ', '}"
|
50
50
|
else
|
51
51
|
# Remove Geordi's Bundler environment when running commands.
|
52
52
|
success = if !defined?(Bundler)
|
53
53
|
system(*commands)
|
54
|
-
elsif Gem::Version.new(Bundler::VERSION) >= Gem::Version.new('1.
|
54
|
+
elsif Gem::Version.new(Bundler::VERSION) >= Gem::Version.new('2.1.2')
|
55
55
|
Bundler.with_original_env do
|
56
56
|
system(*commands)
|
57
57
|
end
|
@@ -59,7 +59,7 @@ module Geordi
|
|
59
59
|
Bundler.clean_system(*commands)
|
60
60
|
end
|
61
61
|
|
62
|
-
success
|
62
|
+
success || raise(options[:fail_message] || 'Something went wrong.')
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -107,7 +107,7 @@ module Geordi
|
|
107
107
|
# try to guess user's favorite cli text editor
|
108
108
|
def decide_texteditor
|
109
109
|
%w[/usr/bin/editor vi].each do |texteditor|
|
110
|
-
if cmd_exists?
|
110
|
+
if cmd_exists?(texteditor) && texteditor.start_with?('$')
|
111
111
|
return ENV[texteditor[1..-1]]
|
112
112
|
elsif cmd_exists? texteditor
|
113
113
|
return texteditor
|
@@ -116,19 +116,17 @@ module Geordi
|
|
116
116
|
end
|
117
117
|
|
118
118
|
# check if given cmd is executable. Absolute path or command in $PATH allowed.
|
119
|
-
def cmd_exists?
|
119
|
+
def cmd_exists?(cmd)
|
120
120
|
system("which #{cmd} > /dev/null")
|
121
|
-
|
121
|
+
$CHILD_STATUS.exitstatus.zero?
|
122
122
|
end
|
123
123
|
|
124
124
|
def is_port_open?(port)
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
return false
|
131
|
-
end
|
125
|
+
socket = TCPSocket.new('127.0.0.1', port)
|
126
|
+
socket.close
|
127
|
+
true
|
128
|
+
rescue Errno::ECONNREFUSED
|
129
|
+
false
|
132
130
|
end
|
133
131
|
|
134
132
|
# splint lines e.g. read from a file into lines and clean those up
|
@@ -161,12 +159,8 @@ module Geordi
|
|
161
159
|
nil
|
162
160
|
end
|
163
161
|
|
164
|
-
def ruby_version
|
165
|
-
Gem::Version.new(RUBY_VERSION)
|
166
|
-
end
|
167
|
-
|
168
162
|
def file_containing?(file, regex)
|
169
|
-
File.
|
163
|
+
File.exist?(file) && File.read(file).scan(regex).any?
|
170
164
|
end
|
171
165
|
|
172
166
|
def testing?
|