Class: Skewer::CLI::Parser
- Inherits:
-
Object
- Object
- Skewer::CLI::Parser
- Defined in:
- lib/parser.rb
Overview
Parses the CLI input and makes sure that it’s clean.
Instance Method Summary collapse
- #delete_usage ⇒ Object
- #destroy_node(node, options) ⇒ Object
-
#initialize(type = nil, options = {}) ⇒ Parser
constructor
A new instance of Parser.
- #provision_usage ⇒ Object
- #update_usage ⇒ Object
- #usage ⇒ Object
- #validate_options(options, type) ⇒ Object
Constructor Details
#initialize(type = nil, options = {}) ⇒ Parser
Returns a new instance of Parser.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/parser.rb', line 10 def initialize(type = nil, = {}) # base case tests that we have input that we accept. Fog.mock! if [:mock] (, type) if type == 'delete' if [:region] SkewerConfig.set 'region', [:region] end case [:kind] when :ec2 node = AWS::Node.find_by_name([:host]) when :rackspace node = Rackspace::Node.find_by_ip([:host]) else raise("#{[:kind]} not found") end destroy_node(node, ) else Skewer::CLI.bootstrap_and_go() end end |
Instance Method Details
#delete_usage ⇒ Object
87 88 89 90 91 92 |
# File 'lib/parser.rb', line 87 def delete_usage out = <<EOF Usage: skewer delete --cloud <which cloud> --host <host> EOF out.strip end |
#destroy_node(node, options) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/parser.rb', line 33 def destroy_node(node, ) if node node.destroy Skewer.logger.info("#{[:host]} deleted.") else abort("#{[:host]} not found.") end end |
#provision_usage ⇒ Object
73 74 75 76 77 78 |
# File 'lib/parser.rb', line 73 def provision_usage out = <<EOF Usage: skewer provision --cloud <which cloud> --image <AWS image> --role <puppet role class> EOF out.strip end |
#update_usage ⇒ Object
80 81 82 83 84 85 |
# File 'lib/parser.rb', line 80 def update_usage out = <<EOF Usage: skewer update --host <host> --user <user with sudo rights> --role <puppet role class> EOF out.strip end |
#usage ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/parser.rb', line 61 def usage out = <<EOF Usage: skewer COMMAND [options] The available skewer commands are: provision spawn a new VM via a cloud system and provision it with puppet code update update the puppet code on a machine that you've already provisioned delete deletes the given host from the provided cloud provider EOF out.strip end |
#validate_options(options, type) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/parser.rb', line 42 def (, type) abort(usage) if type.nil? and .empty? abort(usage) unless ['provision', 'update', 'delete'].include? type abort("A key (--key KEY) must be provided if using EC2") if [:kind] == :ec2 && ![:key_name] if type == 'provision' unless [:kind] && [:image] && [:role] && ![:help] abort(provision_usage) end elsif type == 'update' unless [:host] && [:user] && ![:help] abort(update_usage) end elsif type == 'delete' unless [:kind] && [:host] && ![:help] abort(delete_usage) end end end |