Module: Wokku::CLI

Defined in:
lib/wokku.rb

Constant Summary collapse

COMMANDS =
Wokku::Registry::COMMANDS

Class Method Summary collapse

Class Method Details

.dispatch(args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/wokku.rb', line 33

def dispatch(args)
  sep = args.index("--")
  head = sep ? args[0...sep] : args.dup
  tail = sep ? args[sep..] : []
  Wokku.json  = !!head.delete("--json")
  Wokku.quiet = !!(head.delete("--quiet") || head.delete("-q"))
  ARGV.replace(head + tail)
  command = ARGV.shift

  if command.nil? || command == "help" || command == "--help" || command == "-h"
    show_help
    return 0
  elsif COMMANDS[command]
    COMMANDS[command][:handler].call
    return 0
  else
    puts "Unknown command: #{command}"
    puts "Run 'wokku help' for available commands."
    return 1
  end
end

.show_helpObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/wokku.rb', line 55

def show_help
  puts "Wokku CLI v#{Wokku::VERSION}"
  puts "Usage: wokku COMMAND [args] [--json] [--quiet]"
  puts
  puts "Commands:"
  COMMANDS.sort_by { |k, _| k }.each do |name, cmd|
    puts "  %-20s %s" % [name, cmd[:desc]]
  end
  puts
  puts "Global flags:"
  puts "  --json    Machine-readable JSON output (read commands only)"
  puts "  --quiet   Suppress success messages and hints (alias: -q)"
  puts
  puts "Run 'wokku auth:login' to get started."
end