Implement the hoodoo command line interface.

Methods
R
Included Modules
Constants
KERNEL_EXIT_SUCCESS =
true
 

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.

KERNEL_EXIT_FAILURE =
false
 

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.

NAME_REGEX =
/^[a-zA-Z01-9_-]{2,30}$/
 

Regular expression describing allowed names of services (A-Z, a-z, 0-9, underscore or hyphen; between 2 and 30 characters).

Instance Public methods
run!()

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