class Hoodoo::Generator
Implement the hoodoo
command line interface.
Constants
- KERNEL_EXIT_FAILURE
Kernel::exit takes a boolean but defines no constants to describe what it means; very bad form. This constant equates to the ‘failed’ boolean value.
- KERNEL_EXIT_SUCCESS
Kernel::exit takes a boolean but defines no constants to describe what it means; very bad form. This constant equates to the ‘success’ boolean value.
- NAME_REGEX
Regular expression describing allowed names of services (A-Z, a-z, 0-9, underscore or hyphen; between 2 and 30 characters).
Public Instance Methods
run!()
click to toggle source
Run the hoodoo
command implementation. Command line options are taken from the Ruby ARGV constant.
# File lib/hoodoo/generator.rb, line 43 def run! git = nil path = nil return show_usage() if ARGV.length < 1 name = ARGV.shift() if ARGV.first[ 0 ] != '-' opts = GetoptLong.new( [ '--help', '-h', GetoptLong::NO_ARGUMENT ], [ '--version', '-v', '-V', GetoptLong::NO_ARGUMENT ], [ '--path', '-p', GetoptLong::REQUIRED_ARGUMENT ], [ '--from', '-f', GetoptLong::REQUIRED_ARGUMENT ], [ '--git', '-g', GetoptLong::REQUIRED_ARGUMENT ], ) silence_stream( $stderr ) do begin opts.each do | opt, arg | case opt when '--help' return show_usage() when '--version' return show_version() when '--path' path = arg when '--from', '--git' git = arg end end rescue GetoptLong::InvalidOption, GetoptLong::MissingArgument => e return usage_and_warning( e.message ) end end unless path.nil? || git.nil? return usage_and_warning( 'Use the --path OR --from arguments, but not both' ) end git ||= 'git@github.com:LoyaltyNZ/service_shell.git' name = ARGV.shift() if name.nil? return show_usage() if name.nil? return usage_and_warning( "Unexpected extra arguments were given" ) if ARGV.count > 0 return usage_and_warning( "SERVICE_NAME must match #{ NAME_REGEX.inspect }" ) if naughty_name?( name ) return usage_and_warning( "'#{ name }' already exists" ) if File.exist?( "./#{ name }" ) return create_service( name, git, path ) end