Module: Enzyme

Extended by:
Enzyme
Included in:
Enzyme
Defined in:
lib/enzyme.rb

Constant Summary collapse

@@commands =
{}

Instance Method Summary collapse

Instance Method Details

#error(error) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/enzyme.rb', line 72

def error(error)
  if $trace_errors && error.is_a?(StandardError)
    raise error
  else
    puts 'ERROR'
    puts '-----'
    puts ''
    puts '> '+error
    puts ''
  end
end

#helpObject



36
37
38
39
40
41
42
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
# File 'lib/enzyme.rb', line 36

def help
  ARGV.reject { |x| x.start_with?("-") }
  command = ARGV.shift

  info

  if command
    if @@commands.include?(command.to_s.downcase)
      @@commands[command.to_s.downcase][:help].call
    else
      error("No help available for `#{name}`.")
    end
  else
    puts 'USAGE'
    puts '-----'
    puts ''
    puts '### Commands'
    puts ''
    puts '    enzyme config [<key> [<value> [--global]]]'
    puts '    enzyme create <project_name> [pms | koi]'
    # puts '    enzyme join <project_name>'
    puts '    enzyme sync [<project_name>]'
    puts ''
    puts '### Help'
    puts ''
    puts '    enzyme help [<command>]'
    puts '    enzyme [<command>] --help'
    puts '    enzyme [<command>] -h'
    puts ''
    puts '### Debugging'
    puts ''
    puts 'Use `--trace` at anytime to get full stacktraces.'
    puts ''
  end
end

#infoObject



26
27
28
29
30
31
32
33
34
# File 'lib/enzyme.rb', line 26

def info
  puts 'ENZYME'
  puts '======'
  puts ''
  puts 'Katalyst\'s project collaboration tool.'
  puts ''
  puts 'Version: '+$version
  puts ''
end

#register(command_class, &block) ⇒ Object



84
85
86
# File 'lib/enzyme.rb', line 84

def register(command_class, &block)
  @@commands[command_class.to_s.downcase] = { :class => command_class, :help => block }
end

#runObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/enzyme.rb', line 5

def run
  # Only shift the first argument off the ARGV if help flags haven't been passed.
  command = (ARGV.delete("-h") || ARGV.delete("--help")) ? 'help' : (ARGV.shift || 'help')

  # Show info, help or run the requested command if it has been registered.
  begin
    if command.eql?('help')
      help
    else
      if @@commands.include?(command.to_s.downcase)
        @@commands[command.to_s.downcase][:class].run()
      else
        error("Unable to find command `#{command}`.")
        help
      end
    end
  rescue StandardError => e
    error(e)
  end
end