class JsonLint::CLI
Public Class Methods
new(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel)
click to toggle source
# File lib/jsonlint/cli.rb, line 5 def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel end
Public Instance Methods
execute!()
click to toggle source
# File lib/jsonlint/cli.rb, line 9 def execute! parse_options files_to_check = @argv Optimist::die 'need at least one JSON file to check' if files_to_check.empty? linter = JsonLint::Linter.new begin if files_to_check == ['-'] linter.check_stream(STDIN) else linter.check_all(files_to_check) end rescue JsonLint::FileNotFoundError => e @stderr.puts e.message exit(1) rescue => e @stderr.puts e.message exit(1) end return unless linter.errors? linter.display_errors @kernel.exit(1) end
Private Instance Methods
parse_options()
click to toggle source
# File lib/jsonlint/cli.rb, line 38 def parse_options @opts = Optimist.options(@argv) do banner 'Usage: jsonlint [options] file1.json [file2.json ...]' version(JsonLint::VERSION) banner '' banner 'Options:' end end