Method: Terraspace::Command.dispatch

Defined in:
lib/terraspace/command.rb

.dispatch(m, args, options, config) ⇒ Object



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
71
72
73
74
75
76
77
# File 'lib/terraspace/command.rb', line 42

def dispatch(m, args, options, config)
  # Terraspace.argv provides consistency when terraspace is being called by rspec-terraspace test harness
  Terraspace.argv = args.clone # important to clone since Thor removes the first argv

  unless @@initial_dispatch_command
    @@initial_dispatch_command = "$ terraspace #{args.join(' ')}\n"
    Terraspace::Logger.buffer << @@initial_dispatch_command
  end

  check_standalone_install!
  check_project!(args.first)

  # Allow calling for help via:
  #   terraspace command help
  #   terraspace command -h
  #   terraspace command --help
  #   terraspace command -D
  #
  # as well thor's normal way:
  #
  #   terraspace help command
  if args.length > 1 && !(args & help_flags).empty?
    args -= help_flags
    args.insert(-2, "help")
  end

  #   terraspace version
  #   terraspace --version
  #   terraspace -v
  version_flags = ["--version", "-v"]
  if args.length == 1 && !(args & version_flags).empty?
    args = ["version"]
  end

  super
end