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
82
83
84
85
|
# File 'lib/rbcat/cli.rb', line 42
def self.parse_options(args)
options = {}
args.push("-h") if args.empty?
OptionParser.new do |opts|
opts.banner = <<~HEREDOC
Rbcat it's a CLI tool which reads from standard input (STDIN),
colorizes content by set of regex rules from a config file,
and then writes it to standard output.
HEREDOC
opts.separator ""
predefined_desc = "Colorize input by set of predefined rules. " \
"Currently there are json/hash 'jsonhash' and ruby's logger 'logger'. " \
"Example: --predefined=jsonhash,logger"
opts.on("-p", "--predefined GROUPS", Array, predefined_desc) do |arg|
options[:predefined] = arg
end
rules_desc = "Path to the custom yaml config for rbcat."
opts.on("-r", "--rules PATH", rules_desc) do |arg|
options[:rules] = arg
end
order_desc = "Specify order for predefined and custom rules." \
"Avaiable options: 'predefined_first' (default) or 'predefined_last'."
opts.on("-o", "--order ORDER", order_desc) do |arg|
options[:order] = arg
end
opts.on("-c", "--print_colors", "Print all avaiable colors.") do
Rbcat::Colorizer.print_colors
exit
end
opts.on_tail("-v", "--version", "Show version") do
puts Rbcat::VERSION
exit
end
end.parse!(args)
options
end
|