Class: Pedant::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/pedant/cli.rb

Constant Summary collapse

@@optparse =
nil

Class Method Summary collapse

Class Method Details

.runObject



33
34
35
36
37
38
39
40
41
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
78
79
80
81
# File 'lib/pedant/cli.rb', line 33

def self.run
  options = {
    input_mode: :filesystem,
    output_mode: :terminal,
    verbosity: 0
  }

  Command.initialize!

  @@optparse = OptionParser.new do |opts|
    opts.banner = "Usage: pedant [global-options] [command [command-options] [args]]"

    opts.separator ""
    opts.separator "Global settings:"

    opts.on('-v', '--verbose', 'Output more information, use multiple time to increase verbosity.') do
      options[:verbosity] += 1
    end

    opts.separator ""
    opts.separator "Common operations:"

    opts.on('-h', '--help', 'Display this help screen.') do
      puts opts
      exit 1
    end

    opts.on('-l', '--list', 'Display the list of available commands.') do
      puts Command.list
      exit 1
    end

    opts.on('-V', '--version', 'Display the version of Pedant.') do
      puts "#{Pedant::VERSION}"
      exit
    end
  end

  @@optparse.order!

  # Sanity check the command.
  usage("No command was specified.") if ARGV.empty?
  cmd = ARGV.shift
  cls = Command.find(cmd)
  usage("Command '#{cmd}' not supported.") if cls.nil?

  # Run the command.
  cls.run(options, ARGV)
end

.usage(msg) ⇒ Object



83
84
85
86
87
88
# File 'lib/pedant/cli.rb', line 83

def self.usage(msg)
  puts Rainbow(msg).color(:red)
  puts
  puts @@optparse
  exit 1
end