Class: Doubleshot::CLI

Inherits:
Object show all
Defined in:
lib/doubleshot/cli.rb,
lib/doubleshot/cli/options.rb

Defined Under Namespace

Modules: Commands Classes: Options

Constant Summary collapse

USAGE =
<<-EOS.margin
Usage: doubleshot COMMAND [ OPTIONS ]

Summary: Command line tool for creating and managing doubleshot projects.

EOS

Class Method Summary collapse

Class Method Details

.commandsObject



14
15
16
# File 'lib/doubleshot/cli.rb', line 14

def self.commands
  @commands ||= []
end

.detect(command_name) ⇒ Object



62
63
64
# File 'lib/doubleshot/cli.rb', line 62

def self.detect(command_name)
  commands.detect { |command| command.task_name == command_name }
end

.inherited(target) ⇒ Object



18
19
20
# File 'lib/doubleshot/cli.rb', line 18

def self.inherited(target)
  commands << target
end

.optionsObject

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/doubleshot/cli.rb', line 30

def self.options
  raise NotImplementedError.new
end

.startObject

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/doubleshot/cli.rb', line 34

def self.start(args)
  raise NotImplementedError.new
end

.summaryObject

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/doubleshot/cli.rb', line 26

def self.summary
  raise NotImplementedError.new
end

.task_nameObject



22
23
24
# File 'lib/doubleshot/cli.rb', line 22

def self.task_name
  name.split("::").last.underscore
end

.usage(command_name = "") ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/doubleshot/cli.rb', line 45

def self.usage(command_name = "")
  if command_name.blank?
    puts USAGE

    commands.each do |command|
      puts("\n  doubleshot %-8s # %s" % [ command.task_name, command.summary.gsub("\n", "\n" + (" " * 22) + "# ") ])
    end
  elsif command = detect(command_name)
    puts command.options
  else
    puts "\nERROR! COMMAND NOT FOUND: #{command_name}\n\n"
    usage
    exit 1
  end
  exit 0
end