Module: Brite::Command

Extended by:
Command
Included in:
Command
Defined in:
lib/brite/command.rb

Overview

Brite command module.

Instance Method Summary collapse

Instance Method Details

#call(*argv) ⇒ Object

Execute command.



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

def call(*argv)
  options = parse(argv)

  begin
    controller(options).build
  rescue => e
    $DEBUG ? raise(e) : puts(e.message)
  end
end

#controller(options) ⇒ Controller

Create an instance of Brite::Controller given controller options.

Returns:



33
34
35
# File 'lib/brite/command.rb', line 33

def controller(options)
  Controller.new(options)
end

#options_general(parser, options) ⇒ Object

Add ‘–trace`, `–dryrun`, `–force`, `–debug` and `–warn` options to command line interface. These are all “global” options which means they set global variables if used.

Parameters:

  • parser (OptionParser)

    An instance of option parser.

  • options (Hash)

    An options hash to be passed to Controller.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/brite/command.rb', line 87

def options_general(parser, options)
  parser.on("--trace", "show extra operational information") do
    $TRACE = true
  end

  parser.on("--dryrun", "-n", "don't actually write to disk") do
    $DRYRUN = true
  end

  parser.on("--force", "force overwrites") do
    $FORCE = true
  end

  parser.on("--debug", "run in debug mode") do
    $DEBUG   = true
  end

  parser.on("--warn", "show Ruby warnings") do
    $VERBOSE = true
  end
end

#options_help(parser, options) ⇒ Object

Add ‘–help` option to command line parser.

Parameters:

  • parser (OptionParser)

    An instance of option parser.

  • options (Hash)

    An options hash to be passed to Controller.



118
119
120
121
122
123
# File 'lib/brite/command.rb', line 118

def options_help(parser, options)
  parser.on_tail("--help", "display this help message") do
    puts opt
    exit
  end
end

#options_url(parser, options) ⇒ Object

Add ‘–url` option to command line parser.

Parameters:

  • parser (OptionParser)

    An instance of option parser.

  • options (Hash)

    An options hash to be passed to Controller.



70
71
72
73
74
# File 'lib/brite/command.rb', line 70

def options_url(parser, options)
  parser.on("--url URL", "website fully qualified URL") do |url|
    options[:url] = url
  end
end

#parse(argv) ⇒ Hash

Parse controller options from command line arguments.

Returns:

  • (Hash)

    controller options



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/brite/command.rb', line 42

def parse(argv)
  parser = OptionParser.new

  options = {
    :output => nil,
    :url    => nil
  }

  options_url     parser, options
  options_general parser, options
  options_help    parser, options

  parser.parse!(argv)

  options[:location] = argv.shift || '.'

  options
end