sct 0.1.18 → 0.1.19
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/bin/sct +3 -4
- data/{.DS_Store → cluster/lib/.DS_Store} +0 -0
- data/cluster/lib/cluster.rb +6 -0
- data/cluster/lib/cluster/commands_generator.rb +95 -0
- data/cluster/lib/cluster/module.rb +7 -0
- data/{lib/sct/commands/cluster.rb → cluster/lib/cluster/runner.rb} +96 -118
- data/{lib → sct/lib}/.DS_Store +0 -0
- data/sct/lib/sct.rb +17 -0
- data/sct/lib/sct/.DS_Store +0 -0
- data/sct/lib/sct/cli_tools_distributor.rb +46 -0
- data/{lib → sct/lib}/sct/command.rb +0 -0
- data/{lib → sct/lib}/sct/commands/hostfile.rb +7 -23
- data/sct/lib/sct/commands/init.rb +37 -0
- data/sct/lib/sct/commands/mysqlproxy.rb +20 -0
- data/sct/lib/sct/commands_generator.rb +56 -0
- data/sct/lib/sct/tools.rb +12 -0
- data/sct/lib/sct/version.rb +3 -0
- data/sct_core/lib/.DS_Store +0 -0
- data/sct_core/lib/sct_core.rb +13 -0
- data/{lib/sct → sct_core/lib/sct_core}/.DS_Store +0 -0
- data/sct_core/lib/sct_core/command_executor.rb +104 -0
- data/{lib/sct → sct_core/lib/sct_core}/config.rb +3 -3
- data/sct_core/lib/sct_core/core_ext/string.rb +9 -0
- data/{lib/sct/setup/helpers.rb → sct_core/lib/sct_core/helper.rb} +2 -2
- data/sct_core/lib/sct_core/module.rb +0 -0
- data/sct_core/lib/sct_core/sct_pty.rb +53 -0
- data/sct_core/lib/sct_core/ui/implementations/shell.rb +129 -0
- data/sct_core/lib/sct_core/ui/interface.rb +120 -0
- data/sct_core/lib/sct_core/ui/ui.rb +26 -0
- data/shell/README.md +0 -0
- data/shell/lib/shell.rb +3 -0
- data/{lib/sct → shell/lib/shell}/ClassLevelInheritableAttributes.rb +0 -0
- data/shell/lib/shell/commands_generator.rb +14 -0
- data/{lib/sct → shell/lib/shell}/docker/composer.rb +4 -3
- data/{lib/sct → shell/lib/shell}/docker/docker.rb +7 -10
- data/{lib/sct → shell/lib/shell}/docker/php.rb +3 -2
- data/{lib/sct → shell/lib/shell}/docker/yarn.rb +4 -3
- data/shell/lib/shell/module.rb +9 -0
- data/shell/lib/shell/runner.rb +34 -0
- data/shell/lib/shell/tools.rb +7 -0
- metadata +89 -53
- data/.gitignore +0 -12
- data/.gitlab/merge_request_templates/DefinitionOfDone.md +0 -14
- data/.rspec +0 -3
- data/.travis.yml +0 -7
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -4
- data/Gemfile.lock +0 -48
- data/LICENSE.txt +0 -21
- data/README.md +0 -134
- data/Rakefile +0 -6
- data/lib/sct.rb +0 -61
- data/lib/sct/command_interface.rb +0 -18
- data/lib/sct/command_option.rb +0 -14
- data/lib/sct/commands/composer.rb +0 -29
- data/lib/sct/commands/init.rb +0 -51
- data/lib/sct/commands/mysqlproxy.rb +0 -38
- data/lib/sct/commands/php.rb +0 -37
- data/lib/sct/commands/yarn.rb +0 -26
- data/lib/sct/version.rb +0 -3
- data/resources/corefile.yml +0 -45
- 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
|
data/shell/README.md
ADDED
File without changes
|
data/shell/lib/shell.rb
ADDED
File without changes
|
@@ -1,13 +1,14 @@
|
|
1
|
-
require "
|
1
|
+
require "sct_core"
|
2
|
+
require_relative "docker"
|
2
3
|
|
3
|
-
module
|
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(
|
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 "
|
1
|
+
require "sct_core"
|
2
|
+
require "shell/ClassLevelInheritableAttributes"
|
2
3
|
|
3
|
-
module
|
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
|
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
|
64
|
-
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
|
-
|
145
|
-
|
146
|
-
return $?.success?
|
143
|
+
SctCore::CommandExecutor.execute(command: command, print_all: true, suppress_output: false)
|
147
144
|
end
|
148
145
|
|
149
146
|
###
|
@@ -1,13 +1,14 @@
|
|
1
|
-
require "
|
1
|
+
require "sct_core"
|
2
|
+
require_relative "docker"
|
2
3
|
|
3
|
-
module
|
4
|
+
module Shell
|
4
5
|
class Yarn < 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-yarn:latest", true)
|
9
10
|
self.setPwdAsVolume("/app")
|
10
|
-
self.addVolume(
|
11
|
+
self.addVolume(SctCore::Helper.convertWSLToWindowsPath("#{SctCore::Helper.windowsHomePath || SctCore::Helper.homePath}/.cache") , "/.cache")
|
11
12
|
self.mapPort(8081, 8080)
|
12
13
|
self.mapPort(9001)
|
13
14
|
self.setCurrentUserAndGroup()
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Shell
|
2
|
+
class Runner
|
3
|
+
# define launch work
|
4
|
+
def launch
|
5
|
+
|
6
|
+
tool_name = ARGV.first ? ARGV.first.downcase : nil
|
7
|
+
|
8
|
+
if tool_name && Shell::TOOLS.include?(tool_name.to_sym)
|
9
|
+
|
10
|
+
require_relative "docker/#{tool_name}"
|
11
|
+
command = "#{ARGV[1..(ARGV.length+1)].join(" ")}"
|
12
|
+
|
13
|
+
case ARGV.first
|
14
|
+
when 'php'
|
15
|
+
Shell::Php.exec(command)
|
16
|
+
when 'composer'
|
17
|
+
Shell::Composer.exec(command)
|
18
|
+
when 'yarn'
|
19
|
+
Shell::Yarn.exec(command)
|
20
|
+
else
|
21
|
+
show_error
|
22
|
+
end
|
23
|
+
|
24
|
+
else
|
25
|
+
show_error
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def show_error
|
30
|
+
tools = Shell::TOOLS.map { |tool| tool.to_s }.join(", ")
|
31
|
+
UI.error("Tool not found. Try one of these: #{tools}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|