#!/usr/bin/env ruby # Copyright 2012 Hewlett-Packard Development Company, L.P. # All Rights Reserved. # # Author: Simon McCartney # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # require 'bundler' require 'optparse' require 'methadone' require 'stack-kicker' require 'stack' class App include Methadone::Main include Methadone::CLILogging main do |task| debug { "options = #{options}" } # pass the logger.level into the Stack module Stack.log_level(logger.level) if (task != 'show-stacks') config = Stack.select_stack(options[:stackfile], options['stack']) end # pass some command line options into the config config['skip-secgroup-sync-deletes'] = options['skip-secgroup-sync-deletes'].nil? ? false : true case task when 'validate' Stack.validate(config) when 'configure-knife' Stack.generate_knife_rb(config) when 'show-stacks' Stack.show_stacks(options[:stackfile]) when 'show-stack' Stack.show_stack(config) when 'show-running' Stack.show_running(config) when 'build' Stack.deploy_all(config) when 'delete' Stack.delete_all(config) when 'secgroup-sync' Stack.secgroup_sync(config) else error "Sorry, #{task} hasn't been implemented yet" end end # supplemental methods here # Declare command-line interface here description "create application stacks in the cloud from fundamental building blocks" # # Accept flags via: # on("--flag VAL","Some flag") # options[flag] will contain VAL # # Specify switches via: # on("--[no-]switch","Some switch") # options[:stackfile] = 'Stackfile' on("--stackfile Stackfile", "Specify an alternative Stackfile") on("--stack mystack", "Specify the stack in Stackfile that you want to work with") on("--ssh-user USER", "User to be used for SSH access") on("--skip-secgroup-sync-deletes", "Skip deletes during secgroup-sync, handy for running multiple stacks in the one account with overlapping group names") arg :task, "task to be performed validate|configure-knife|show-stacks|show-stack|show-running|build|replace|delete|secgroup-sync|ssh" version Stack::Kicker::VERSION use_log_level_option go! end