sct 0.1.17 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/bin/sct +3 -4
  3. data/{.DS_Store → cluster/lib/.DS_Store} +0 -0
  4. data/cluster/lib/cluster.rb +6 -0
  5. data/cluster/lib/cluster/commands_generator.rb +109 -0
  6. data/cluster/lib/cluster/module.rb +7 -0
  7. data/{lib/sct → cluster/lib/cluster/resources}/.DS_Store +0 -0
  8. data/{resources → cluster/lib/cluster/resources}/corefile.yml +0 -0
  9. data/{lib/sct/commands/cluster.rb → cluster/lib/cluster/runner.rb} +160 -145
  10. data/{lib → sct/lib}/.DS_Store +0 -0
  11. data/sct/lib/sct.rb +17 -0
  12. data/sct/lib/sct/.DS_Store +0 -0
  13. data/sct/lib/sct/cli_tools_distributor.rb +50 -0
  14. data/{lib → sct/lib}/sct/command.rb +0 -0
  15. data/{lib → sct/lib}/sct/commands/hostfile.rb +7 -23
  16. data/sct/lib/sct/commands/init.rb +37 -0
  17. data/sct/lib/sct/commands/mysqlproxy.rb +20 -0
  18. data/sct/lib/sct/commands_generator.rb +56 -0
  19. data/sct/lib/sct/tools.rb +12 -0
  20. data/sct/lib/sct/version.rb +3 -0
  21. data/sct_core/lib/.DS_Store +0 -0
  22. data/sct_core/lib/sct_core.rb +14 -0
  23. data/sct_core/lib/sct_core/.DS_Store +0 -0
  24. data/sct_core/lib/sct_core/command_executor.rb +104 -0
  25. data/{lib/sct → sct_core/lib/sct_core}/config.rb +3 -3
  26. data/sct_core/lib/sct_core/core_ext/string.rb +9 -0
  27. data/{lib/sct/setup/helpers.rb → sct_core/lib/sct_core/helper.rb} +2 -2
  28. data/sct_core/lib/sct_core/module.rb +0 -0
  29. data/sct_core/lib/sct_core/sct_pty.rb +53 -0
  30. data/sct_core/lib/sct_core/ui/implementations/shell.rb +129 -0
  31. data/sct_core/lib/sct_core/ui/interface.rb +120 -0
  32. data/sct_core/lib/sct_core/ui/ui.rb +26 -0
  33. data/sct_core/lib/sct_core/update_checker/update_checker.rb +76 -0
  34. data/shell/README.md +0 -0
  35. data/shell/lib/shell.rb +3 -0
  36. data/{lib/sct → shell/lib/shell}/ClassLevelInheritableAttributes.rb +0 -0
  37. data/shell/lib/shell/commands_generator.rb +14 -0
  38. data/{lib/sct → shell/lib/shell}/docker/composer.rb +4 -3
  39. data/{lib/sct → shell/lib/shell}/docker/docker.rb +7 -10
  40. data/{lib/sct → shell/lib/shell}/docker/php.rb +3 -2
  41. data/{lib/sct → shell/lib/shell}/docker/yarn.rb +4 -3
  42. data/shell/lib/shell/module.rb +9 -0
  43. data/shell/lib/shell/runner.rb +34 -0
  44. data/shell/lib/shell/tools.rb +7 -0
  45. metadata +126 -53
  46. data/.gitignore +0 -12
  47. data/.gitlab/merge_request_templates/DefinitionOfDone.md +0 -14
  48. data/.rspec +0 -3
  49. data/.travis.yml +0 -7
  50. data/CODE_OF_CONDUCT.md +0 -74
  51. data/Gemfile +0 -4
  52. data/Gemfile.lock +0 -44
  53. data/LICENSE.txt +0 -21
  54. data/README.md +0 -134
  55. data/Rakefile +0 -6
  56. data/lib/sct.rb +0 -61
  57. data/lib/sct/command_interface.rb +0 -18
  58. data/lib/sct/command_option.rb +0 -14
  59. data/lib/sct/commands/composer.rb +0 -29
  60. data/lib/sct/commands/init.rb +0 -51
  61. data/lib/sct/commands/mysqlproxy.rb +0 -38
  62. data/lib/sct/commands/php.rb +0 -37
  63. data/lib/sct/commands/yarn.rb +0 -26
  64. data/lib/sct/version.rb +0 -3
  65. data/sct.gemspec +0 -40
@@ -0,0 +1,129 @@
1
+ require_relative '../interface'
2
+
3
+ module SctCore
4
+ # Shell is the terminal output of things
5
+ # For documentation for each of the methods open `interface.rb`
6
+ class Shell < Interface
7
+ require 'tty-screen'
8
+
9
+ def log
10
+ $stdout.sync = true
11
+ end
12
+
13
+ def writeToUser(message)
14
+ puts message
15
+ end
16
+
17
+ def error(message)
18
+ writeToUser(message.to_s.red)
19
+ end
20
+
21
+ def important(message)
22
+ writeToUser(message.to_s.yellow)
23
+ end
24
+
25
+ def success(message)
26
+ writeToUser(message.to_s.green)
27
+ end
28
+
29
+ def message(message)
30
+ writeToUser(message.to_s)
31
+ end
32
+
33
+ def deprecated(message)
34
+ writeToUser(message.to_s.deprecated)
35
+ end
36
+
37
+ def command(message)
38
+ writeToUser("$ #{message}".cyan)
39
+ end
40
+
41
+ def command_output(message)
42
+ actual = (message.split("\r").last || "") # as clearing the line will remove the `>` and the time stamp
43
+ actual.split("\n").each do |msg|
44
+ # prefix = msg.include?("▸") ? "" : "▸ "
45
+ prefix = ""
46
+ writeToUser(prefix + "" + msg.magenta)
47
+ end
48
+ end
49
+
50
+ def verbose(message)
51
+ message.to_s if $verbose
52
+ end
53
+
54
+ def header(message)
55
+ format = format_string
56
+ if message.length + 8 < TTY::Screen.width - format.length
57
+ message = "--- #{message} ---"
58
+ i = message.length
59
+ else
60
+ i = TTY::Screen.width - format.length
61
+ end
62
+ success("-" * i)
63
+ success(message)
64
+ success("-" * i)
65
+ end
66
+
67
+ def content_error(content, error_line)
68
+ error_line = error_line.to_i
69
+ return unless error_line > 0
70
+
71
+ contents = content.split(/\r?\n/).map(&:chomp)
72
+
73
+ start_line = error_line - 2 < 1 ? 1 : error_line - 2
74
+ end_line = error_line + 2 < contents.length ? error_line + 2 : contents.length
75
+
76
+ Range.new(start_line, end_line).each do |line|
77
+ str = line == error_line ? " => " : " "
78
+ str << line.to_s.rjust(Math.log10(end_line) + 1)
79
+ str << ":\t#{contents[line - 1]}"
80
+ error(str)
81
+ end
82
+ end
83
+
84
+ #####################################################
85
+ # @!group Errors: Inputs
86
+ #####################################################
87
+
88
+ def interactive?
89
+ interactive = true
90
+ interactive = false if $stdout.isatty == false
91
+ return interactive
92
+ end
93
+
94
+ def input(message)
95
+ verify_interactive!(message)
96
+ ask("#{format_string}#{message.to_s.yellow}").to_s.strip
97
+ end
98
+
99
+ def confirm(message)
100
+ verify_interactive!(message)
101
+ agree("#{format_string}#{message.to_s.yellow} (y/n)", true)
102
+ end
103
+
104
+ def select(message, options)
105
+ verify_interactive!(message)
106
+
107
+ important(message)
108
+ choose(*options)
109
+ end
110
+
111
+ def password(message)
112
+ verify_interactive!(message)
113
+
114
+ ask("#{format_string}#{message.to_s.yellow}") { |q| q.echo = "*" }
115
+ end
116
+
117
+ def user_error!(error_message, options = {})
118
+ writeToUser(error_message.yellow)
119
+ end
120
+
121
+ private
122
+
123
+ def verify_interactive!(message)
124
+ return if interactive?
125
+ important(message)
126
+ crash!("Could not retrieve response as sct runs in non-interactive mode")
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,120 @@
1
+ module SctCore
2
+ # Abstract super class
3
+ class Interface
4
+ #####################################################
5
+ # @!group Messaging: show text to the user
6
+ #####################################################
7
+
8
+ # Level Error: Can be used to show additional error
9
+ # information before actually raising an exception
10
+ # or can be used to just show an error from which
11
+ #
12
+ # By default those messages are shown in red
13
+ def error(_message)
14
+ not_implemented(__method__)
15
+ end
16
+
17
+ # Level Important: Can be used to show warnings to the user
18
+ # not necessarily negative, but something the user should
19
+ # be aware of.
20
+ #
21
+ # By default those messages are shown in yellow
22
+ def important(_message)
23
+ not_implemented(__method__)
24
+ end
25
+
26
+ # Level Success: Show that something was successful
27
+ #
28
+ # By default those messages are shown in green
29
+ def success(_message)
30
+ not_implemented(__method__)
31
+ end
32
+
33
+ # Level Message: Show a neutral message to the user
34
+ #
35
+ # By default those messages shown in white/black
36
+ def message(_message)
37
+ not_implemented(__method__)
38
+ end
39
+
40
+ # Level Deprecated: Show that a particular function is deprecated
41
+ #
42
+ # By default those messages shown in strong blue
43
+ def deprecated(_message)
44
+ not_implemented(__method__)
45
+ end
46
+
47
+ # Level Command: Print out a terminal command that is being
48
+ # executed.
49
+ #
50
+ # By default those messages shown in cyan
51
+ def command(_message)
52
+ not_implemented(__method__)
53
+ end
54
+
55
+ # Level Command Output: Print the output of a command with
56
+ # this method
57
+ #
58
+ # By default those messages shown in magenta
59
+ def command_output(_message)
60
+ not_implemented(__method__)
61
+ end
62
+
63
+ # Level Verbose: Print out additional information for the
64
+ # users that are interested. Will only be printed when
65
+ #
66
+ # By default those messages are shown in white
67
+ def verbose(_message)
68
+ not_implemented(__method__)
69
+ end
70
+
71
+ # Print a header = a text in a box
72
+ # use this if this message is really important
73
+ def header(_message)
74
+ not_implemented(__method__)
75
+ end
76
+
77
+ # Print lines of content around specific line where
78
+ # failed to parse.
79
+ #
80
+ # This message will be shown as error
81
+ def content_error(content, error_line)
82
+ not_implemented(__method__)
83
+ end
84
+
85
+ #####################################################
86
+ # @!group Errors: Inputs
87
+ #####################################################
88
+
89
+ # Is is possible to ask the user questions?
90
+ def interactive?
91
+ not_implemented(__method__)
92
+ end
93
+
94
+ # get a standard text input (single line)
95
+ def input(_message)
96
+ not_implemented(__method__)
97
+ end
98
+
99
+ # A simple yes or no question
100
+ def confirm(_message)
101
+ not_implemented(__method__)
102
+ end
103
+
104
+ # Let the user select one out of x items
105
+ # return value is the value of the option the user chose
106
+ def select(_message, _options)
107
+ not_implemented(__method__)
108
+ end
109
+
110
+ # Password input for the user, text field shouldn't show
111
+ # plain text
112
+ def password(_message)
113
+ not_implemented(__method__)
114
+ end
115
+
116
+ def user_error!(error_message, options = {})
117
+ not_implemented(__method__)
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,26 @@
1
+ module SctCore
2
+ class UI
3
+ class << self
4
+ attr_accessor(:ui_object)
5
+
6
+ def ui_object
7
+ require_relative 'implementations/shell'
8
+ @ui_object ||= Shell.new
9
+ end
10
+
11
+ def method_missing(method_sym, *args, &_block)
12
+ # not using `responds` because we don't care about methods like .to_s and so on
13
+ require_relative 'interface'
14
+ interface_methods = SctCore::Interface.instance_methods - Object.instance_methods
15
+ UI.user_error!("Unknown method '#{method_sym}', supported #{interface_methods}") unless interface_methods.include?(method_sym)
16
+
17
+ self.ui_object.send(method_sym, *args)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ # Import all available implementations
24
+ Dir[File.dirname(__FILE__) + '/implementations/*.rb'].each do |file|
25
+ require_relative file
26
+ end
@@ -0,0 +1,76 @@
1
+
2
+ require 'excon'
3
+ require 'json'
4
+
5
+ module SctCore
6
+ class UpdateChecker
7
+ def self.start_looking_for_update(gem_name)
8
+ begin
9
+ server_results[gem_name] = fetch_latest(gem_name)
10
+ rescue => e
11
+ # ignore possible exceptions
12
+ UI.verbose("error occured fetching latest version #{e.message}")
13
+ end
14
+ end
15
+
16
+ def self.server_results
17
+ @results ||= {}
18
+ end
19
+
20
+ def self.update_available?(gem_name, current_version)
21
+ latest = server_results[gem_name]
22
+ return (latest and Gem::Version.new(latest) > Gem::Version.new(current_version))
23
+ end
24
+
25
+ def self.show_update_status(gem_name, current_version)
26
+ if update_available?(gem_name, current_version)
27
+ show_update_message(gem_name, current_version)
28
+ end
29
+ end
30
+
31
+ def self.show_update_message(gem_name, current_version)
32
+ available = server_results[gem_name]
33
+ puts("")
34
+ UI.important('#######################################################################')
35
+ if available
36
+ UI.important("# #{gem_name} #{available} is available. You are on #{current_version}.")
37
+ else
38
+ UI.important("# An update for #{gem_name} is available. You are on #{current_version}.")
39
+ end
40
+ UI.important("# You should use the latest version.")
41
+ UI.important("# Please update using `#{self.update_command(gem_name: gem_name)}`.")
42
+
43
+ UI.important('#######################################################################')
44
+ UI.important("# Run `sudo gem cleanup` from time to time to speed up sct.")
45
+
46
+ UI.important('#######################################################################')
47
+
48
+ ensure_rubygems_source
49
+ end
50
+
51
+ # Check if RubyGems is set as a gem source
52
+ # on some machines that might not be the case
53
+ # and then users can't find the update when
54
+ # running the specified command
55
+ def self.ensure_rubygems_source
56
+ return if `gem sources`.include?("https://rubygems.org")
57
+ puts("")
58
+ UI.error("RubyGems is not listed as your Gem source")
59
+ UI.error("You can run `gem sources` to see all your sources")
60
+ UI.error("Please run the following command to fix this:")
61
+ UI.command("gem sources --add https://rubygems.org")
62
+ end
63
+
64
+ def self.update_command(gem_name: "sct")
65
+ "sudo gem install #{gem_name.downcase}"
66
+ end
67
+
68
+ def self.fetch_latest(gem_name)
69
+ JSON.parse(Excon.get(generate_fetch_url(gem_name)).body)["version"]
70
+ end
71
+
72
+ def self.generate_fetch_url(gem_name)
73
+ "https://rubygems.org/api/v1/gems/#{gem_name}.json"
74
+ end
75
+ end
76
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ require_relative 'shell/tools'
2
+ require_relative 'shell/runner'
3
+ require_relative 'shell/module'
@@ -0,0 +1,14 @@
1
+ require_relative 'runner'
2
+
3
+ module Shell
4
+ class CommandsGenerator
5
+
6
+ def self.start
7
+ self.new.run
8
+ end
9
+
10
+ def run
11
+ Shell::Runner.new.launch
12
+ end
13
+ end
14
+ end
@@ -1,13 +1,14 @@
1
- require "sct/docker/docker"
1
+ require "sct_core"
2
+ require_relative "docker"
2
3
 
3
- module Sct
4
+ module Shell
4
5
  class Composer < Docker
5
6
 
6
7
  # Configure the Yarn command
7
8
  def self.config
8
9
  self.setImage("eu.gcr.io/dev-pasc-vcdm/helpers-composer:latest", true)
9
10
  self.setPwdAsVolume("/app")
10
- self.addVolume(Sct::Helpers.convertWSLToWindowsPath("#{Sct::Helpers.windowsHomePath || Sct::Helpers.homePath}/.composer") , "/tmp")
11
+ self.addVolume(SctCore::Helper.convertWSLToWindowsPath("#{SctCore::Helper.windowsHomePath || SctCore::Helper.homePath}/.composer") , "/tmp")
11
12
  self.setCurrentUserAndGroup()
12
13
  self.setEntrypoint("composer")
13
14
  end
@@ -1,6 +1,7 @@
1
- require "sct/ClassLevelInheritableAttributes"
1
+ require "sct_core"
2
+ require "shell/ClassLevelInheritableAttributes"
2
3
 
3
- module Sct
4
+ module Shell
4
5
  class Docker
5
6
  include ClassLevelInheritableAttributes
6
7
  inheritable_attributes :image, :is_private_registry, :entrypoint, :volumes, :ports, :extra_arguments
@@ -26,9 +27,7 @@ module Sct
26
27
  ###
27
28
  def self.exec(cli_arguments)
28
29
 
29
- cli_arguments.each do | argument |
30
- self.addExtraArgument(argument)
31
- end
30
+ self.addExtraArgument(cli_arguments)
32
31
 
33
32
  self.config()
34
33
 
@@ -60,8 +59,8 @@ module Sct
60
59
  def self.setPwdAsVolume(volume_path)
61
60
  pwd = `pwd -P`
62
61
 
63
- if Sct::Helpers.operatingSystem == Sct::Helpers::WINDOWS
64
- pwd=Sct::Helpers.convertWSLToWindowsPath(pwd)
62
+ if SctCore::Helper.operatingSystem == SctCore::Helper::WINDOWS
63
+ pwd=SctCore::Helper.convertWSLToWindowsPath(pwd)
65
64
  end
66
65
 
67
66
  addVolume(pwd, volume_path)
@@ -141,9 +140,7 @@ module Sct
141
140
  def self.runCommand()
142
141
  command = self.compileCommand()
143
142
 
144
- system(command)
145
-
146
- return $?.success?
143
+ SctCore::CommandExecutor.execute(command: command, print_all: true, suppress_output: false)
147
144
  end
148
145
 
149
146
  ###
@@ -1,6 +1,7 @@
1
- require "sct/docker/docker"
1
+ require "sct_core"
2
+ require_relative "docker"
2
3
 
3
- module Sct
4
+ module Shell
4
5
  class Php < Docker
5
6
 
6
7
  # Configure the Yarn command