Class: Dogids::Cli
- Inherits:
-
Thor
- Object
- Thor
- Dogids::Cli
- Includes:
- Thor::Actions
- Defined in:
- lib/dogids/run.rb,
lib/dogids/ssh.rb,
lib/dogids/base.rb,
lib/dogids/cache.rb,
lib/dogids/config.rb,
lib/dogids/deploy.rb,
lib/dogids/reload.rb,
lib/dogids/version.rb,
lib/dogids/deploy/web.rb,
lib/dogids/ssh/staging.rb,
lib/dogids/cache/staging.rb,
lib/dogids/deploy/worker.rb,
lib/dogids/deploy/backend.rb,
lib/dogids/deploy/staging.rb,
lib/dogids/deploy/testing.rb,
lib/dogids/ssh/production.rb,
lib/dogids/ssh/development.rb,
lib/dogids/cache/production.rb,
lib/dogids/cache/development.rb
Class Method Summary collapse
-
.source_root ⇒ Object
This is the directory where your templates should be placed.
Instance Method Summary collapse
- #cache(env_name = nil) ⇒ Object
- #config(command = nil) ⇒ Object
- #deploy(app_name = nil) ⇒ Object
-
#dev(app_name = nil) ⇒ Object
Run the development site.
-
#help(method = nil) ⇒ Object
Add the ablitity to print help for commands like: ‘dogids help development:install` This would print help for the method: `development_install`.
-
#method_missing(method, *args, &block) ⇒ Object
Add the ablitity to run commands like: ‘dogids development:install` This would run the defined method: `development_install`.
-
#reload(app_name = nil) ⇒ Object
Reload the specified environment TODO add environments.
- #ssh(vm_name = nil) ⇒ Object
- #update ⇒ Object
- #version ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Add the ablitity to run commands like:
`dogids development:install`
This would run the defined method:
`development_install`
27 28 29 30 31 32 33 34 35 |
# File 'lib/dogids/base.rb', line 27 def method_missing(method, *args, &block) if method.to_s.split(":").length >= 2 self.send(method.to_s.gsub(":", "_"), *args) elsif method.to_s == "run" self.walk(*args) else super end end |
Class Method Details
.source_root ⇒ Object
This is the directory where your templates should be placed.
38 39 40 |
# File 'lib/dogids/base.rb', line 38 def self.source_root File.("../../../resources", __FILE__) end |
Instance Method Details
#cache(env_name = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dogids/cache.rb', line 9 def cache(env_name = nil) puts " " puts "Cache Commands:" puts " " puts " Use the following format:" puts " dogids cache:<environment> <machine> <action>" puts " " puts " Here are some basic examples:" puts " " puts " dogids cache:dev dev clear # Clear whole cache for the dogids.dev storefront" puts " dogids cache:dev dev category # Clear category cache for the dogids.dev storefront" puts " dogids cache:dev dev css # Clear CSS cache for the dogids.dev storefront" puts " dogids cache:dev dev javascript # Clear Javascript cache for the dogids.dev storefront" puts " dogids cache:dev dev qa # Clear Q&A cache for the dogids.dev storefront" puts " " puts " dogids cache:staging staging clear # Clear whole cache for the staging.dogids.com storefront" puts " dogids cache:staging staging category # Clear category cache for the staging.dogids.com storefront" puts " dogids cache:staging staging css # Clear CSS cache for the staging.dogids.com storefront" puts " dogids cache:staging staging javascript # Clear Javascript cache for the staging.dogids.com storefront" puts " dogids cache:staging staging qa # Clear Q&A cache for the staging.dogids.com storefront" puts " " puts " dogids cache:production web clear # Clear whole cache for the dogids.com storefront" puts " dogids cache:production web category # Clear category cache for the dogids.dev storefront" puts " dogids cache:production web css # Clear CSS cache for the production.dogids.com storefront" puts " dogids cache:production web javascript # Clear Javascript cache for the production.dogids.com storefront" puts " dogids cache:production web qa # Clear Q&A cache for the dogids.com storefront" puts " " end |
#config(command = nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dogids/config.rb', line 7 def config(command = nil) # Commands case command when "list" list when "clear" if yes?("------->Remove all configurations? [no]") system("rm ~/.dogids/conf.yaml") puts " " say("All configurations removed","\e[31m") set_default_configuration puts " " list else say("Fine, I didn't want to remove anything anyway","\e[31m") end else puts " " puts "Config Commands:" puts " " puts " Use the following so set environments:" puts " dogids config:<environment> <machine>" puts " " puts " dogids config list # List all current configurations" puts " " puts " dogids config:dev # Set URL/IP for Development Machines" puts " dogids config:production # Set URL/IP for Production Machines" puts " dogids config:staging # Set URL/IP for Staging machines" puts " " end end |
#deploy(app_name = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dogids/deploy.rb', line 11 def deploy(app_name = nil) deploy_command = "deploy_#{app_name}" return self.send(deploy_command) if self.respond_to?(deploy_command) puts "Deployment Commands:" puts " dogids deploy backend # Deploy the new backend" puts " dogids deploy staging # Deploy the staging.dogids.com storefront" puts " dogids deploy testing # Deploy the new backend to testing" puts " dogids deploy web # Deploy the dogids.com storefront" puts " dogids deploy worker # Deploy the dogids-backgrounder app" puts " " end |
#dev(app_name = nil) ⇒ Object
Run the development site
9 10 11 |
# File 'lib/dogids/run.rb', line 9 def dev(app_name = nil) system("cd ~/dogids-backend/themes/dogids && npm run dev") end |
#help(method = nil) ⇒ Object
Add the ablitity to print help for commands like:
`dogids help development:install`
This would print help for the method:
`development_install`
14 15 16 17 18 19 20 21 |
# File 'lib/dogids/base.rb', line 14 def help(method = nil) if method.to_s.split(":").length >= 2 method = method.to_s.gsub(":", "_") elsif method.to_s == "run" method = "walk" end super end |
#reload(app_name = nil) ⇒ Object
Reload the specified environment TODO add environments
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dogids/reload.rb', line 10 def reload(app_name = nil) ssh_address = get_config_url("dev","dev") if yes?("-----> Reload development? [no]") reload_development_machine restart_lamp(ssh_address, "dogids") elsif yes?("-----> Restart LAMP stack? [no]") restart_lamp(ssh_address, "dogids") elsif yes?("-----> Restart LB and LAMP stack? [no]") restart_all elsif yes?("-----> Update Vagrant Box? (NOT RECOMMENDED) [no]") update_vagrant_box else say("Fine, I didn't want you to do anything anyway.") end end |
#ssh(vm_name = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dogids/ssh.rb', line 9 def ssh(vm_name = nil) case vm_name when "dev" ssh_dev(vm_name) when "staging" ssh_staging(vm_name) else puts "Development SSH Commands:" puts " dogids ssh:dev dev # SSH into local development VM" puts " dogids ssh:dev lb # SSH into local development LB" puts " " puts "Staging SSH Commands:" puts " dogids ssh:staging lb # SSH into staging LB" puts " dogids ssh:staging staging # SSH into staging Apache/PHP/MySQL VM" puts " " puts "Production SSH Commands:" puts " dogids ssh:production lb # SSH into production LB" puts " dogids ssh:production railgun # SSH into production railgun instance" puts " dogids ssh:production admin # SSH into VM for long running admin processes" puts " dogids ssh:production db # SSH into production MySQL/Redis VM" puts " dogids ssh:production web # SSH into production Apache/PHP VM" puts " dogids ssh:production worker # SSH into production Ruby/Sidekiq VM" puts " " end end |
#update ⇒ Object
10 11 12 13 14 |
# File 'lib/dogids/version.rb', line 10 def update command = "gem install dogids-cli" puts "Running #{command}" exec(command) end |
#version ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dogids/version.rb', line 17 def version gem_version = "v#{Dogids::VERSION}" # Grab the latest version of the RubyGem rubygems_json = open("https://rubygems.org/api/v1/gems/dogids-cli.json").read rubygems_version = "v#{JSON.parse(rubygems_json)['version'].strip}" = "" if gem_version != rubygems_version = " Run `dogids update` to install" end puts puts "Dogids CLI" puts " Installed: #{gem_version}" puts " Latest: #{rubygems_version}#{}" puts end |