Class: Holivia::Commands::Env
Class Method Summary collapse
Instance Method Summary collapse
- #add(args = []) ⇒ Object
- #debug(args = []) ⇒ Object
- #list ⇒ Object
- #remove(args = []) ⇒ Object
- #show ⇒ Object
- #use(args = []) ⇒ Object
Class Method Details
.route(args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/holivia/commands/env.rb', line 8 def self.route(args) subcommand = args.shift case subcommand when "add" then new.add(args) when "use" then new.use(args) when "remove" then new.remove(args) when "debug" then new.debug(args) when "list" then new.list when nil then new.show else warn "Unknown env command: #{subcommand}" exit 1 end end |
Instance Method Details
#add(args = []) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/holivia/commands/env.rb', line 36 def add(args = []) = {} OptionParser.new do |opts| opts. = "Usage: holivia env add <name> --url <url> [--debug]" opts.on("--url URL") { |v| [:url] = v } opts.on("--debug") { [:debug] = true } opts.on("--no-debug") { [:debug] = false } end.parse!(args) name = args.shift abort "Usage: holivia env add <name> --url <url>" unless name && [:url] config.add_env(name, url: [:url], debug: [:debug]) puts "Environment '#{name}' added." end |
#debug(args = []) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/holivia/commands/env.rb', line 68 def debug(args = []) value = nil OptionParser.new do |opts| opts. = "Usage: holivia env debug [name] --true/--false" opts.on("--true") { value = true } opts.on("--false") { value = false } end.parse!(args) name = args.shift || config.current_env abort "Usage: holivia env debug [name] --true/--false" if value.nil? config.update_env(name, debug: value) puts "Debug #{value ? "on" : "off"} for '#{name}'." end |
#list ⇒ Object
29 30 31 32 33 34 |
# File 'lib/holivia/commands/env.rb', line 29 def list config.environments.each do |name, env| prefix = name == config.current_env ? "*" : " " puts "#{prefix} #{name}\t#{env["url"]}" end end |
#remove(args = []) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/holivia/commands/env.rb', line 60 def remove(args = []) name = args.shift abort "Usage: holivia env remove <name>" unless name config.remove_env(name) puts "Environment '#{name}' removed." end |
#show ⇒ Object
22 23 24 25 26 27 |
# File 'lib/holivia/commands/env.rb', line 22 def show puts "Environment: #{config.current_env}" puts "URL: #{config.base_url}" puts "Debug: #{config.debug?}" puts "Credentials: #{File.exist?(config.credentials_path) ? "yes" : "no"}" end |
#use(args = []) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/holivia/commands/env.rb', line 52 def use(args = []) name = args.shift abort "Usage: holivia env use <name>" unless name config.use_env(name) puts "Switched to '#{name}'." end |