Module: Montage::Commands

Extended by:
Commands
Included in:
Commands, Generate, Init
Defined in:
lib/montage/commands.rb,
lib/montage/commands/init.rb,
lib/montage/commands/generate.rb

Defined Under Namespace

Classes: Generate, Init

Constant Summary collapse

BLANK =

A blank line; HighLine doesn’t allow calling say without an argument.

"\n".freeze

Instance Method Summary collapse

Instance Method Details

#configHash

Returns a configuration hash, containing options defined on the command-line.

Returns:

  • (Hash)


13
14
15
# File 'lib/montage/commands.rb', line 13

def config
  @config ||= { :force => false, :quiet => false }
end

#exit(status = 0) ⇒ Object

Exits immediately, outputting a blank line first.



59
60
61
62
# File 'lib/montage/commands.rb', line 59

def exit(status = 0)
  say BLANK
  Kernel.exit(status)
end

#parse_options!(argv) ⇒ Object

Uses OptParse to parse command-line arguments.

Returns any unparsed command-line arguments.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/montage/commands.rb', line 21

def parse_options!(argv)
  HighLine.use_color = false if !STDOUT.tty? && !ENV.has_key?("AUTOTEST")

  OptionParser.new do |opts|
    opts.banner = "Usage: montage [config file path] [options]"

    opts.on('-c', '--[no-]color', '--[no-]colour',
            'Enables and disables colour output.') do |color|
      HighLine.use_color = color
    end

    opts.on('-f', '--force',
            'Regenerate sprites even if no changes have been made.') do
      Montage::Commands.config[:force] = true
    end

    # opts.on('-q', '--quiet',
    #         'Tell Montage to shut up. No messages sent to STDOUT.') do
    #   Montage::Commands.config[:quiet] = true
    # end

    opts.on_tail("-h", "--help", "Shows this message.") do
      say BLANK
      say opts.to_s
      exit
    end

    opts.on_tail("--version", "Print the current Montage version.") do
      say BLANK
      say "Montage v#{Montage::VERSION}"
      exit
    end
  end.parse!(argv)

  argv
end