class Boilerpl8::MainApp

Constants

COMMAND_OPTIONS

Public Class Methods

main() click to toggle source
# File lib/boilerpl8.rb, line 214
def self.main
  begin
    self.new.run(*ARGV)
    exit 0
  rescue CommandOptionError => ex
    $stderr.puts ex.message
    exit 1
  end
end
new(script_name=nil) click to toggle source
# File lib/boilerpl8.rb, line 224
def initialize(script_name=nil)
  @script_name = script_name || File.basename($0)
end

Public Instance Methods

help_message() click to toggle source
# File lib/boilerpl8.rb, line 253
    def help_message
      script = @script_name
      buf = <<"END"
#{script} -- download boilerplate files

Usage:
  #{script} [options] github:<USER>/<REPO> <DIR>
  #{script} [options] file:<PATH> <DIR>

Options:
END
      COMMAND_OPTIONS.each {|s| buf << "  #{s}\n" }
      buf << <<"END"

Examples:

  ## download boilerplate files from github
  $ #{script} github:kwatch/hello-ruby mygem1             # for ruby
  $ #{script} github:kwatch/hello-python mypkg1           # for python
  $ #{script} github:kwatch/keight-ruby myapp1            # for keight.rb

  ## '-B' option doesn't append '-boilerpl8' to github repo name
  $ #{script} -B github:h5bp/html5-boilerplate website1   # for html5

  ## expand boilerplate files
  $ #{script} file:./keight-ruby.tar.gz myapp1

END
    end
run(*args) click to toggle source
# File lib/boilerpl8.rb, line 228
def run(*args)
  parser = CommandOptionParser.new(COMMAND_OPTIONS)
  options = parser.parse(args)
  #
  if options['help']
    puts help_message()
    return 0
  end
  #
  if options['version']
    puts RELEASE
    return 0
  end
  #
  boilerplate_name = args[0]  # ex: "github:kwatch/hello-ruby"
  target_dir       = args[1]  # ex: "mygem1"
  #; [!eqisx] reports error when boilerplate name or target dir is not specified.
  boilerplate_name  or raise err("#{@script_name}: argument required.")
  target_dir        or raise err("#{@script_name}: target directory name required.")
  #
  op = Operation.create(boilerplate_name)
  op.do_everything(boilerplate_name, target_dir, options)
  return 0
end

Private Instance Methods

err(msg) click to toggle source
# File lib/boilerpl8.rb, line 285
def err(msg)
  raise CommandOptionError.new(msg)
end