#!/usr/bin/env ruby require 'rubygems' require 'gli' require 'opsicle' include GLI::App program_desc 'Opsworks Command Line Utility Belt' version Opsicle::VERSION wrap_help_text :verbatim program_long_desc """ DOCUMENTATION For documentation and help in setting up your configuration files, see Opsicle's GitHub repo: https://github.com/sportngin/opsicle """ switch :verbose, :desc => 'Enable Verbose mode for more logging', :negatable => false switch :debug, :desc => 'Enable Debug mode for detailed logs and backtraces', :negatable => false switch :color, :desc => 'Use colored output', :default_value => true pre do |global_options, command, options, args| $verbose = global_options[:verbose] $debug = global_options[:debug] $color = global_options[:color] ENV['GLI_DEBUG'] = $debug.to_s true end on_error do |exception| exit(0) if exception.is_a?(Opsicle::Monitor::QuitMonitor) true end desc "Deploy your current app to the given environment stack" arg_name '' command :deploy do |c| c.switch [:b, :browser], :desc => "Open the OpsWorks deployments screen for this stack on deploy" c.switch [:m, :monitor], :desc => "Run the Stack Monitor on deploy", :default_value => true c.action do |global_options, options, args| raise ArgumentError, 'You must specify an environment' unless args.first Opsicle::Deploy.new(args.first).execute global_options.merge(options) end end desc "List all apps in the given environment stack" arg_name '' command :list do |c| c.action do |global_options, options, args| raise ArgumentError, "Environment is required" unless args.first Opsicle::List.new(args.first).execute global_options.merge options end end desc "SSH access to instances in the given environment stack" arg_name '' command :ssh do |c| c.action do |global_options, options, args| raise ArgumentError, "Environment is required" unless args.first Opsicle::SSH.new(args.first).execute global_options.merge(options) end end desc "Set your user SSH key (PUBLIC KEY) for OpsWorks" arg_name ' ' command 'ssh-key' do |c| c.action do |global_options, options, args| raise ArgumentError, "Environment is required" unless args.first raise ArgumentError, "ssh public key-file is required" unless args[1] Opsicle::SSHKey.new(*args).execute global_options.merge(options) end end desc "Launch the Opsicle Stack Monitor for the given environment stack" arg_name '' command 'monitor' do |c| c.action do |global_options, options, args| raise ArgumentError, "Environment is required" unless args.first @monitor = Opsicle::Monitor::App.new(args.first, global_options.merge(options)) @monitor.start end end desc "Show the OpsWorks URL for the given environment stack" long_desc """ Shows the full OpsWorks URL to a page in the web interface. Acceptable arguments to --page include: stack (default) layers instances apps deployments monitoring resources permissions Example: 'opsicle opsworks-url staging --page=deployments' """ arg_name '' command 'opsworks-url' do |c| opsworks_pages = %w(stack layers instances apps deployments monitoring resources permissions) c.flag [:p, :page], :desc => 'Request a specific page in the OpsWorks web interface', :must_match => opsworks_pages, :default_value => 'stack' c.action do |global_options, options, args| raise ArgumentError, "Environment is required" unless args.first url = "#{Opsicle::Client.new(args.first).opsworks_url}/#{options[:page]}" Opsicle::Output.say url end end exit run(ARGV)