Class: GraphQL::Doctor::CLI
- Inherits:
-
Object
- Object
- GraphQL::Doctor::CLI
- Defined in:
- lib/graphql/doctor/cli.rb
Constant Summary collapse
- REPORTERS =
{ "text" => Reporters::Text, "json" => Reporters::Json, "sarif" => Reporters::Sarif, "github" => Reporters::Github }.freeze
- HELP =
<<~TEXT Usage: graphql-doctor COMMAND [options] [paths] Commands: check [paths] Check resolver contracts (default) dump-schema Dump runtime schema as JSON coverage Show source/runtime mapping coverage explain CODE Explain a diagnostic version Print the version TEXT
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv, out:, err:) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(argv, out:, err:) ⇒ CLI
Returns a new instance of CLI.
35 36 37 38 39 |
# File 'lib/graphql/doctor/cli.rb', line 35 def initialize(argv, out:, err:) @argv = argv.dup @out = out @err = err end |
Class Method Details
.start(argv = ARGV, out: $stdout, err: $stderr) ⇒ Object
31 32 33 |
# File 'lib/graphql/doctor/cli.rb', line 31 def self.start(argv = ARGV, out: $stdout, err: $stderr) new(argv, out: out, err: err).run end |
Instance Method Details
#run ⇒ Object
41 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 |
# File 'lib/graphql/doctor/cli.rb', line 41 def run if %w[help --help -h].include?(@argv.first) @out.puts(HELP) return 0 end @argv[0] = {"--version" => "version", "-v" => "version"}.fetch(@argv.first, @argv.first) command = @argv.first&.start_with?("-") ? "check" : (@argv.shift || "check") case command when "version" @out.puts(VERSION) 0 when "help", "--help", "-h" @out.puts(HELP) 0 when "check" then check when "dump-schema" dump_schema 0 when "coverage" coverage 0 when "explain" then explain else @err.puts("Command #{command.inspect} is not implemented yet") 2 end rescue Error, OptionParser::ParseError, SystemCallError => e @err.puts(e.) 2 end |