Class: Hoodoo::Generator
- Inherits:
-
Object
- Object
- Hoodoo::Generator
- Includes:
- Singleton
- Defined in:
- lib/hoodoo/generator.rb
Overview
Implement the hoodoo
command line interface.
Constant Summary collapse
- 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.
true
- 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.
false
- NAME_REGEX =
Regular expression describing allowed names of services (A-Z, a-z, 0-9, underscore or hyphen; between 2 and 30 characters).
/^[a-zA-Z01-9_-]{2,30}$/
Instance Method Summary collapse
-
#run! ⇒ Object
Run the
hoodoo
command implementation.
Instance Method Details
#run! ⇒ Object
Run the hoodoo
command implementation. Command line options are taken from the Ruby ARGV constant.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# 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. ) end end unless path.nil? || git.nil? return usage_and_warning( 'Use the --path OR --from arguments, but not both' ) end git ||= '[email protected]: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 |