brightpearl-cli 1.3.0 → 1.4.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.
Files changed (46) hide show
  1. checksums.yaml +5 -13
  2. data/bin/bp +1 -1
  3. data/bin/brightpearl +1 -1
  4. data/lib/brightpearl_cli.rb +161 -168
  5. data/lib/core/api.rb +1 -1
  6. data/lib/core/config.rb +10 -133
  7. data/lib/core/config_unique.rb +113 -0
  8. data/lib/core/encrypter.rb +6 -6
  9. data/lib/core/enums.rb +1 -1
  10. data/lib/core/git.rb +123 -108
  11. data/lib/core/git_delete.rb +89 -0
  12. data/lib/core/jira.rb +2 -2
  13. data/lib/core/mysql.rb +14 -14
  14. data/lib/core/pom.rb +129 -0
  15. data/lib/core/terminal.rb +28 -8
  16. data/lib/core/tools.rb +6 -6
  17. data/lib/core/utils_files.rb +92 -0
  18. data/lib/core/utils_routes.rb +25 -0
  19. data/lib/core/utils_strings.rb +45 -0
  20. data/lib/core/validate.rb +1 -1
  21. data/lib/routes/build.rb +16 -17
  22. data/lib/routes/dummy_order.rb +5 -5
  23. data/lib/routes/fix.rb +49 -0
  24. data/lib/routes/git_branch.rb +6 -6
  25. data/lib/routes/git_checkout.rb +42 -33
  26. data/lib/routes/git_delete.rb +8 -62
  27. data/lib/routes/git_merge.rb +198 -111
  28. data/lib/routes/git_pull.rb +11 -11
  29. data/lib/routes/git_push.rb +21 -12
  30. data/lib/routes/git_stash.rb +13 -8
  31. data/lib/routes/git_update.rb +17 -22
  32. data/lib/routes/jira.rb +3 -3
  33. data/lib/routes/production_logs.rb +12 -12
  34. data/lib/routes/reset.rb +1 -1
  35. data/lib/routes/review.rb +6 -5
  36. data/lib/routes/scripts_api_docs.rb +5 -5
  37. data/lib/routes/scripts_branch_cleaner.rb +58 -79
  38. data/lib/routes/scripts_color.rb +1 -1
  39. data/lib/routes/scripts_pom_fixer.rb +5 -62
  40. data/lib/routes/scripts_sonar.rb +82 -0
  41. data/lib/routes/setup.rb +6 -6
  42. data/lib/routes/tail.rb +5 -5
  43. data/lib/routes/test.rb +3 -3
  44. data/lib/routes/update.rb +1 -1
  45. metadata +16 -9
  46. data/lib/routes/scripts_code_sniffer.rb +0 -36
data/lib/core/mysql.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  require 'mysql'
2
2
 
3
- module Brightpearl
3
+ module App
4
4
 
5
5
  class MySQL
6
6
 
7
7
  DEFAULT_VM_SCHEMA = 'app'
8
8
  DEFAULT_EC2_SCHEMA = 'brightpearl'
9
9
 
10
- @vm_connection = nil
10
+ @vm_connection = {}
11
11
  @ec2_connection = nil
12
12
 
13
13
  @ids_customers = []
@@ -15,15 +15,15 @@ module Brightpearl
15
15
 
16
16
  def self.vm(schema = DEFAULT_VM_SCHEMA)
17
17
 
18
- if @vm_connection.nil?
19
- @vm_connection = Mysql.new(
20
- Brightpearl::Config.param(Brightpearl::Config::VM_IP),
21
- Brightpearl::Config.param(Brightpearl::Config::VM_MYSQL_USER),
22
- Brightpearl::Config.param(Brightpearl::Config::VM_MYSQL_PASSWORD),
18
+ if @vm_connection[schema].nil?
19
+ @vm_connection[schema] = Mysql.new(
20
+ App::Config.param(App::Config::VM_IP),
21
+ App::Config.param(App::Config::VM_MYSQL_USER),
22
+ App::Config.param(App::Config::VM_MYSQL_PASSWORD),
23
23
  schema
24
24
  )
25
25
  end
26
- @vm_connection
26
+ @vm_connection[schema]
27
27
 
28
28
  end
29
29
 
@@ -32,11 +32,11 @@ module Brightpearl
32
32
  if @ec2_connection.nil?
33
33
 
34
34
  encrypter = Encrypter.new
35
- host = Brightpearl::Config.param(Brightpearl::Config::EC2_HOST)
36
- user = Brightpearl::Config.param(Brightpearl::Config::EC2_USER)
37
- pass = Brightpearl::Config.param(Brightpearl::Config::EC2_PASS)
35
+ host = App::Config.param(App::Config::EC2_HOST)
36
+ user = App::Config.param(App::Config::EC2_USER)
37
+ pass = App::Config.param(App::Config::EC2_PASS)
38
38
  if host.nil? || user.nil? || pass.nil? || host == '' || user == '' || pass == ''
39
- Brightpearl::Terminal::error('EC2 access data not found', ["The command you're trying to run requires access to an EC2 database.", "In order for this to work you will need valid #{Brightpearl::Terminal::format_highlight('access data')}.", "Please speak to #{Brightpearl::Terminal::format_highlight('Albert')} (or team Raptor) for more info."], true)
39
+ App::Terminal::error('EC2 access data not found', ["The command you're trying to run requires access to an EC2 database.", "In order for this to work you will need valid #{App::Terminal::format_highlight('access data')}.", "Please speak to #{App::Terminal::format_highlight('Albert')} (or team Raptor) for more info."], true)
40
40
  end
41
41
  @ec2_connection = Mysql.new(
42
42
  encrypter.decrypt(host),
@@ -51,7 +51,7 @@ module Brightpearl
51
51
 
52
52
  def self.get_random_customer_id
53
53
  unless @ids_customers.any?
54
- customers = Brightpearl::MySQL::vm.query('SELECT customers_id FROM customers ORDER BY customers_id DESC LIMIT 100')
54
+ customers = App::MySQL::vm.query('SELECT customers_id FROM customers ORDER BY customers_id DESC LIMIT 100')
55
55
  customers.each_hash do |row|
56
56
  @ids_customers << row['customers_id']
57
57
  end
@@ -61,7 +61,7 @@ module Brightpearl
61
61
 
62
62
  def self.get_random_shipping_id
63
63
  unless @ids_shipping.any?
64
- ship_methods = Brightpearl::MySQL::vm.query('SELECT ship_method_id FROM ship_methods ORDER BY ship_method_id DESC LIMIT 100')
64
+ ship_methods = App::MySQL::vm.query('SELECT ship_method_id FROM ship_methods ORDER BY ship_method_id DESC LIMIT 100')
65
65
  ship_methods.each_hash do |row|
66
66
  @ids_shipping << row['ship_method_id']
67
67
  end
data/lib/core/pom.rb ADDED
@@ -0,0 +1,129 @@
1
+ module App
2
+
3
+ class Pom
4
+
5
+ # Initialise credentials
6
+ # @return void
7
+ def initialize
8
+ end
9
+
10
+ # Retrieves list of pom.xml files which need to be un-snapshotted
11
+ # @return Array
12
+ def self.get_files_to_change
13
+
14
+ command = "find #{ App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)} -name 'pom.xml'"
15
+ files = App::Terminal::command_capture(command)
16
+ files = files[0].split("\n")
17
+
18
+ unless files.any?
19
+ App::Terminal::error('No files found', ["The command: #{App::Terminal::format_command(command)} didn't return any files.", 'It might be possible that the directory structure of our codebase has changed and this script needs to be updated.', nil, "Speak to #{App::Terminal::format_highlight('Albert')}."], true)
20
+ end
21
+
22
+ blank_line_inserted = false
23
+
24
+ files_to_change = []
25
+ files.each do |filename|
26
+ file_lines = File.open(filename, 'rb').read
27
+ file_lines.split("\n").each do |line|
28
+ if line.match(/<version>\d+\.\d+\.\d+-(.*)-(snapshot)<\/version>/i)
29
+
30
+ unless blank_line_inserted
31
+ puts
32
+ blank_line_inserted = true
33
+ end
34
+
35
+ puts " \x1B[38;5;240mMatched line:\x1B[0m \x1B[38;5;11m#{line.strip}\x1B[0m"
36
+ files_to_change << filename
37
+
38
+ end
39
+ end
40
+ end
41
+
42
+ files_to_change
43
+
44
+ end
45
+
46
+ def self.unsnapshot_files(files_to_change, current_branch_code_repo, add_branch_tag = true)
47
+
48
+ unless files_to_change.any?
49
+ App::Terminal::info('No feature-tagged POMs found', 'Nothing to un-snapshot.')
50
+ return
51
+ end
52
+
53
+ unless App::Terminal::prompt_yes_no('Un-snapshot POMs', generate_confirmation_text(files_to_change))
54
+ App::Terminal::abort(nil, nil, true, false)
55
+ end
56
+
57
+ files_to_change.each do |filename|
58
+ App::Terminal::output("Un-snapshotting: #{App::Terminal::format_directory(filename)}")
59
+ if current_branch_code_repo == App::Git::MASTER || add_branch_tag == false
60
+ new_snapshot_tag = '-SNAPSHOT'
61
+ else
62
+ new_snapshot_tag = "-#{current_branch_code_repo}-SNAPSHOT"
63
+ end
64
+ contents = File.read(filename)
65
+ contents_new = contents.gsub(/-(.*)-SNAPSHOT/, new_snapshot_tag)
66
+ File.open(filename, 'w') { |file| file.puts contents_new }
67
+ end
68
+
69
+ diff_result = App::Terminal::command_capture('git diff | grep "+ \|- "', App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
70
+ puts
71
+ diff_result[0].split("\n").each do |line|
72
+ if line[0] == '+'
73
+ puts " \x1B[38;5;46m#{line.gsub(' ', '')}\x1B[0m"
74
+ else
75
+ puts " \x1B[38;5;196m#{line.gsub(' ', '')}\x1B[0m"
76
+ end
77
+ end
78
+ puts
79
+
80
+ App::Terminal::command(['git add .', 'git status'], App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
81
+
82
+ # Figure out the commit message.
83
+ git = App::Git.new
84
+ current_branch_name = git.current_branch_for_repo(App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
85
+ if current_branch_name =~ /\A(bp|bug)-\d{4,5}\z/i
86
+ jira_number = current_branch_name.gsub(/\D/, '')
87
+ else
88
+ jira_number = '0000'
89
+ end
90
+ commit_message = "BP-#{jira_number} Updated POM tags on #{current_branch_code_repo}."
91
+
92
+ unless current_branch_code_repo == App::Git::MASTER
93
+
94
+ if App::Terminal::prompt_yes_no('Commit to GIT', ["This will commit your changes to GIT with message: #{App::Terminal::format_highlight(commit_message)}"])
95
+ App::Terminal::command(["git commit -m '#{commit_message.gsub("'", "\\'")}'"], App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
96
+ else
97
+ 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)
98
+ return
99
+ end
100
+
101
+ if App::Terminal::prompt_yes_no('Push changes to origin')
102
+ App::Terminal::command('git push', App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE))
103
+ 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.")
104
+ else
105
+ 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)
106
+ end
107
+ else
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)
109
+ end
110
+
111
+ end
112
+
113
+ private
114
+
115
+ def self.generate_confirmation_text(files_to_change)
116
+
117
+ confirmation_text = ['The following files will have their branch tags removed:', nil]
118
+ files_to_change.each do |file_name|
119
+ unless file_name == ''
120
+ confirmation_text << App::Terminal::format_directory(file_name)
121
+ end
122
+ end
123
+ confirmation_text
124
+
125
+ end
126
+
127
+ end
128
+
129
+ end
data/lib/core/terminal.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'highline/import'
2
2
  require 'columnist'
3
3
 
4
- module Brightpearl
4
+ module App
5
5
 
6
6
  class Terminal
7
7
 
@@ -12,6 +12,8 @@ module Brightpearl
12
12
  MSG_ERROR = 'error'
13
13
  MSG_TODO = 'todo'
14
14
  MSG_AUTOMATIC = 'automatic'
15
+ MSG_GENERATED = 'generated'
16
+ MSG_PROCESSED = 'processed'
15
17
 
16
18
  # Runs a series of commands in the terminal.
17
19
  # @return void
@@ -20,18 +22,18 @@ module Brightpearl
20
22
  commands = [commands]
21
23
  end
22
24
  unless location.nil?
23
- unless File.directory?(location)
25
+ unless File.directory?(File.expand_path(location))
24
26
  error('Directory not found.', "Cannot find the following directory: \x1B[38;5;205m#{location}\x1B[0m", true)
25
27
  end
26
28
  end
27
29
  output = []
28
30
  if verbose_cd && verbose && commands.any? && !location.nil?
29
- puts "\x1B[42m Executing \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m #{Brightpearl::Terminal::format_command("cd #{location}")}"
31
+ puts "\x1B[42m Executing \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m #{App::Terminal::format_command("cd #{location}")}"
30
32
  end
31
33
  if commands.any?
32
34
  commands.each do |command|
33
35
  if verbose
34
- puts "\x1B[42m Executing \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m #{Brightpearl::Terminal::format_command("#{command}")}"
36
+ puts "\x1B[42m Executing \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m #{App::Terminal::format_command("#{command}")}"
35
37
  end
36
38
  if location.nil?
37
39
  if capture_real_output
@@ -74,6 +76,10 @@ module Brightpearl
74
76
  puts "\x1B[48;5;199m @TODO \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m \x1B[0m#{message}\x1B[0m"
75
77
  when MSG_AUTOMATIC
76
78
  puts "\x1B[48;5;96m Automatic \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m \x1B[0m#{message}\x1B[0m"
79
+ when MSG_GENERATED
80
+ puts "\x1B[48;5;96m Generated \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m \x1B[0m#{message}\x1B[0m"
81
+ when MSG_PROCESSED
82
+ puts "\x1B[48;5;238m Processed \x1B[0m \x1B[0m\xe2\x86\x92\x1B[0m \x1B[0m#{message}\x1B[0m"
77
83
  else
78
84
  puts "'#{type}' is not a valid Terminal::output() type."
79
85
  exit
@@ -89,7 +95,7 @@ module Brightpearl
89
95
  if message.nil?
90
96
  message = "You have chosen to \x1B[38;5;9mABORT\x1B[38;5;240m the script."
91
97
  end
92
- Brightpearl::Terminal::error(title, message, exit_script, preceding_blank_line, 'ABORT')
98
+ App::Terminal::error(title, message, exit_script, preceding_blank_line, 'ABORT')
93
99
  end
94
100
 
95
101
  # Displays error and exits script by default.
@@ -174,7 +180,21 @@ module Brightpearl
174
180
  # Returns flag name in consistent, uniform manner.
175
181
  # @return String
176
182
  def self.format_flag(flag_letter, display_flag_text = true)
177
- "\x1B[38;5;152m-#{flag_letter}#{display_flag_text ? ' flag' : ''}\x1B[0m"
183
+ letter_array = []
184
+ if flag_letter.is_a? String
185
+ letter_array = Array[flag_letter]
186
+ elsif flag_letter.is_a? Array
187
+ letter_array = flag_letter
188
+ else
189
+ App::Terminal::error('Terminal::format_flag expects either String or Array.', nil, true)
190
+ end
191
+ flag_txt = ''
192
+ letter_array.each do |letter|
193
+ flag_txt = "#{flag_txt}, -#{letter}"
194
+ end
195
+ xtra_txt = letter_array.length > 1 ? ' flags' : ' flag'
196
+ flag_txt = flag_txt[2..-1]
197
+ "\x1B[38;5;152m#{flag_txt}#{display_flag_text ? xtra_txt : ''}\x1B[0m"
178
198
  end
179
199
 
180
200
  # Returns action text in consistent, uniform manner.
@@ -229,9 +249,9 @@ module Brightpearl
229
249
  puts "\n"
230
250
  return false
231
251
  when 'a'
232
- Brightpearl::Terminal::error('Abandon ship!', ["You have chosen to \x1B[38;5;9mABORT\x1B[38;5;240m the script.", nil, 'Please note that whenever you do this, any scripted tasks which were running', 'will have been interrupted mid-script. This may (or may not) cause problems.'], true)
252
+ App::Terminal::error('Abandon ship!', ["You have chosen to \x1B[38;5;9mABORT\x1B[38;5;240m the script.", nil, 'Please note that whenever you do this, any scripted tasks which were running', 'will have been interrupted mid-script. This may (or may not) cause problems.'], true)
233
253
  when 'x'
234
- Brightpearl::Terminal::error('Abandon ship!', ["You have chosen to \x1B[38;5;9mABORT\x1B[38;5;240m the script.", nil, 'Please note that whenever you do this, any scripted tasks which were running', 'will have been interrupted mid-script. This may (or may not) cause problems.'], true)
254
+ App::Terminal::error('Abandon ship!', ["You have chosen to \x1B[38;5;9mABORT\x1B[38;5;240m the script.", nil, 'Please note that whenever you do this, any scripted tasks which were running', 'will have been interrupted mid-script. This may (or may not) cause problems.'], true)
235
255
  else
236
256
  end
237
257
  end
data/lib/core/tools.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'open-uri'
2
2
 
3
- module Brightpearl
3
+ module App
4
4
 
5
5
  class Tools
6
6
 
@@ -10,20 +10,20 @@ module Brightpearl
10
10
  # @return void
11
11
  def self.verify_internet_access
12
12
  if ping('www.google.com') != 0
13
- Brightpearl::Terminal::error('You are not connected to the internet', 'Please check your connection and try and again.')
13
+ App::Terminal::error('You are not connected to the internet', 'Please check your connection and try and again.')
14
14
  end
15
15
  end
16
16
 
17
17
  def self.verify_vm_is_reachable
18
- if ping(Brightpearl::Config.param(Brightpearl::Config::VM_IP)) != 0
19
- Brightpearl::Terminal::error('Cannot reach VM', ["The remote host #{Brightpearl::Terminal::format_highlight(Brightpearl::Config.param(Brightpearl::Config::VM_IP))} cannot be reached.", 'Please make sure your VM is online and correctly configured.'])
18
+ if ping(App::Config.param(App::Config::VM_IP)) != 0
19
+ App::Terminal::error('Cannot reach VM', ["The remote host #{App::Terminal::format_highlight(App::Config.param(App::Config::VM_IP))} cannot be reached.", 'Please make sure your VM is online and correctly configured.'])
20
20
  end
21
21
  end
22
22
 
23
23
  # Ping a URL or IP and returns the exit status. 0 = success, anything else means it failed.
24
24
  # @return Integer
25
25
  def self.ping(ip_or_url, verbose = true)
26
- Brightpearl::Terminal::output("Checking that #{Brightpearl::Terminal::format_highlight(ip_or_url)} is reachable") if verbose == true
26
+ App::Terminal::output("Checking that #{App::Terminal::format_highlight(ip_or_url)} is reachable") if verbose == true
27
27
  `ping -t 1 -c 1 #{ip_or_url}`
28
28
  $?.exitstatus
29
29
  end
@@ -80,7 +80,7 @@ module Brightpearl
80
80
  # Returns TRUE if Mac, FALSE if Linux (or anything else for that matter)
81
81
  # @return boolean
82
82
  def self.this_is_a_mac
83
- return Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_OS) == Brightpearl::Config::MAC
83
+ return App::Config.param(App::Config::WORKSTATION_OS) == App::Config::MAC
84
84
  end
85
85
 
86
86
  private
@@ -0,0 +1,92 @@
1
+ require 'fileutils'
2
+ require 'parseconfig'
3
+
4
+ module App
5
+
6
+ class UtilsFiles
7
+
8
+ def self.write_file(full_path_and_file, array_of_lines)
9
+
10
+ unless array_of_lines.is_a? Array
11
+ raise RuntimeError, "Expected an array of lines to write to file, instead got: #{array_of_lines.class}"
12
+ end
13
+
14
+ unless path_exists(File.dirname(full_path_and_file))
15
+ FileUtils::mkdir_p(File.dirname(full_path_and_file))
16
+ end
17
+
18
+ if file_exists(full_path_and_file)
19
+ File.delete(full_path_and_file)
20
+ end
21
+
22
+ begin
23
+
24
+ File.open(full_path_and_file, 'w') { |file|
25
+
26
+ array_of_lines.each_with_index do |line, index|
27
+ if index == array_of_lines.size - 1
28
+ file.write("#{line}")
29
+ else
30
+ file.write("#{line}\n")
31
+ end
32
+ end
33
+
34
+ file.close
35
+ }
36
+
37
+ add_file_to_git(full_path_and_file)
38
+
39
+ rescue Exception => e
40
+
41
+ App::Terminal::error('Something went wrong', "#{e.message}", true)
42
+
43
+ end
44
+
45
+ end
46
+
47
+ def self.read_file(full_path_and_file)
48
+
49
+ unless file_exists(full_path_and_file)
50
+ App::Terminal::error("The file doesn't exist: #{full_path_and_file}", nil, true)
51
+ end
52
+
53
+ file_content = []
54
+ file = File.open(full_path_and_file).read
55
+ file.gsub!(/\r\n?/, "\n")
56
+ file.each_line do |line|
57
+ file_content << line
58
+ end
59
+ file_content
60
+
61
+ end
62
+
63
+ def self.path_exists(full_path)
64
+ File.directory?(File.expand_path(full_path))
65
+ end
66
+
67
+ def self.file_exists(full_path_and_file)
68
+ File.exist?(full_path_and_file)
69
+ end
70
+
71
+ def self.get_full_path(path)
72
+ "/#{App::UtilsStrings.remove_surrounding_slashes(File.expand_path(path))}"
73
+ end
74
+
75
+ def self.get_files_in_dir(path, only_with_extension = nil)
76
+ path = "/#{App::UtilsStrings.remove_surrounding_slashes(File.expand_path(path))}"
77
+ unless path_exists(path)
78
+ raise RuntimeError, "Directory doesn't exist: #{path}"
79
+ end
80
+ files = Dir.glob("#{path}/**/*.#{only_with_extension.nil? ? '*' : only_with_extension}")
81
+ files
82
+ end
83
+
84
+ def self.add_file_to_git(full_path_and_file)
85
+
86
+ App::Terminal::error('Must program add_file_to_git', "#{full_path_and_file}", true)
87
+
88
+ end
89
+
90
+ end
91
+
92
+ end
@@ -0,0 +1,25 @@
1
+ module App
2
+
3
+ class UtilsRoutes
4
+
5
+ # Returns number of flags set for route (from @opts variable)
6
+ # @param Array (@opts)
7
+ # @return int
8
+ def self.flags_set(opts)
9
+ flags_set = 0
10
+ opts.each do |key, value|
11
+ # Only here to prevent code-inspector from complaining.
12
+ key.strip! if key.nil?
13
+ if value
14
+ flags_set = flags_set + 1
15
+ end
16
+ end
17
+ if flags_set > 0
18
+ flags_set = flags_set / 2
19
+ end
20
+ flags_set
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,45 @@
1
+ module App
2
+
3
+ class UtilsStrings
4
+
5
+ # Convert 'snake_case' or 'SnAKE_cAse' to 'SnakeCase'.
6
+ # @param String
7
+ # @return String
8
+ def self.snake_case_to_camel_case(string)
9
+ validate_string(string)
10
+ string.downcase!
11
+ return string if string !~ /_/ && string =~ /[A-Z]+.*/
12
+ string.split('_').map { |e| e.capitalize }.join
13
+ end
14
+
15
+ # Convert 'snake_case' or 'SnAKE_cAse' to 'snakeCase'.
16
+ # @param String
17
+ # @return String
18
+ def self.snake_case_to_camel_case_lower(string)
19
+ string = snake_case_to_camel_case(string)
20
+ "#{string[0, 1].downcase}#{string[1..-1]}"
21
+ end
22
+
23
+ # Remove preceding/trailing slashes from a string (and trim preceding/trailing whitespace).
24
+ # @param String - The string to be trimmed (and returned).
25
+ # @return String
26
+ def self.remove_surrounding_slashes(string)
27
+ string.strip!
28
+ validate_string(string)
29
+ string.gsub!(/\A\/+/, '')
30
+ string.gsub!(/\/+\z/, '')
31
+ string
32
+ end
33
+
34
+ private
35
+
36
+ def self.validate_string(string)
37
+ if string.nil? || !string.is_a?(String)
38
+ raise RuntimeError, "Expected String, got: #{string.class}"
39
+ end
40
+ end
41
+
42
+
43
+ end
44
+
45
+ end
data/lib/core/validate.rb CHANGED
@@ -1,4 +1,4 @@
1
- module Brightpearl
1
+ module App
2
2
 
3
3
  class Validate
4
4
 
data/lib/routes/build.rb CHANGED
@@ -1,4 +1,4 @@
1
- module BrightpearlCommand
1
+ module AppCommand
2
2
 
3
3
  class Build < ::Convoy::ActionCommand::Base
4
4
 
@@ -16,7 +16,7 @@ module BrightpearlCommand
16
16
  def opts_validate
17
17
 
18
18
  if @args[0].nil?
19
- Brightpearl::Terminal::error('Must specify service name', "The script cannot build your service because you haven't told it what service to build.", true)
19
+ App::Terminal::error('Must specify service name', "The script cannot build your service because you haven't told it what service to build.", true)
20
20
  end
21
21
 
22
22
  # Set 'service only' to default.
@@ -32,7 +32,7 @@ module BrightpearlCommand
32
32
  suffix = ''
33
33
  end
34
34
 
35
- service_dir = Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE)
35
+ service_dir = App::Config.param(App::Config::WORKSTATION_PATH_TO_BP_CODE)
36
36
  dir_dev_support = "#{service_dir}/services/dev-support/#{@args[0]}#{suffix}"
37
37
  dir_functional = "#{service_dir}/services/functional/#{@args[0]}#{suffix}"
38
38
  dir_infrastructure = "#{service_dir}/services/infrastructure/#{@args[0]}#{suffix}"
@@ -56,7 +56,7 @@ module BrightpearlCommand
56
56
  @is_lib = true
57
57
  end
58
58
  if @service_dir.nil?
59
- Brightpearl::Terminal::error('Cannot find service', "The script is unable to find a service called: \x1B[38;5;202m#{@args[0].downcase}\x1B[0m\nPlease check your spelling and try again.")
59
+ App::Terminal::error('Cannot find service', "The script is unable to find a service called: \x1B[38;5;202m#{@args[0].downcase}\x1B[0m\nPlease check your spelling and try again.")
60
60
  end
61
61
 
62
62
  end
@@ -69,9 +69,9 @@ module BrightpearlCommand
69
69
 
70
70
  def build_service
71
71
 
72
- Brightpearl::Tools::verify_vm_is_reachable if @is_lib == false
72
+ App::Tools::verify_vm_is_reachable if @is_lib == false
73
73
 
74
- if Brightpearl::Tools::this_is_a_mac
74
+ if App::Tools::this_is_a_mac
75
75
 
76
76
  args = @args.dup
77
77
  args.shift
@@ -81,7 +81,7 @@ module BrightpearlCommand
81
81
  ]
82
82
  if @is_lib == false
83
83
 
84
- output = Brightpearl::Terminal::command_capture(commands, @service_dir)
84
+ output = App::Terminal::command_capture(commands, @service_dir)
85
85
 
86
86
  lines = output[0].chomp
87
87
  lines = lines.split("\n")
@@ -106,37 +106,36 @@ module BrightpearlCommand
106
106
  end
107
107
 
108
108
  if build_failed
109
- Brightpearl::Terminal::error('Build failed', nil, false)
109
+ App::Terminal::error('Build failed', nil, false)
110
110
  puts output[0]
111
111
  puts
112
-
113
112
  # If a build fail URL was found, launch it in default browser.
114
113
  unless build_fail_url.nil?
115
- if Brightpearl::Terminal::prompt_yes_no("Would you like to #{Brightpearl::Terminal::format_action('open a stack-trace')} in your default browser?", build_fail_url)
114
+ if App::Terminal::prompt_yes_no("Would you like to #{App::Terminal::format_action('open a stack-trace')} in your default browser?", build_fail_url)
116
115
  system("open -a Google\\ Chrome #{build_fail_url}")
117
116
  end
118
117
  end
119
-
120
118
  exit
121
119
  end
122
120
 
121
+ puts output
122
+
123
123
  war_file_ws = war_file_ws.split('war: ')
124
124
  war_file_ws = war_file_ws[1].chomp
125
125
 
126
126
  war_file_vm = war_file_ws.split('/')
127
127
  war_file_vm = war_file_vm[war_file_vm.length - 1]
128
128
 
129
-
130
129
  commands = [
131
- "scp #{war_file_ws} #{Brightpearl::Config.param(Brightpearl::Config::VM_USER)}@#{Brightpearl::Config.param(Brightpearl::Config::VM_IP)}:/tmp",
132
- "sshpass -p#{Brightpearl::Config.param(Brightpearl::Config::VM_USER_PASSWORD)} ssh #{Brightpearl::Config.param(Brightpearl::Config::VM_USER)}@#{Brightpearl::Config.param(Brightpearl::Config::VM_IP)} 'cd /brightpearl-source/dev-vm-control-scripts/scm && ~/generated-scripts/deploy-uploaded-service #{war_file_vm}'"
130
+ "scp #{war_file_ws} #{App::Config.param(App::Config::VM_USER)}@#{App::Config.param(App::Config::VM_IP)}:/tmp",
131
+ "sshpass -p#{App::Config.param(App::Config::VM_USER_PASSWORD)} ssh #{App::Config.param(App::Config::VM_USER)}@#{App::Config.param(App::Config::VM_IP)} 'cd /brightpearl-source/dev-vm-control-scripts/scm && ~/generated-scripts/deploy-uploaded-service #{war_file_vm}'"
133
132
 
134
133
  ]
135
- Brightpearl::Terminal::command(commands)
134
+ App::Terminal::command(commands)
136
135
 
137
136
  else
138
137
 
139
- Brightpearl::Terminal::command(commands, @service_dir)
138
+ App::Terminal::command(commands, @service_dir)
140
139
 
141
140
  end
142
141
 
@@ -145,7 +144,7 @@ module BrightpearlCommand
145
144
  commands = [
146
145
  'mvn clean install -P deploy-service',
147
146
  ]
148
- Brightpearl::Terminal::command(commands, @service_dir)
147
+ App::Terminal::command(commands, @service_dir)
149
148
 
150
149
  end
151
150
 
@@ -2,7 +2,7 @@ require 'rest_client'
2
2
  require 'mysql'
3
3
  require 'json'
4
4
 
5
- module BrightpearlCommand
5
+ module AppCommand
6
6
 
7
7
  class DummyOrder < ::Convoy::ActionCommand::Base
8
8
 
@@ -14,7 +14,7 @@ module BrightpearlCommand
14
14
  def execute
15
15
 
16
16
  @opts = command_options
17
- # @database = Brightpearl::MySQL::get_database_connection
17
+ # @database = App::MySQL::get_database_connection
18
18
  opts_validate
19
19
  opts_routing
20
20
 
@@ -86,14 +86,14 @@ module BrightpearlCommand
86
86
  },
87
87
  'delivery' => {
88
88
  'deliveryDate' => '2014-10-19T11:12:24.000+01:00',
89
- 'shippingMethodId' => Brightpearl::MySQL::get_random_shipping_id
89
+ 'shippingMethodId' => App::MySQL::get_random_shipping_id
90
90
  },
91
91
  'currency' => {
92
92
  'orderCurrencyCode' => 'GBP'
93
93
  },
94
94
  'parties' => {
95
95
  'customer' => {
96
- 'contactId' => Brightpearl::MySQL::get_random_customer_id
96
+ 'contactId' => App::MySQL::get_random_customer_id
97
97
  }
98
98
  },
99
99
  'assignment' => {
@@ -112,7 +112,7 @@ module BrightpearlCommand
112
112
 
113
113
  begin
114
114
  response = RestClient.post(
115
- "http://#{Brightpearl::Config.param(Brightpearl::Config::VM_IP)}:#{Brightpearl::Enum::PORT_ORDER_SERVICE}/order-service/app/order",
115
+ "http://#{App::Config.param(App::Config::VM_IP)}:#{App::Enum::PORT_ORDER_SERVICE}/order-service/app/order",
116
116
  post_data,
117
117
  :content_type => :json, :accept => :json, :'account-version' => 'admindev', :'effective-user-id' => 6
118
118
  )