Module: Logi::Runner

Defined in:
lib/logi/runner.rb

Class Method Summary collapse

Class Method Details

.helpObject



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

def help
  require 'logi/default'
  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
23
24
# 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::Default.  default_root_path],
   ['  post directory' , Logi::Default.  default_post_path],
   ['layout directory' , Logi::Default.default_layout_path],
   ['output directory' , Logi::Default.default_output_path],
   ['    post command' , Logi::Default.default_command    ],
   ['     layout file' , Logi::Logger.strip_path(
                           Logi::Default.default_layout)  ],
   ['    example site' , Logi::Logger.strip_path(
                           Logi::Default.example_directory)]]
end

.parse(argv) ⇒ Object



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
65
66
# File 'lib/logi/runner.rb', line 32

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

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

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

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

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

    when /^-v/, '--version'
      require 'logi/version'
      puts(Logi::VERSION)
      exit

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

.parse_next(argv, arg) ⇒ Object



68
69
70
# File 'lib/logi/runner.rb', line 68

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

.run(argv = ARGV) ⇒ Object



26
27
28
29
30
# File 'lib/logi/runner.rb', line 26

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