Module: Lkml::CLI
- Defined in:
- lib/lkml/cli.rb
Class Method Summary collapse
Class Method Details
.parse_args(argv) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/lkml/cli.rb', line 13 def parse_args(argv) = { log_level: Logger::WARN } parser = OptionParser.new do |opts| opts. = "usage: lkml [-v|--verbose] FILE" opts.on("-v", "--verbose", "Increase logging verbosity to debug") do [:log_level] = Logger::DEBUG end end parser.parse!(argv) raise OptionParser::MissingArgument, "FILE is required" if argv.empty? [:file_path] = argv[0] end |
.run(argv = ARGV) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lkml/cli.rb', line 30 def run(argv = ARGV) logger = Logger.new($stderr) logger.level = Logger::WARN opts = parse_args(argv.dup) logger.level = opts[:log_level] File.open(opts[:file_path], "r:UTF-8") do |file| result = Lkml.load(file) puts JSON.pretty_generate(result) end end |