Class: Terraspace::Command
Class Method Summary
collapse
logger
Class Method Details
.alter_command_description(command) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/terraspace/command.rb', line 116
def alter_command_description(command)
return unless command
long_desc = if command.long_description
"#{command.description}\n\n#{command.long_description}"
else
command.description
end
unless website.empty?
full_command = [command.ancestor_name, command.name].compact.join('-')
url = "#{website}/reference/terraspace-#{full_command}"
long_desc += "\n\nHelp also available at: #{url}"
end
command.long_description = long_desc
end
|
.check_project!(command_name) ⇒ Object
94
95
96
97
98
99
100
101
|
# File 'lib/terraspace/command.rb', line 94
def check_project!(command_name)
return if subcommand?
return if command_name.nil?
return if %w[-h -v check_setup completion completion_script help new test version].include?(command_name)
return if File.exist?("#{Terraspace.root}/config/app.rb")
logger.error "ERROR: It doesnt look like this is a terraspace project. Are you sure you are in a terraspace project?".color(:red)
ENV['TS_TEST'] ? raise : exit(1)
end
|
.check_standalone_install! ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/terraspace/command.rb', line 62
def check_standalone_install!
return unless opt?
version_manager = "rvm" if rvm?
version_manager = "rbenv" if rbenv?
if rbenv? || rvm?
puts <<~EOL.color(:yellow)
WARN: It looks like a standalone Terraspace install and #{version_manager} is also in use.
Different gems from the standalone Terraspace install and #{version_manager} can cause all kinds of trouble.
Please install Terraspace as a gem instead and remove the standalone Terraspace /opt/terraspace installation.
See: https://terraspace.cloud/docs/install/gem/
EOL
end
end
|
.command_help(shell, command_name) ⇒ Object
Override command_help to include the description at the top of the long_description.
109
110
111
112
113
114
|
# File 'lib/terraspace/command.rb', line 109
def command_help(shell, command_name)
meth = normalize_command_name(command_name)
command = all_commands[meth]
alter_command_description(command)
super
end
|
.dispatch(m, args, options, config) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/terraspace/command.rb', line 32
def dispatch(m, args, options, config)
check_standalone_install!
check_project!(args.first)
help_flags = Thor::HELP_MAPPINGS + ["help"]
if args.length > 1 && !(args & help_flags).empty?
args -= help_flags
args.insert(-2, "help")
end
version_flags = ["--version", "-v"]
if args.length == 1 && !(args & version_flags).empty?
args = ["version"]
end
super
end
|
.exit_on_failure? ⇒ Boolean
github.com/erikhuda/thor/issues/244 Deprecation warning: Thor exit with status 0 on errors. To keep this behavior, you must define ‘exit_on_failure?` in `Lono::CLI` You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.
145
146
147
|
# File 'lib/terraspace/command.rb', line 145
def exit_on_failure?
true
end
|
.opt? ⇒ Boolean
76
77
78
79
80
|
# File 'lib/terraspace/command.rb', line 76
def opt?
paths = ENV['PATH'].split(':')
opt = paths.detect { |p| p.include?('/opt/terraspace') }
opt && File.exist?('/opt/terraspace')
end
|
.rbenv? ⇒ Boolean
88
89
90
91
92
|
# File 'lib/terraspace/command.rb', line 88
def rbenv?
paths = ENV['PATH'].split(':')
rbenv = paths.detect { |p| p.include?('/rbenv/') || p.include?('/.rbenv/') }
rbenv && system("type rbenv > /dev/null 2>&1")
end
|
.rvm? ⇒ Boolean
82
83
84
85
86
|
# File 'lib/terraspace/command.rb', line 82
def rvm?
paths = ENV['PATH'].split(':')
rvm = paths.detect { |p| p.include?('/rvm/') || p.include?('/.rvm/') }
rvm && system("type rvm > /dev/null 2>&1")
end
|
.subcommand? ⇒ Boolean
103
104
105
|
# File 'lib/terraspace/command.rb', line 103
def subcommand?
!!caller.detect { |l| l.include?('in subcommand') }
end
|
.website ⇒ Object
138
139
140
|
# File 'lib/terraspace/command.rb', line 138
def website
"https://terraspace.cloud"
end
|