Class: EhcCommandTasks

Inherits:
Object
  • Object
show all
Defined in:
lib/ehc_command_tasks.rb

Constant Summary collapse

COMMAND_WHITELIST =
%w(init generate server help)
HELP_MESSAGE =
<<-EOT
  Usage: ehc COMMAND [ARGS]

  The avalible commands are:
  init      Initialize 'dev_root' and 'web_root' with a demo website
  generate  Only generate output files  (short-cut alias: "g")
  server    Start the wserver (short-cut alias: "s")
  help      Shows this message

EOT

Instance Method Summary collapse

Constructor Details

#initializeEhcCommandTasks

Returns a new instance of EhcCommandTasks.



18
19
20
21
22
23
24
25
# File 'lib/ehc_command_tasks.rb', line 18

def initialize
  command = parse_command
  if COMMAND_WHITELIST.include?(command)
    send(command)
  else
    print_error(command)
  end
end

Instance Method Details

#generateObject



62
63
64
65
# File 'lib/ehc_command_tasks.rb', line 62

def generate
  require 'generator/generator'
  Generator::Generator.new.generate
end

#helpObject



49
50
51
# File 'lib/ehc_command_tasks.rb', line 49

def help
  puts HELP_MESSAGE
end

#initObject



53
54
55
56
57
58
59
60
# File 'lib/ehc_command_tasks.rb', line 53

def init
  puts "Creating dev_root and web_root with sample websites"

  init_dev_root
  init_web_root

  puts "All done, use \e[32m'ehc server'\e[0m to start the development server."
end

#parse_commandObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ehc_command_tasks.rb', line 27

def parse_command
  return "" if ARGV.empty?

  command =  ARGV.first

  if command == 'g'
    command = 'generate'
  elsif command == 's'
    command = 'server'
  end
  return command
end


40
41
42
43
44
45
46
47
# File 'lib/ehc_command_tasks.rb', line 40

def print_error(command)
  if command.empty?
    puts 'no command given'
  else
    puts "command '#{command}' not valid"
  end if
  help
end

#serverObject



67
68
69
70
# File 'lib/ehc_command_tasks.rb', line 67

def server
  $options = parse_server_options
  require 'easy_html_creator'
end