geordi 3.1.0 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +66 -11
  5. data/Gemfile.lock +1 -1
  6. data/README.md +127 -132
  7. data/Rakefile +18 -8
  8. data/exe/dumple +10 -0
  9. data/geordi.gemspec +1 -0
  10. data/lib/geordi/COMMAND_TEMPLATE +4 -2
  11. data/lib/geordi/cli.rb +1 -1
  12. data/lib/geordi/commands/bundle_install.rb +1 -1
  13. data/lib/geordi/commands/capistrano.rb +1 -1
  14. data/lib/geordi/commands/chromedriver_update.rb +2 -2
  15. data/lib/geordi/commands/commit.rb +1 -6
  16. data/lib/geordi/commands/console.rb +12 -6
  17. data/lib/geordi/commands/create_databases.rb +7 -5
  18. data/lib/geordi/commands/cucumber.rb +17 -12
  19. data/lib/geordi/commands/delete_dumps.rb +0 -1
  20. data/lib/geordi/commands/deploy.rb +17 -17
  21. data/lib/geordi/commands/drop_databases.rb +0 -6
  22. data/lib/geordi/commands/dump.rb +10 -19
  23. data/lib/geordi/commands/firefox.rb +3 -6
  24. data/lib/geordi/commands/migrate.rb +4 -4
  25. data/lib/geordi/commands/rake.rb +7 -3
  26. data/lib/geordi/commands/rspec.rb +8 -12
  27. data/lib/geordi/commands/security_update.rb +24 -25
  28. data/lib/geordi/commands/server.rb +4 -4
  29. data/lib/geordi/commands/setup.rb +7 -16
  30. data/lib/geordi/commands/shell.rb +7 -4
  31. data/lib/geordi/commands/tests.rb +4 -4
  32. data/lib/geordi/commands/unit.rb +3 -3
  33. data/lib/geordi/commands/update.rb +4 -15
  34. data/lib/geordi/commands/vnc.rb +2 -4
  35. data/lib/geordi/commands/with_rake.rb +3 -3
  36. data/lib/geordi/commands/yarn_install.rb +1 -1
  37. data/lib/geordi/cucumber.rb +7 -5
  38. data/lib/geordi/dump_loader.rb +1 -1
  39. data/lib/geordi/gitpt.rb +10 -52
  40. data/lib/geordi/interaction.rb +1 -1
  41. data/lib/geordi/remote.rb +16 -4
  42. data/lib/geordi/settings.rb +155 -0
  43. data/lib/geordi/util.rb +36 -18
  44. data/lib/geordi/version.rb +1 -1
  45. metadata +7 -33
  46. data/exe/cap-all +0 -4
  47. data/exe/console-for +0 -4
  48. data/exe/cuc +0 -4
  49. data/exe/cuc-show +0 -4
  50. data/exe/cuc-vnc-setup +0 -4
  51. data/exe/deploy-to-production +0 -4
  52. data/exe/dump-for +0 -8
  53. data/exe/gitpt +0 -4
  54. data/exe/load-dump +0 -4
  55. data/exe/migrate-all +0 -4
  56. data/exe/rs +0 -4
  57. data/exe/run_tests +0 -4
  58. data/exe/shell-for +0 -4
  59. data/exe/tests +0 -4
  60. data/lib/geordi/commands/eurest.rb +0 -4
@@ -24,7 +24,7 @@ module Geordi
24
24
  end
25
25
 
26
26
  # Like `note`, but pink. Use to print (bash) commands.
27
- # Also see Util.system!
27
+ # Also see Util.run!
28
28
  def note_cmd(text)
29
29
  message = "> #{text}"
30
30
  puts "\e[35m#{message}\e[0m" # pink
@@ -34,7 +34,6 @@ module Geordi
34
34
  # Generate dump on the server
35
35
  shell options.merge({
36
36
  remote_command: "dumple #{@config.env} --for_download",
37
- select_server: nil, # Dump must be generated on the primary server
38
37
  })
39
38
 
40
39
  destination_directory = File.join(@config.root, 'tmp')
@@ -44,7 +43,7 @@ module Geordi
44
43
 
45
44
  Interaction.note "Downloading remote dump to #{relative_destination} ..."
46
45
  server = @config.primary_server
47
- Util.system! "scp -C #{@config.user(server)}@#{server}:#{REMOTE_DUMP_PATH} #{destination_path}"
46
+ Util.run!("scp -C #{@config.user(server)}@#{server}:#{REMOTE_DUMP_PATH} #{destination_path}")
48
47
 
49
48
  Interaction.success "Dumped the #{@stage} database to #{relative_destination}."
50
49
 
@@ -56,13 +55,26 @@ module Geordi
56
55
  end
57
56
 
58
57
  def shell(options = {})
59
- server = options[:select_server] ? select_server : @config.primary_server
58
+ server_option = options[:select_server]
59
+ server_number = server_option.to_i
60
+
61
+ server = if server_option == 'select_server'
62
+ select_server
63
+ elsif server_number != 0 && server_number <= @config.servers.count
64
+ server_index = server_number - 1
65
+ @config.servers[server_index]
66
+ elsif server_option.nil?
67
+ @config.primary_server
68
+ else
69
+ Interaction.warn "Invalid server number: #{server_option}"
70
+ select_server
71
+ end
60
72
 
61
73
  remote_command = "cd #{@config.remote_root} && #{@config.shell}"
62
74
  remote_command << " -c '#{options[:remote_command]}'" if options[:remote_command]
63
75
 
64
76
  Interaction.note 'Connecting to ' + server.to_s
65
- Util.system! 'ssh', "#{@config.user(server)}@#{server}", '-t', remote_command
77
+ Util.run!(['ssh', "#{@config.user(server)}@#{server}", '-t', remote_command])
66
78
  end
67
79
 
68
80
  end
@@ -0,0 +1,155 @@
1
+ require 'yaml'
2
+
3
+ require File.expand_path('util', __dir__)
4
+ require File.expand_path('interaction', __dir__)
5
+
6
+ module Geordi
7
+ class Settings
8
+ GLOBAL_SETTINGS_FILE_NAME = Util.testing? ? './tmp/global_settings.yml'.freeze : File.join(ENV['HOME'], '.config/geordi/global.yml').freeze
9
+ LOCAL_SETTINGS_FILE_NAME = Util.testing? ? './tmp/local_settings.yml'.freeze : './.geordi.yml'.freeze
10
+
11
+ ALLOWED_GLOBAL_SETTINGS = %w[ pivotal_tracker_api_key ].freeze
12
+ ALLOWED_LOCAL_SETTINGS = %w[ use_vnc pivotal_tracker_project_ids ].freeze
13
+
14
+ def initialize
15
+ read_settings
16
+ end
17
+
18
+ # Global settings
19
+ def pivotal_tracker_api_key
20
+ @global_settings['pivotal_tracker_api_key'] || gitpt_api_key_old || inquire_pt_api_key
21
+ end
22
+
23
+ def pivotal_tracker_api_key=(value)
24
+ @global_settings['pivotal_tracker_api_key'] = value
25
+ save_global_settings
26
+ end
27
+
28
+ # Local settings
29
+ # They should not be changed by geordi to avoid unexpected diffs, therefore
30
+ # there are no setters for these settings
31
+ def use_vnc?
32
+ @local_settings.fetch('use_vnc', true)
33
+ end
34
+
35
+ def pivotal_tracker_project_ids
36
+ project_ids = @local_settings['pivotal_tracker_project_ids'] || pt_project_ids_old
37
+
38
+ case project_ids
39
+ when Array
40
+ # nothing to do
41
+ when String
42
+ project_ids = project_ids.split(/[\s]+/).map(&:to_i)
43
+ when Integer
44
+ project_ids = [project_ids]
45
+ else
46
+ project_ids = []
47
+ end
48
+
49
+ if project_ids.empty?
50
+ puts
51
+ Geordi::Interaction.warn "Sorry, I could not find a project ID in .geordi.yml :("
52
+ puts
53
+
54
+ puts "Please put at least one Pivotal Tracker project id into the .geordi.yml file in this directory, e.g."
55
+ puts
56
+ puts "pivotal_tracker_project_ids:"
57
+ puts "- 123456"
58
+ puts
59
+ puts 'You may add multiple IDs.'
60
+ exit 1
61
+ end
62
+
63
+ project_ids
64
+ end
65
+
66
+ private
67
+
68
+ def read_settings
69
+ global_path = GLOBAL_SETTINGS_FILE_NAME
70
+ local_path = LOCAL_SETTINGS_FILE_NAME
71
+
72
+ if File.exists?(global_path)
73
+ global_settings = YAML.safe_load(File.read(global_path))
74
+ check_for_invalid_keys(global_settings, ALLOWED_GLOBAL_SETTINGS, global_path)
75
+ end
76
+
77
+ if File.exists?(local_path)
78
+ local_settings = YAML.safe_load(File.read(local_path))
79
+ check_for_invalid_keys(local_settings, ALLOWED_LOCAL_SETTINGS, local_path)
80
+ end
81
+
82
+ @global_settings = global_settings || {}
83
+ @local_settings = local_settings || {}
84
+ end
85
+
86
+ def check_for_invalid_keys(settings, allowed_keys, file)
87
+ invalid_keys = settings.keys - allowed_keys
88
+ unless invalid_keys.empty?
89
+ Geordi::Interaction.warn "Geordi detected unknown keys in #{file}.\n"
90
+
91
+ invalid_keys.sort.each do |key|
92
+ puts "* #{key}"
93
+ end
94
+
95
+ puts "\nAllowed keys are:"
96
+ allowed_keys.sort.each do |key|
97
+ puts "* #{key}"
98
+ end
99
+ puts
100
+
101
+ exit 1
102
+ end
103
+ end
104
+
105
+ def save_global_settings
106
+ global_path = GLOBAL_SETTINGS_FILE_NAME
107
+ global_directory = File.dirname(global_path)
108
+ FileUtils.mkdir_p(global_directory) unless File.directory? global_directory
109
+ File.open(global_path, 'w') do |file|
110
+ file.write @global_settings.to_yaml
111
+ end
112
+ end
113
+
114
+ # deprecated
115
+ def gitpt_api_key_old
116
+ file_path = File.join(ENV['HOME'], '.gitpt')
117
+ if File.exist?(file_path) && !Util.testing?
118
+ token = YAML.load_file(file_path).fetch :token
119
+ self.pivotal_tracker_api_key = token
120
+
121
+ Geordi::Interaction.warn "The ~/.gitpt file is deprecated."
122
+ Geordi::Interaction.note "The contained setting has been moved to ~/.config/geordi/global.yml."
123
+ Geordi::Interaction.note "If you don't need to work with an older version of geordi you can delete ~/.gitpt now."
124
+
125
+ token
126
+ end
127
+ end
128
+
129
+ def inquire_pt_api_key
130
+ Geordi::Interaction.warn 'Your settings are missing or invalid.'
131
+ Geordi::Interaction.warn "Please configure your Pivotal Tracker access."
132
+ token = Geordi::Interaction.prompt 'Your API key:'
133
+ self.pivotal_tracker_api_key = token
134
+ puts
135
+
136
+ token
137
+ end
138
+
139
+ # deprecated
140
+ def pt_project_ids_old
141
+ if File.exist?('.pt_project_id')
142
+ project_ids = File.read('.pt_project_id')
143
+ puts # Make sure to start on a new line (e.g. when invoked after a #print)
144
+ Geordi::Interaction.warn "The usage of the .pt_project_id file is deprecated."
145
+ Geordi::Interaction.note Util.strip_heredoc(<<-INSTRUCTIONS)
146
+ Please remove this file from your project and add or extend the .geordi.yml file with the following content:
147
+ pivotal_tracker_project_ids: #{project_ids}
148
+ INSTRUCTIONS
149
+
150
+ project_ids
151
+ end
152
+ end
153
+
154
+ end
155
+ end
@@ -21,7 +21,7 @@ module Geordi
21
21
  # install missing gem
22
22
  Interaction.warn 'Probably missing gem: ' + gem_name
23
23
  Interaction.prompt('Install it now?', 'y', /y|yes/) || Interaction.fail('Missing Gems.')
24
- system! install_command, show_cmd: true
24
+ Util.run!(install_command, show_cmd: true)
25
25
 
26
26
  # retry
27
27
  Gem.clear_paths
@@ -33,42 +33,60 @@ module Geordi
33
33
  # Run a command with a clean environment.
34
34
  # Print an error message and exit if the command fails.
35
35
  #
36
- # @option show_cmd: Whether to print the command
37
- # @option confirm: Whether to ask for confirmation before running it
38
- # @option fail_message: The text to print on command failure
39
- def system!(*commands)
40
- options = commands.last.is_a?(Hash) ? commands.pop : {}
41
- Interaction.note_cmd commands.join(' ') if options[:show_cmd]
42
-
43
- if options[:confirm]
36
+ # show_cmd: Whether to print the command
37
+ # confirm: Whether to ask for confirmation before running it
38
+ # fail_message: The text to print on command failure
39
+ def run!(command, show_cmd: false, confirm: false, fail_message: 'Something went wrong.')
40
+ # Disable shell features for arrays https://stackoverflow.com/questions/13338147/ruby-system-method-arguments
41
+ # Conversion: ['ls *', 'some arg'] => ['ls', '*', 'some arg']
42
+ # If you need shell features, you need to pass in a String instead of an array.
43
+ if command.is_a?(Array)
44
+ real_command, *arguments = *command
45
+ command = [real_command.split(' '), arguments].flatten
46
+ printable_command = command.join(', ')
47
+ else
48
+ printable_command = command
49
+ end
50
+
51
+ if show_cmd
52
+ Interaction.note_cmd printable_command
53
+ end
54
+
55
+ if confirm
44
56
  Interaction.prompt('Run this now?', 'n', /y|yes/) or Interaction.fail('Cancelled.')
45
57
  end
46
58
 
47
59
  if testing?
48
- puts "Util.system! #{commands.join ', '}"
60
+ puts "Util.run! #{printable_command}"
49
61
  else
50
62
  # Remove Geordi's Bundler environment when running commands.
51
63
  success = if !defined?(Bundler)
52
- system(*commands)
64
+ system(*command)
53
65
  elsif Gem::Version.new(Bundler::VERSION) >= Gem::Version.new('2.1.2')
54
66
  Bundler.with_original_env do
55
- system(*commands)
67
+ system(*command)
56
68
  end
57
69
  else
58
- Bundler.clean_system(*commands)
70
+ Bundler.clean_system(*command)
59
71
  end
60
72
 
61
- success || Interaction.fail(options[:fail_message] || 'Something went wrong.')
73
+ success || Interaction.fail(fail_message)
62
74
  end
63
75
  end
64
76
 
77
+ def binstub_or_fallback(executable)
78
+ binstub_file = "bin/#{executable}"
79
+
80
+ File.exists?(binstub_file) ? binstub_file : "bundle exec #{executable}"
81
+ end
82
+
65
83
  def console_command(environment)
66
84
  if gem_major_version('rails') == 2
67
85
  'script/console ' + environment
68
86
  elsif gem_major_version('rails') == 3
69
- 'bundle exec rails console ' + environment
87
+ "#{binstub_or_fallback('rails')} console #{environment}"
70
88
  else
71
- "bundle exec rails console -e #{environment}"
89
+ "#{binstub_or_fallback('rails')} console -e #{environment}"
72
90
  end
73
91
  end
74
92
 
@@ -76,7 +94,7 @@ module Geordi
76
94
  if gem_major_version('rails') == 2
77
95
  'script/server ""'
78
96
  else
79
- 'bundle exec rails server'
97
+ "#{binstub_or_fallback('rails')} server"
80
98
  end
81
99
  end
82
100
 
@@ -93,7 +111,7 @@ module Geordi
93
111
  ENV['GEORDI_TESTING_STAGED_CHANGES'] == 'true'
94
112
  else
95
113
  statuses = `git status --porcelain`.split("\n")
96
- statuses.any? { |l| l.start_with? /[A-Z]/i }
114
+ statuses.any? { |l| /^[A-Z]/i =~ l }
97
115
  end
98
116
  end
99
117
 
@@ -1,3 +1,3 @@
1
1
  module Geordi
2
- VERSION = '3.1.0'.freeze
2
+ VERSION = '4.1.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geordi
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henning Koch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-03 00:00:00.000000000 Z
11
+ date: 2020-08-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -30,23 +30,9 @@ email:
30
30
  - henning.koch@makandra.de
31
31
  executables:
32
32
  - b
33
- - cap-all
34
- - console-for
35
- - cuc
36
- - cuc-show
37
- - cuc-vnc-setup
38
- - deploy-to-production
39
- - dump-for
40
33
  - dumple
41
34
  - geordi
42
- - gitpt
43
35
  - launchy_browser
44
- - load-dump
45
- - migrate-all
46
- - rs
47
- - run_tests
48
- - shell-for
49
- - tests
50
36
  extensions: []
51
37
  extra_rdoc_files: []
52
38
  files:
@@ -60,23 +46,9 @@ files:
60
46
  - README.md
61
47
  - Rakefile
62
48
  - exe/b
63
- - exe/cap-all
64
- - exe/console-for
65
- - exe/cuc
66
- - exe/cuc-show
67
- - exe/cuc-vnc-setup
68
- - exe/deploy-to-production
69
- - exe/dump-for
70
49
  - exe/dumple
71
50
  - exe/geordi
72
- - exe/gitpt
73
51
  - exe/launchy_browser
74
- - exe/load-dump
75
- - exe/migrate-all
76
- - exe/rs
77
- - exe/run_tests
78
- - exe/shell-for
79
- - exe/tests
80
52
  - geordi.gemspec
81
53
  - lib/geordi.rb
82
54
  - lib/geordi/COMMAND_TEMPLATE
@@ -98,7 +70,6 @@ files:
98
70
  - lib/geordi/commands/deploy.rb
99
71
  - lib/geordi/commands/drop_databases.rb
100
72
  - lib/geordi/commands/dump.rb
101
- - lib/geordi/commands/eurest.rb
102
73
  - lib/geordi/commands/firefox.rb
103
74
  - lib/geordi/commands/migrate.rb
104
75
  - lib/geordi/commands/png_optimize.rb
@@ -123,13 +94,16 @@ files:
123
94
  - lib/geordi/gitpt.rb
124
95
  - lib/geordi/interaction.rb
125
96
  - lib/geordi/remote.rb
97
+ - lib/geordi/settings.rb
126
98
  - lib/geordi/util.rb
127
99
  - lib/geordi/version.rb
128
100
  homepage: http://makandra.com
129
101
  licenses:
130
102
  - MIT
131
103
  metadata: {}
132
- post_install_message: "* Binary `geordi` installed\n"
104
+ post_install_message: |
105
+ * Binary `geordi` installed
106
+ * Geordi 4.0.0 has removed its deprecated executables. If you want to invoke these commands like before, you may create aliases on your machine. For the alias mapping, please refer to https://github.com/makandra/geordi/commit/68fa92acb146ebde3acb92d7b9556bd4eaa2b4ff
133
107
  rdoc_options: []
134
108
  require_paths:
135
109
  - lib
@@ -144,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
118
  - !ruby/object:Gem::Version
145
119
  version: '0'
146
120
  requirements: []
147
- rubygems_version: 3.1.4
121
+ rubygems_version: 3.0.8
148
122
  signing_key:
149
123
  specification_version: 4
150
124
  summary: Collection of command line tools we use in our daily work with Ruby, Rails
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- puts 'DEPRECATED: Use `geordi ca[pistrano]` instead'
4
- exec 'geordi', 'capistrano', *ARGV
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- puts 'DEPRECATED: Use `geordi con[sole]` instead'
4
- exec 'geordi', 'console', *ARGV
data/exe/cuc DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- puts 'DEPRECATED: Use `geordi cu[cumber]` instead'
4
- exec 'geordi', 'cucumber', *ARGV
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- puts 'DEPRECATED: Use `geordi vn[c]` instead'
4
- exec 'geordi', 'vnc'
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- puts 'DEPRECATED: Use `geordi vn[c] --setup` instead'
4
- exec 'geordi', 'vnc', '--setup'
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- puts 'DEPRECATED: Use `geordi dep[loy]` instead'
4
- exec 'geordi', 'deploy'