Class: Stable::CLI
- Inherits:
-
Thor
- Object
- Thor
- Stable::CLI
- Defined in:
- lib/stable/cli.rb
Overview
Main CLI class for the Stable command-line interface
Class Method Summary collapse
Instance Method Summary collapse
- #add(folder) ⇒ Object
- #caddy_reload ⇒ Object
- #destroy(name) ⇒ Object
- #doctor ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #list ⇒ Object
- #new(name, ruby: RUBY_VERSION, rails: nil, port: nil) ⇒ Object
- #open(app_name) ⇒ Object
- #remove(name) ⇒ Object
- #restart(name) ⇒ Object
- #secure(domain) ⇒ Object
- #setup ⇒ Object
- #start(name) ⇒ Object
- #stop(name) ⇒ Object
- #upgrade_ruby(name, version) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
14 15 16 17 18 19 20 |
# File 'lib/stable/cli.rb', line 14 def initialize(*) super return if ENV['STABLE_TEST_MODE'] Stable::Bootstrap.run! Services::SetupRunner.ensure_dependencies! end |
Class Method Details
.exit_on_failure? ⇒ Boolean
22 23 24 |
# File 'lib/stable/cli.rb', line 22 def self.exit_on_failure? true end |
Instance Method Details
#add(folder) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/stable/cli.rb', line 46 def add(folder) folder = File.(folder) unless File.exist?(File.join(folder, 'config', 'application.rb')) puts "Not a Rails app: #{folder}" return end puts "Detected gemset: #{File.read('.ruby-gemset').strip}" if File.exist?('.ruby-gemset') name = File.basename(folder) domain = "#{name}.test" if Services::AppRegistry.all.any? { |a| a[:path] == folder } puts "App already exists: #{name}" return end port = next_free_port ruby = Stable::Services::Ruby.detect_ruby_version(folder) app = { name: name, path: folder, domain: domain, port: port, ruby: ruby } Services::AppRegistry.add_app(app) puts "Added #{name} -> https://#{domain} (port #{port})" Services::HostsManager.add(domain) Services::CaddyManager.add_app(name, skip_ssl: [:skip_ssl]) Services::CaddyManager.reload end |
#caddy_reload ⇒ Object
106 107 108 109 |
# File 'lib/stable/cli.rb', line 106 def caddy_reload Services::CaddyManager.reload puts 'Caddy reloaded' end |
#destroy(name) ⇒ Object
81 82 83 |
# File 'lib/stable/cli.rb', line 81 def destroy(name) Commands::Destroy.new(name).call end |
#doctor ⇒ Object
129 130 131 |
# File 'lib/stable/cli.rb', line 129 def doctor Commands::Doctor.new.call end |
#list ⇒ Object
41 42 43 |
# File 'lib/stable/cli.rb', line 41 def list Commands::List.new.call end |
#new(name, ruby: RUBY_VERSION, rails: nil, port: nil) ⇒ Object
35 36 37 38 |
# File 'lib/stable/cli.rb', line 35 def new(name, ruby: RUBY_VERSION, rails: nil, port: nil) safe_name = Validators::AppName.call!(name) Commands::New.new(safe_name, ).call end |
#open(app_name) ⇒ Object
139 140 141 |
# File 'lib/stable/cli.rb', line 139 def open(app_name) Stable::Commands::Open.new(app_name).call end |
#remove(name) ⇒ Object
76 77 78 |
# File 'lib/stable/cli.rb', line 76 def remove(name) Commands::Remove.new(name).call end |
#restart(name) ⇒ Object
91 92 93 |
# File 'lib/stable/cli.rb', line 91 def restart(name) Commands::Restart.new(name).call end |
#secure(domain) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/stable/cli.rb', line 112 def secure(domain) apps = Services::AppRegistry.all app = apps.find { |a| a[:domain] == domain } app ||= apps.find { |a| a[:name] == domain } app ||= apps.find { |a| a[:domain] == "#{domain}.test" } unless app puts "No app found with domain #{domain}" return end Services::CaddyManager.add_app(app[:name], skip_ssl: true) Services::CaddyManager.reload puts "Secured https://#{app[:domain]}" end |
#setup ⇒ Object
101 102 103 |
# File 'lib/stable/cli.rb', line 101 def setup Commands::Setup.new.call end |
#start(name) ⇒ Object
86 87 88 |
# File 'lib/stable/cli.rb', line 86 def start(name) Commands::Start.new(name).call end |
#stop(name) ⇒ Object
96 97 98 |
# File 'lib/stable/cli.rb', line 96 def stop(name) Commands::Stop.new(name).call end |
#upgrade_ruby(name, version) ⇒ Object
134 135 136 |
# File 'lib/stable/cli.rb', line 134 def upgrade_ruby(name, version) Commands::UpgradeRuby.new(name, version).call end |