Module: Logi::Runner
- Defined in:
- lib/logi/runner.rb
Class Method Summary collapse
- .help ⇒ Object
- .options ⇒ Object
- .parse(argv) ⇒ Object
- .parse_next(argv, arg) ⇒ Object
- .run(argv = ARGV) ⇒ Object
Class Method Details
.help ⇒ Object
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 = .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" + .map{ |(name, desc)| if name.end_with?(':') name else sprintf(" %-*s %-*s", maxn, name, maxd, desc) end }.join("\n") end |
.options ⇒ Object
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 ||= [['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 = {} until argv.empty? case arg = argv.shift when /^-c/, '--color' [:nocolor] = false parse_next(argv, arg) when /^-n/, '--no-color' [:nocolor] = true parse_next(argv, arg) when /^-V/, '--verbose' [:quiet] = false parse_next(argv, arg) when /^-q/, '--quiet' [:quiet] = true parse_next(argv, arg) when /^-h/, '--help' puts(help) exit when /^-v/, '--version' require 'rib/version' puts(Rib::VERSION) exit else [:root] = File.(arg) end end 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 |