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(name) ⇒ Object
- #remove(name) ⇒ Object
- #restart(name) ⇒ Object
- #secure(domain) ⇒ Object
- #setup ⇒ Object
- #share(name, provider = nil, qrcode: false) ⇒ Object
- #start(name) ⇒ Object
- #start_all ⇒ Object
- #stop(name) ⇒ Object
- #stop_all ⇒ Object
- #upgrade_ruby(name, version) ⇒ Object
- #workdir(name) ⇒ 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
116 117 118 119 |
# File 'lib/stable/cli.rb', line 116 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
139 140 141 |
# File 'lib/stable/cli.rb', line 139 def doctor Commands::Doctor.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(name) ⇒ Object
149 150 151 |
# File 'lib/stable/cli.rb', line 149 def open(name) Stable::Commands::Open.new(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
96 97 98 |
# File 'lib/stable/cli.rb', line 96 def restart(name) Commands::Restart.new(name).call end |
#secure(domain) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/stable/cli.rb', line 122 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
111 112 113 |
# File 'lib/stable/cli.rb', line 111 def setup Commands::Setup.new.call end |
#share(name, provider = nil, qrcode: false) ⇒ Object
156 157 158 159 |
# File 'lib/stable/cli.rb', line 156 def share(name, provider = nil, qrcode: false) provider ||= [:provider] || 'ngrok' Commands::Share.new(name, provider: provider.to_sym, qrcode: [:qrcode]).call end |
#start(name) ⇒ Object
86 87 88 |
# File 'lib/stable/cli.rb', line 86 def start(name) Commands::Start.new(name).call end |
#start_all ⇒ Object
91 92 93 |
# File 'lib/stable/cli.rb', line 91 def start_all Commands::StartAll.new.call end |
#stop(name) ⇒ Object
101 102 103 |
# File 'lib/stable/cli.rb', line 101 def stop(name) Commands::Stop.new(name).call end |
#stop_all ⇒ Object
106 107 108 |
# File 'lib/stable/cli.rb', line 106 def stop_all Commands::StopAll.new.call end |
#upgrade_ruby(name, version) ⇒ Object
144 145 146 |
# File 'lib/stable/cli.rb', line 144 def upgrade_ruby(name, version) Commands::UpgradeRuby.new(name, version).call end |