Module: CloudFlock::App

Extended by:
App
Includes:
ConsoleGlitter
Included in:
App, Common
Defined in:
lib/cloudflock/app.rb,
lib/cloudflock/error.rb,
lib/cloudflock/errstr.rb,
lib/cloudflock/app/files-migrate.rb,
lib/cloudflock/app/common/cleanup.rb,
lib/cloudflock/app/common/servers.rb,
lib/cloudflock/app/server-migrate.rb,
lib/cloudflock/app/server-profile.rb,
lib/cloudflock/app/common/rackspace.rb,
lib/cloudflock/app/common/exclusions.rb,
lib/cloudflock/app/common/cleanup/unix.rb,
lib/cloudflock/app/common/exclusions/unix.rb,
lib/cloudflock/app/common/platform_action.rb,
lib/cloudflock/app/common/exclusions/unix/centos.rb,
lib/cloudflock/app/common/exclusions/unix/redhat.rb

Overview

Public: The App module provides any functionality that is expected to be used by all CLI applications.

Defined Under Namespace

Modules: Common, Rackspace Classes: FilesMigrate, ServerMigrate, ServerProfile

Instance Method Summary collapse

Instance Method Details

#check_option(options, name, prompt, prompt_options = {}) ⇒ Object

Public: Check if an option is set; return the value if so, otherwise prompt the user for a response.

options - Hash containing options to test against. name - The key in the options Hash expected to contain the

response desired.

prompt - Prompt to present to the user. prompt_options - Options to pass along to ConsoleGlitter::UI#prompt.

(default: {})

Returns the contents of the options or else a String if options is nil.



23
24
25
26
27
# File 'lib/cloudflock/app.rb', line 23

def check_option(options, name, prompt, prompt_options = {})
  return options[name] unless options[name].nil?

  options[name] = UI.prompt(prompt, prompt_options)
end

#check_option_fs(options, name, prompt, prompt_options = {}) ⇒ Object

Public: Wrap check_option, allowing for filesystem autocompletion in user response if the option is not set.

options - Hash containing options to test against. name - The key in the options Hash expected to contain the

response desired.

prompt - Prompt to present to the user. prompt_options - Options to pass along to ConsoleGlitter::UI#prompt.

(default: {})

Returns the contents of the options or else a String if options is nil.



41
42
43
44
45
# File 'lib/cloudflock/app.rb', line 41

def check_option_fs(options, name, prompt, prompt_options = {})
  return options[name] unless options[name].nil?

  options[name] = UI.prompt_filesystem(prompt, prompt_options)
end

#check_option_pw(options, name, prompt, prompt_options = {}) ⇒ Object

Public: Wrap check_option, disabling local echo for password entry if the option is not set.

options - Hash containing options to test against. name - The key in the options Hash expected to contain the

response desired.

prompt - Prompt to present to the user. prompt_options - Options to pass along to ConsoleGlitter::UI#prompt.

(default: {})

Returns the contents of the options or else a String if options is nil.



59
60
61
62
63
# File 'lib/cloudflock/app.rb', line 59

def check_option_pw(options, name, prompt, prompt_options = {})
  return options[name] unless options[name].nil?

  options[name] = UI.secure_prompt(prompt, prompt_options)
end

#check_option_yn(options, name, prompt, prompt_options = {}) ⇒ Object

Public: Check if an option is set; return the value if so, otherwise prompt the user for a response.

options - Hash containing options to test against. name - The key in the options Hash expected to contain the

response desired.

prompt - Prompt to present to the user. prompt_options - Options to pass along to ConsoleGlitter::UI#prompt_yn.

(default: {})

Returns true or false.



76
77
78
79
80
# File 'lib/cloudflock/app.rb', line 76

def check_option_yn(options, name, prompt, prompt_options = {})
  return(options[name] ? true : false) unless options[name].nil?

  options[name] = UI.prompt_yn(prompt, prompt_options)
end

#parse_options(options = {}) ⇒ Object

Public: Parse options and expose global options which are expected to be useful in any CLI application.

options - Hash containing already-set options.

Yields the OptionsParser object in use if a block is given.

Returns a Hash.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/cloudflock/app.rb', line 90

def parse_options(options = {})
  opts = OptionParser.new

  yield opts if block_given?

  opts.separator ''
  opts.separator 'Global Options:'

  opts.on('-c', '--config FILE', 'Specify configuration file') do |file|
    options[:config_file] = File.expand_path(file)
  end

  opts.on_tail('--version', 'Show Version Information') do
    puts "CloudFlock v#{CloudFlock::VERSION}"
    exit
  end

  opts.on_tail('-?', '--help', 'Show this Message') do
    puts opts
    exit
  end

  opts.parse!(ARGV)

  options
rescue OptionParser::MissingArgument, OptionParser::InvalidOption => error
  puts error.message.capitalize
  puts
  ARGV.clear
  ARGV.unshift('-?')
  retry
end