Class: Hoodoo::Generator

Inherits:
Object
  • Object
show all
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

Instance Method Details

#run!(args) ⇒ Object

Run the hoodoo command implementation.

args

Array of command line arguments, excluding the hoodoo command itself (so, just any extra arguments passed in).



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/hoodoo/generator.rb', line 43

def run!( args )
  return show_usage if args_empty?(args)

  name = args.first

  return show_usage if name == '-h' || name == '--help'

  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 }" )

  git = args[ 2 ] if args[ 1 ] == '--from'
  git ||= '[email protected]:LoyaltyNZ/service_shell.git'

  return create_service( name, git )
end