brightpearl-cli 2.5.0 → 2.6.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 +4 -4
- data/lib/brightpearl_cli.rb +28 -45
- data/lib/core/config.rb +14 -1
- data/lib/core/config_unique.rb +16 -9
- data/lib/core/enums.rb +2 -11
- data/lib/core/git.rb +66 -11
- data/lib/core/pom.rb +16 -30
- data/lib/core/sql_update.rb +115 -7
- data/lib/core/ssh.rb +160 -0
- data/lib/core/terminal.rb +23 -3
- data/lib/core/tools.rb +1 -1
- data/lib/core/utils_files.rb +5 -12
- data/lib/core/utils_tools.rb +83 -0
- data/lib/routes/fix.rb +12 -26
- data/lib/routes/git_checkout.rb +2 -2
- data/lib/routes/git_merge.rb +102 -46
- data/lib/routes/git_update.rb +9 -0
- data/lib/routes/scripts_branch_cleaner.rb +44 -10
- data/lib/routes/scripts_sonar.rb +16 -2
- data/lib/routes/ssh.rb +1 -46
- data/lib/routes/tail.rb +30 -16
- data/lib/routes/test.rb +20 -28
- data/lib/version.rb +1 -1
- data/vm-scripts/fix-sql-mode.sh +3 -0
- data/vm-scripts/run-behat-tests.sh +7 -0
- data/vm-scripts/run-phpunit-tests.sh +5 -0
- data/vm-scripts/tail-access.sh +3 -0
- data/vm-scripts/tail-catalina.sh +3 -0
- data/vm-scripts/tail-php.sh +3 -0
- data/vm-scripts/tail-phpunit.sh +3 -0
- metadata +11 -5
- data/lib/core/vm.rb +0 -62
- data/lib/routes/dummy_order.rb +0 -150
- data/vm-scripts/sql-updates.sh +0 -9
data/lib/core/pom.rb
CHANGED
@@ -38,23 +38,25 @@ module App
|
|
38
38
|
|
39
39
|
end
|
40
40
|
|
41
|
-
def self.unsnapshot_files(files_to_change,
|
41
|
+
def self.unsnapshot_files(files_to_change, current_branch_code, add_branch_tag = true, first_answer = nil, second_answer = nil, third_answer = nil)
|
42
42
|
|
43
43
|
unless files_to_change.any?
|
44
44
|
App::Terminal::info('No feature-tagged POMs found', 'Nothing to un-snapshot.')
|
45
45
|
return
|
46
46
|
end
|
47
47
|
|
48
|
-
unless App::
|
49
|
-
App::Terminal::
|
48
|
+
unless first_answer == App::Enum::YES
|
49
|
+
if first_answer == App::Enum::NO || App::Terminal::prompt_yes_no('Un-snapshot POMs', generate_confirmation_text(files_to_change)) == false
|
50
|
+
App::Terminal::abort
|
51
|
+
end
|
50
52
|
end
|
51
53
|
|
52
54
|
files_to_change.each do |filename|
|
53
55
|
App::Terminal::output("Un-snapshotting: #{App::Terminal::format_directory(filename)}")
|
54
|
-
if
|
56
|
+
if current_branch_code == App::Git::MASTER || add_branch_tag == false
|
55
57
|
new_snapshot_tag = '-SNAPSHOT'
|
56
58
|
else
|
57
|
-
new_snapshot_tag = "-#{
|
59
|
+
new_snapshot_tag = "-#{current_branch_code}-SNAPSHOT"
|
58
60
|
end
|
59
61
|
contents = File.read(filename)
|
60
62
|
contents_new = contents.gsub(/-(.*)-SNAPSHOT/, new_snapshot_tag)
|
@@ -79,51 +81,35 @@ module App
|
|
79
81
|
|
80
82
|
if red_versions != green_versions
|
81
83
|
unless App::Terminal::prompt_yes_no('POM version conflict occurred', ['Unable to successfully Un-snapshot POMs.', 'Please fix the POM versions before continuing.'], 'POMs fixed and ready to continue?')
|
82
|
-
App::Terminal::abort
|
84
|
+
App::Terminal::abort
|
83
85
|
end
|
84
86
|
end
|
85
87
|
|
86
88
|
App::Terminal::command_capture(['git add .', 'git status'], App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
87
89
|
|
88
90
|
# Figure out the commit message.
|
89
|
-
git = App::Git.new
|
90
|
-
current_branch_name = git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
91
|
+
@git = App::Git.new
|
92
|
+
current_branch_name = @git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
91
93
|
if current_branch_name =~ /\A(bp|bug)-\d{4,5}\z/i
|
92
94
|
jira_number = current_branch_name.gsub(/\D/, '')
|
93
95
|
else
|
94
96
|
jira_number = '0000'
|
95
97
|
end
|
96
98
|
|
97
|
-
if
|
99
|
+
if current_branch_code == App::Git::MASTER
|
98
100
|
commit_message = "BP-#{jira_number} Removed POM tags."
|
99
101
|
else
|
100
|
-
commit_message = "BP-#{jira_number} Updated POM tags on #{
|
102
|
+
commit_message = "BP-#{jira_number} Updated POM tags on #{current_branch_code}."
|
101
103
|
end
|
102
104
|
|
103
|
-
git = App::Git.new
|
105
|
+
@git = App::Git.new
|
104
106
|
|
105
|
-
if git.current_branch_for_repo(App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_CODE)) == App::Git::MASTER
|
107
|
+
if @git.current_branch_for_repo(App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_CODE)) == App::Git::MASTER
|
106
108
|
App::Terminal::info('Un-snapshotting complete', ["Your POMs have been un-snapshotted. However, nothing has been committed to Git or pushed to origin because you are on #{App::Git::MASTER}.", 'You will need to do this manually.'], false)
|
107
109
|
else
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
if App::Terminal::prompt_yes_no('Commit to GIT', ["This will commit your changes to GIT with message: #{App::Terminal::format_highlight(commit_message)}"])
|
112
|
-
App::Terminal::command(["git commit -m '#{commit_message.gsub("'", "\\'")}'"], App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
113
|
-
else
|
114
|
-
App::Terminal::info('Un-snapshotting complete', "Please note that your changes #{App::Terminal::format_highlight('HAVE NOT')} been #{App::Terminal::format_action('committed')} to Git.", false)
|
115
|
-
return
|
116
|
-
end
|
117
|
-
|
118
|
-
if App::Terminal::prompt_yes_no('Push changes to origin')
|
119
|
-
App::Terminal::command('git push', App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
|
120
|
-
App::Terminal::info('Un-snapshotting complete', "Your POMs have been un-snapshotted, the changes #{App::Terminal::format_action('committed')} to Git and #{App::Terminal::format_action('pushed')} to origin.")
|
121
|
-
else
|
122
|
-
App::Terminal::info('Un-snapshotting complete', ["Your POMs have been un-snapshotted and the changes #{App::Terminal::format_action('committed')} to Git.", 'However, nothing has been pushed to origin. You will need to do this manually.'], false)
|
123
|
-
end
|
124
|
-
|
110
|
+
if @git.changes_exist(App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_CODE))
|
111
|
+
@git.ask_to_commit_to_git(commit_message, App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE), second_answer, third_answer)
|
125
112
|
end
|
126
|
-
|
127
113
|
end
|
128
114
|
|
129
115
|
end
|
data/lib/core/sql_update.rb
CHANGED
@@ -2,21 +2,129 @@ module App
|
|
2
2
|
|
3
3
|
class SqlUpdate
|
4
4
|
|
5
|
-
def self.run_sql_update
|
5
|
+
def self.run_sql_update(branch_to_run_on = nil, skip_first_confirm = false)
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
@git = App::Git::new
|
8
|
+
|
9
|
+
branch_to_run_on = @git.current_branch_for_repo(App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_DB)) if branch_to_run_on.nil?
|
10
|
+
jira_number = @git.resolve_jira_for_branch(branch_to_run_on)
|
11
|
+
|
12
|
+
unless skip_first_confirm
|
13
|
+
unless App::Terminal::prompt_yes_no("You're about to run the SQL update script for #{App::Terminal::format_highlight("BP-#{jira_number}")} on branch #{App::Terminal::format_branch(@git.current_branch_for_repo(App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_DB)))}", ["Please note this script is still in #{App::Terminal::format_highlight('BETA')} and will only work under certain (assumed) circumstances."])
|
14
|
+
App::Terminal::abort
|
15
|
+
end
|
9
16
|
end
|
10
17
|
|
11
18
|
@git = App::Git::new
|
12
19
|
|
13
|
-
|
14
|
-
|
20
|
+
update_performed = false
|
21
|
+
fail_message = ["An automatic SQL update #{App::Terminal::format_invalid('could not', true)}\x1B[38;5;240m be performed.", "You can either do this #{App::Terminal::format_action('manually')} or exit the script."]
|
22
|
+
fail_confirmation = "Have you #{App::Terminal::format_highlight('made altered the necessary files')}\x1B[38;5;89m and #{App::Terminal::format_action('committed')}\x1B[38;5;89m the changes?"
|
23
|
+
|
24
|
+
unless jira_number =~ /\d{4,5}/i
|
25
|
+
unless App::Terminal::prompt_yes_no("No #{App::Terminal::format_highlight('jira number')} could be resolved for branch #{App::Terminal::format_branch(branch_to_run_on)}", fail_message, fail_confirmation)
|
26
|
+
App::Terminal::abort
|
27
|
+
end
|
28
|
+
return
|
29
|
+
end
|
30
|
+
|
31
|
+
sandpit_files = get_sandpit_files(jira_number)
|
32
|
+
|
33
|
+
unless sandpit_files.any?
|
34
|
+
unless App::Terminal::prompt_yes_no("No #{App::Terminal::format_highlight('sandpit files')} found for jira number: #{App::Terminal::format_action(jira_number)}", fail_message, fail_confirmation)
|
35
|
+
App::Terminal::abort
|
36
|
+
end
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
sandpit_files.each do |file|
|
41
|
+
new_file_contents = []
|
42
|
+
new_file_contents_output = []
|
43
|
+
script_run_line_found = false
|
44
|
+
latest_sql_index = get_latest_unused_sql_index
|
45
|
+
file_contents = App::UtilsFiles::read_file(file)
|
46
|
+
file_contents.each do |line|
|
47
|
+
if line =~ /\A\s*(#+|-{2,}).*(sql_script_run|leave\s+.+;|end\s+if\s*;)/i
|
48
|
+
new_file_contents_output << "\x1B[38;5;196m- #{line.gsub("\n", '')}\x1B[0m"
|
49
|
+
|
50
|
+
# REMOVE COMMENTS
|
51
|
+
if line =~ /\A\s*#+/i
|
52
|
+
new_line = line.sub(/#+/i, '')
|
53
|
+
elsif line =~ /\A\s*-{2,}/i
|
54
|
+
new_line = line.sub(/-{2,}/i, '')
|
55
|
+
else
|
56
|
+
new_line = line
|
57
|
+
end
|
58
|
+
|
59
|
+
# UPDATE SQL INDEX
|
60
|
+
if new_line =~ /script_index\s*=\s*('|")\S*('|")/i
|
61
|
+
new_line = new_line.sub(/script_index\s*=\s*('|")\S*('|")/i, "script_index = '#{get_latest_unused_sql_index}'")
|
62
|
+
elsif new_line =~ /sql_script_run\s+values\s+\(('|")\S*('|")\s*,/i
|
63
|
+
new_line = new_line.sub(/sql_script_run\s+values\s+\(('|")\S*('|")\s*,/i, "sql_script_run VALUES ('#{get_latest_unused_sql_index}',")
|
64
|
+
end
|
15
65
|
|
16
|
-
|
66
|
+
new_file_contents_output << "\x1B[38;5;10m+ #{new_line.gsub("\n", '')}\x1B[0m"
|
67
|
+
new_file_contents << new_line.gsub("\n", '')
|
68
|
+
else
|
69
|
+
new_file_contents_output << "\x1B[38;5;240m. #{line.gsub("\n", '')}\x1B[0m"
|
70
|
+
new_file_contents << line.gsub("\n", '')
|
71
|
+
end
|
17
72
|
|
18
|
-
|
73
|
+
# IF SQL_INDEX INSERT IS FOUND..
|
74
|
+
if line =~ /insert\s+into\s+sql_script_run\s+values\s+\(/i
|
75
|
+
script_run_line_found = true
|
76
|
+
end
|
19
77
|
|
78
|
+
end
|
79
|
+
if script_run_line_found == false
|
80
|
+
sql_index_insert_statement = "INSERT INTO sql_script_run VALUES ('#{latest_sql_index}', NOW(), 1);"
|
81
|
+
new_file_contents_output << "\x1B[38;5;10m+ #{sql_index_insert_statement}\x1B[0m"
|
82
|
+
new_file_contents << sql_index_insert_statement
|
83
|
+
end
|
84
|
+
new_sql_filename = "#{latest_sql_index}.sql"
|
85
|
+
new_sql_filename_full = "#{App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_DB)}/brightpearl/structure/#{new_sql_filename}"
|
86
|
+
if App::Terminal::prompt_yes_no('SQL changes', new_file_contents_output, "Would you like to #{App::Terminal::format_action('apply')}\x1B[38;5;89m these changes and create #{App::Terminal::format_directory(new_sql_filename)} ?")
|
87
|
+
App::Terminal::output("\x1B[38;5;46mCREATING: #{new_sql_filename_full}\x1B[0m")
|
88
|
+
App::UtilsFiles::write_file(new_sql_filename_full, new_file_contents)
|
89
|
+
App::Terminal::command("git add brightpearl/structure/#{new_sql_filename}", App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_DB))
|
90
|
+
App::Terminal::output("\x1B[38;5;196mDELETING: #{file}\x1B[0m")
|
91
|
+
App::UtilsFiles::delete_file(file)
|
92
|
+
update_performed = true
|
93
|
+
else
|
94
|
+
App::Terminal::warning('SQL update not processed', ["Sandpit file found but not processed: #{App::Terminal::format_directory(file)}", "Either this is your intention or it will need to be done #{App::Terminal::format_action('manually')}."])
|
95
|
+
App::Terminal::any_key_to_continue(" Press any key to #{App::Terminal::format_highlight('acknowledge you understand')}...")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
if update_performed
|
100
|
+
@git.ask_to_commit_to_git("BP-#{jira_number} SQL Update [auto-script].", App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_DB))
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.get_sandpit_files(jira_number)
|
106
|
+
App::Terminal::output('Checking for sandpit files...')
|
107
|
+
sql_update_files = []
|
108
|
+
sandpit_files = App::UtilsFiles::get_files_in_dir("#{App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_DB)}/brightpearl/sandpit")
|
109
|
+
sandpit_files.each do |file|
|
110
|
+
file_basename = File.basename(file)
|
111
|
+
if file_basename =~ /#{jira_number}/i
|
112
|
+
sql_update_files << file
|
113
|
+
App::Terminal::output("Found: #{App::Terminal::format_directory(file_basename)}", App::Terminal::MSG_AUTOMATIC)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
sql_update_files
|
117
|
+
end
|
118
|
+
|
119
|
+
# Gets the latest (unused) SQL index .
|
120
|
+
# @return Integer
|
121
|
+
def self.get_latest_unused_sql_index
|
122
|
+
sql_numbers = []
|
123
|
+
current_sql_files = App::UtilsFiles::get_files_in_dir("#{App::Config.param(ConfigUnique::WORKSTATION_PATH_TO_BP_DB)}/brightpearl/structure")
|
124
|
+
current_sql_files.each do |file|
|
125
|
+
sql_numbers << File.basename(file).gsub(/.sql/i, '').strip.to_i
|
126
|
+
end
|
127
|
+
(sql_numbers[sql_numbers.length - 1] + 1).to_s.rjust(4, '0')
|
20
128
|
end
|
21
129
|
|
22
130
|
end
|
data/lib/core/ssh.rb
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
module App
|
2
|
+
|
3
|
+
class SSH
|
4
|
+
|
5
|
+
SCRIPT_PATH = 'vm-scripts/'
|
6
|
+
|
7
|
+
# SSH into remote host.
|
8
|
+
# @return void
|
9
|
+
def self.ssh_into_remote(config_key)
|
10
|
+
ssh_user, ssh_host, ssh_cert = get_ssh_credentials(config_key)
|
11
|
+
ssh_into_remote_credentials(ssh_user, ssh_host, ssh_cert)
|
12
|
+
end
|
13
|
+
|
14
|
+
# SSH into remote with pre-supplied credentials.
|
15
|
+
# @return void
|
16
|
+
def self.ssh_into_remote_credentials(ssh_user, ssh_host, ssh_cert = nil)
|
17
|
+
if ssh_cert.nil?
|
18
|
+
App::Terminal::command("ssh #{ssh_user}@#{ssh_host}", nil, false, false)
|
19
|
+
else
|
20
|
+
App::Terminal::command("ssh -i #{ssh_cert} #{ssh_user}@#{ssh_host}", nil, false, false)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Source can be a file or directory but whatever it is, target must be the same (a file or directory).
|
25
|
+
# @return void
|
26
|
+
def self.scp_to_remote(config_key, source, target)
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# SCPs a script to a remote host and runs it.
|
31
|
+
# @return void
|
32
|
+
def self.run_script_on_remote(config_key, script_name, args = nil, run_as_root = false)
|
33
|
+
ssh_user, ssh_host, ssh_cert = get_ssh_credentials(config_key)
|
34
|
+
run_script_on_remote_credentials(ssh_user, ssh_host, ssh_cert, script_name, args, run_as_root)
|
35
|
+
end
|
36
|
+
|
37
|
+
# SCPs a script to remote and runs it with pre-supplied credentials.
|
38
|
+
# @return void
|
39
|
+
def self.run_script_on_remote_credentials(ssh_user, ssh_host, ssh_cert, script_name, args = nil, run_as_root = false)
|
40
|
+
script_path_local = "#{App::UtilsTools::get_base_path}/#{App::SSH::SCRIPT_PATH}#{script_name}"
|
41
|
+
script_path_remote = "/tmp/#{script_name}" # Time.now.to_i
|
42
|
+
check_script_exists(script_name)
|
43
|
+
scp_script_to_vm(script_path_local, script_path_remote, ssh_user, ssh_host, ssh_cert)
|
44
|
+
args = args.nil? ? [] : args
|
45
|
+
command("chmod 0755 #{script_path_remote}", ssh_user, ssh_host, ssh_cert)
|
46
|
+
command_execute_message("#{script_path_remote} #{args.join(' ')}")
|
47
|
+
display_script_content(script_path_local)
|
48
|
+
command("#{script_path_remote} #{args.join(' ')}", ssh_user, ssh_host, ssh_cert, false)
|
49
|
+
command("rm #{script_path_remote}", ssh_user, ssh_host, ssh_cert)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
# Get SSH credentials from the config file.
|
55
|
+
# @return Array
|
56
|
+
def self.get_ssh_credentials(config_key)
|
57
|
+
ssh_parts = App::Config.get_custom_key('ssh_', config_key).split('|')
|
58
|
+
ssh_user = ssh_parts[0]
|
59
|
+
ssh_host = ssh_parts[1]
|
60
|
+
ssh_cert = ssh_parts[2].to_s.strip.length == 0 ? nil : ssh_parts[2]
|
61
|
+
help_message = [
|
62
|
+
"The file: #{App::Terminal::format_directory(ConfigUnique::CONFIG_FILE)} must contain a line similar to the following:",
|
63
|
+
nil,
|
64
|
+
'ssh_ec2=ec2-user|ec2-XX-XX-XX-XX.eu-west-1.compute.amazonaws.com|~/.ssh/pem-key.pem',
|
65
|
+
'ssh_ec2=ec2-user|ec2-XX-XX-XX-XX.eu-west-1.compute.amazonaws.com',
|
66
|
+
]
|
67
|
+
App::Terminal::error("SSH #{App::Terminal::format_highlight('user')} required", help_message, true) if ssh_user.nil? || ssh_user == ''
|
68
|
+
App::Terminal::error("SSH #{App::Terminal::format_highlight('host')} required", help_message, true) if ssh_host.nil? || ssh_host == ''
|
69
|
+
unless ssh_cert.nil?
|
70
|
+
unless App::UtilsFiles::file_exists(File.expand_path(ssh_cert))
|
71
|
+
App::Terminal::error("PEM key not found: #{App::Terminal::format_directory(ssh_cert)}")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
return ssh_user, ssh_host, ssh_cert
|
75
|
+
end
|
76
|
+
|
77
|
+
# Check script exists.
|
78
|
+
# @return void
|
79
|
+
def self.check_script_exists(script_name)
|
80
|
+
App::Terminal::output("Fetching: #{App::Terminal::format_directory("#{SCRIPT_PATH}#{script_name}")}")
|
81
|
+
scripts = get_all_scripts.keys
|
82
|
+
unless scripts.include?(script_name)
|
83
|
+
App::Terminal::error("Script doesn't exist: #{App::Terminal::format_invalid(script_name)}", nil, true)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Returns all script files as hash, IE: {'sql-updates' => '/Library/Ruby/Gems/2.0.0/gems/brightpearl-cli-1.4.0/vm-scripts/sql-updates.sh'}
|
88
|
+
# @return Hash
|
89
|
+
def self.get_all_scripts
|
90
|
+
return_hash = {}
|
91
|
+
all_scripts = App::UtilsFiles::get_files_in_dir("#{App::UtilsTools::get_base_path}/vm-scripts")
|
92
|
+
all_scripts.each do |file|
|
93
|
+
return_hash[File.basename(file)] = file
|
94
|
+
end
|
95
|
+
return_hash
|
96
|
+
end
|
97
|
+
|
98
|
+
# Check that SSHPASS is installed.
|
99
|
+
# @return void
|
100
|
+
def self.check_sshpass_is_installed
|
101
|
+
App::UtilsTools::check_sshpass_is_installed
|
102
|
+
end
|
103
|
+
|
104
|
+
# Copy script to VM.
|
105
|
+
# @return void
|
106
|
+
def self.scp_script_to_vm(script_path_local, script_path_remote, ssh_user, ssh_host, ssh_cert)
|
107
|
+
App::Terminal::output("Local: #{script_path_local}")
|
108
|
+
App::Terminal::output("Remote: #{script_path_remote}")
|
109
|
+
App::Terminal::output("scp to \xe2\x86\x92 #{App::Terminal::format_highlight(ssh_host)}")
|
110
|
+
if ssh_cert.nil?
|
111
|
+
App::Terminal::command("scp #{script_path_local} #{ssh_user}@#{ssh_host}:#{script_path_remote}", nil, false, false)
|
112
|
+
else
|
113
|
+
App::Terminal::command("scp -i #{ssh_cert} #{script_path_local} #{ssh_user}@#{ssh_host}:#{script_path_remote}", nil, false, false)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
# Runs a series of commands on the VM.
|
118
|
+
# @return void
|
119
|
+
def self.command(commands, ssh_user, ssh_host, ssh_cert, verbose = true)
|
120
|
+
unless commands.is_a?(Array)
|
121
|
+
commands = [commands]
|
122
|
+
end
|
123
|
+
if commands.any?
|
124
|
+
commands.each do |command|
|
125
|
+
if verbose
|
126
|
+
command_execute_message(command)
|
127
|
+
end
|
128
|
+
if ssh_cert.nil?
|
129
|
+
App::Terminal::command("ssh #{ssh_user}@#{ssh_host} '#{command}'", nil, false, false)
|
130
|
+
else
|
131
|
+
App::Terminal::command("ssh -i #{ssh_cert} #{ssh_user}@#{ssh_host} '#{command}'", nil, false, false)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Custom Terminal::output clone only used here).
|
138
|
+
# @return void
|
139
|
+
def self.command_execute_message(command)
|
140
|
+
puts "\x1B[48;5;136m Executing \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m #{App::Terminal::format_command("#{command}")}"
|
141
|
+
end
|
142
|
+
|
143
|
+
# DISPLAY SCRIPT CONTENT
|
144
|
+
# @return void
|
145
|
+
def self.display_script_content(script_path_local)
|
146
|
+
script_content = App::Terminal::command_capture("cat #{script_path_local}", nil, false, false)
|
147
|
+
if script_content[0] != ''
|
148
|
+
puts
|
149
|
+
script_content[0].split("\n").each do |line|
|
150
|
+
if line.strip != ''
|
151
|
+
puts "\x1B[38;5;95m #{line}\x1B[0m"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
puts
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
data/lib/core/terminal.rb
CHANGED
@@ -14,6 +14,7 @@ module App
|
|
14
14
|
MSG_AUTOMATIC = 'automatic'
|
15
15
|
MSG_GENERATED = 'generated'
|
16
16
|
MSG_PROCESSED = 'processed'
|
17
|
+
MSG_CUSTOM = 'custom'
|
17
18
|
|
18
19
|
# Runs a series of commands in the terminal.
|
19
20
|
# @return void
|
@@ -63,8 +64,9 @@ module App
|
|
63
64
|
end
|
64
65
|
|
65
66
|
# Outputs messages to the terminal.
|
67
|
+
# If CUSTOM, title must be 11 characters to match existing scheme.
|
66
68
|
# @return void
|
67
|
-
def self.output(message = 'No message', type = MSG_INFO)
|
69
|
+
def self.output(message = 'No message', type = MSG_INFO, title = nil, bg_color = nil)
|
68
70
|
case type
|
69
71
|
when MSG_INFO
|
70
72
|
puts "\x1B[48;5;2m Executing \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m \x1B[0m#{message}\x1B[0m"
|
@@ -80,6 +82,10 @@ module App
|
|
80
82
|
puts "\x1B[48;5;96m Generated \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m \x1B[0m#{message}\x1B[0m"
|
81
83
|
when MSG_PROCESSED
|
82
84
|
puts "\x1B[48;5;238m Processed \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m \x1B[0m#{message}\x1B[0m"
|
85
|
+
when MSG_CUSTOM
|
86
|
+
raise RuntimeError, "'title' cannot be nil." if title.nil?
|
87
|
+
raise RuntimeError, "'bg_color' cannot be nil." if bg_color.nil?
|
88
|
+
puts "\x1B[48;5;#{bg_color}m#{title}\x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m \x1B[0m#{message}\x1B[0m"
|
83
89
|
else
|
84
90
|
puts "'#{type}' is not a valid Terminal::output() type."
|
85
91
|
exit
|
@@ -88,7 +94,7 @@ module App
|
|
88
94
|
|
89
95
|
# Displays error and exits script by default.
|
90
96
|
# @return void
|
91
|
-
def self.abort(title = nil, message = nil, exit_script = true, preceding_blank_line =
|
97
|
+
def self.abort(title = nil, message = nil, exit_script = true, preceding_blank_line = false)
|
92
98
|
if title.nil?
|
93
99
|
title = 'Abandon ship!'
|
94
100
|
end
|
@@ -114,6 +120,20 @@ module App
|
|
114
120
|
end
|
115
121
|
end
|
116
122
|
|
123
|
+
# Displays automatic message.
|
124
|
+
# @return void
|
125
|
+
def self.automatic(title = nil, message = nil, preceding_blank_line = true)
|
126
|
+
if title.nil?
|
127
|
+
title = 'Something is happening automatically...'
|
128
|
+
end
|
129
|
+
if preceding_blank_line
|
130
|
+
puts
|
131
|
+
end
|
132
|
+
puts "\x1B[48;5;96m Automatic \x1B[0m \xe2\x86\x92 #{title}"
|
133
|
+
parse_messages(message)
|
134
|
+
end
|
135
|
+
|
136
|
+
|
117
137
|
# Displays info message.
|
118
138
|
# @return void
|
119
139
|
def self.info(title = nil, message = nil, preceding_blank_line = true)
|
@@ -270,11 +290,11 @@ module App
|
|
270
290
|
|
271
291
|
# Gives a prompt where ANY KEY will continue executing the script.
|
272
292
|
# @return void
|
273
|
-
# @deprecated
|
274
293
|
def self.any_key_to_continue(text = "\n\x1B[90mPress any key to continue\x1B[0m => ")
|
275
294
|
STDOUT.flush
|
276
295
|
print "#{text}"
|
277
296
|
STDIN.gets
|
297
|
+
puts
|
278
298
|
nil
|
279
299
|
end
|
280
300
|
|