Module: Logi::Runner

Defined in:
lib/logi/runner.rb

Class Method Summary collapse

Class Method Details

.helpObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/logi/runner.rb', line 70

def help
  require 'logi/config'
  require 'logi/logger'
  optt = options.transpose
  maxn = optt.first.map(&:size).max
  maxd = [optt.last .map(&:size).max, `tput cols`.to_i - maxn - 4].min
  "Usage: logi [OPTIONS] [PATH to logi root]\n" +
  options.map{ |(name, desc)|
    if name.end_with?(':')
      name
    else
      sprintf("  %-*s  %-*s", maxn, name, maxd, desc)
    end
  }.join("\n")
end

.optionsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/logi/runner.rb', line 5

def options
  @options ||=
  [['logi options:'    , ''                       ],
   ['-c, --color'      , '   Color mode (default)'],
   ['-n, --no-color'   , 'No color mode'          ],
   ['-V, --verbose'    , ' Verbose mode (default)'],
   ['-q, --quiet'      , '   Quiet mode'          ],
   ['-h, --help'       , 'Print this message'     ],
   ['-v, --version'    , 'Print the version'      ],
   ['defaults:'        , ''                       ],
   ['  root directory' , Logi::Config.  default_root_path],
   ['  post directory' , Logi::Config.  default_post_path],
   ['layout directory' , Logi::Config.default_layout_path],
   ['output directory' , Logi::Config.default_output_path],
   ['    post command' , Logi::Config.default_command    ],
   ['     layout file' , Logi::Logger.strip_path(
                           Logi::Config.default_layout)  ]]
end

.parse(argv) ⇒ Object



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
57
58
59
60
61
62
63
64
# File 'lib/logi/runner.rb', line 30

def parse argv
  options = {}
  until argv.empty?
    case arg = argv.shift
    when /^-c/, '--color'
      options[:nocolor] = false
      parse_next(argv, arg)

    when /^-n/, '--no-color'
      options[:nocolor] = true
      parse_next(argv, arg)

    when /^-V/, '--verbose'
      options[:quiet] = false
      parse_next(argv, arg)

    when /^-q/, '--quiet'
      options[:quiet] = true
      parse_next(argv, arg)

    when /^-h/, '--help'
      puts(help)
      exit

    when /^-v/, '--version'
      require 'rib/version'
      puts(Rib::VERSION)
      exit

    else
      options[:root] = File.expand_path(arg)
    end
  end
  options
end

.parse_next(argv, arg) ⇒ Object



66
67
68
# File 'lib/logi/runner.rb', line 66

def parse_next argv, arg
  argv.unshift("-#{arg[2..-1]}") if arg.size > 2
end

.run(argv = ARGV) ⇒ Object



24
25
26
27
28
# File 'lib/logi/runner.rb', line 24

def run argv=ARGV
  options = parse(argv)
  require 'logi' # lazily load logi since we might exit earlier
  Logi.new(options).make
end