Class: JsonLint::CLI
- Inherits:
-
Object
- Object
- JsonLint::CLI
- Defined in:
- lib/jsonlint/cli.rb
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ CLI
constructor
A new instance of CLI.
Constructor Details
#initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = Kernel) ⇒ CLI
Returns a new instance of CLI.
5 6 7 |
# 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 |
Instance Method Details
#execute! ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jsonlint/cli.rb', line 9 def execute! files_to_check = @argv Trollop::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. exit(1) rescue => e @stderr.puts e. exit(1) end return unless linter.errors? linter.display_errors @kernel.exit(1) end |