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
- #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 |
# File 'lib/stable/cli.rb', line 14 def initialize(*) super Stable::Bootstrap.run! Services::SetupRunner.ensure_dependencies! end |
Class Method Details
.exit_on_failure? ⇒ Boolean
20 21 22 |
# File 'lib/stable/cli.rb', line 20 def self.exit_on_failure? true end |
Instance Method Details
#add(folder) ⇒ Object
44 45 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 |
# File 'lib/stable/cli.rb', line 44 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
104 105 106 107 |
# File 'lib/stable/cli.rb', line 104 def caddy_reload Services::CaddyManager.reload puts 'Caddy reloaded' end |
#destroy(name) ⇒ Object
79 80 81 |
# File 'lib/stable/cli.rb', line 79 def destroy(name) Commands::Destroy.new(name).call end |
#doctor ⇒ Object
127 128 129 |
# File 'lib/stable/cli.rb', line 127 def doctor Commands::Doctor.new.call end |
#list ⇒ Object
39 40 41 |
# File 'lib/stable/cli.rb', line 39 def list Commands::List.new.call end |
#new(name, ruby: RUBY_VERSION, rails: nil, port: nil) ⇒ Object
33 34 35 36 |
# File 'lib/stable/cli.rb', line 33 def new(name, ruby: RUBY_VERSION, rails: nil, port: nil) safe_name = Validators::AppName.call!(name) Commands::New.new(safe_name, ).call end |
#remove(name) ⇒ Object
74 75 76 |
# File 'lib/stable/cli.rb', line 74 def remove(name) Commands::Remove.new(name).call end |
#restart(name) ⇒ Object
89 90 91 |
# File 'lib/stable/cli.rb', line 89 def restart(name) Commands::Restart.new(name).call end |
#secure(domain) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/stable/cli.rb', line 110 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
99 100 101 |
# File 'lib/stable/cli.rb', line 99 def setup Commands::Setup.new.call end |
#start(name) ⇒ Object
84 85 86 |
# File 'lib/stable/cli.rb', line 84 def start(name) Commands::Start.new(name).call end |
#stop(name) ⇒ Object
94 95 96 |
# File 'lib/stable/cli.rb', line 94 def stop(name) Commands::Stop.new(name).call end |
#upgrade_ruby(name, version) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/stable/cli.rb', line 132 def upgrade_ruby(name, version) app = Services::AppRegistry.find(name) unless app puts "No app named #{name}" return end if Stable::Services::Ruby.rvm_available? system("bash -lc 'rvm install #{version}'") elsif Stable::Services::Ruby.rbenv_available? system("rbenv install #{version}") else puts 'No Ruby version manager found' return end File.write(File.join(app[:path], '.ruby-version'), version) Services::AppRegistry.update(name, ruby: version) puts "#{name} now uses Ruby #{version}" end |