Class: RuboCop::Schema::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/schema/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(working_dir: Dir.pwd, env: ENV, args: ARGV, home: Dir.home, out_file: nil, log_file: $stderr) ⇒ CLI

Returns a new instance of CLI.

Parameters:

  • working_dir (Pathname) (defaults to: Dir.pwd)
  • env (Hash) (defaults to: ENV)
  • args (Array<String>) (defaults to: ARGV)
  • home (String) (defaults to: Dir.home)
  • out_file (IO) (defaults to: nil)
  • log_file (IO) (defaults to: $stderr)

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
# File 'lib/rubocop/schema/cli.rb', line 19

def initialize(working_dir: Dir.pwd, env: ENV, args: ARGV, home: Dir.home, out_file: nil, log_file: $stderr)
  @working_dir = Pathname(working_dir)
  @home_dir    = Pathname(home)
  @env         = env
  @args        = args
  @out_file    = out_file
  @log_file    = log_file

  raise ArgumentError, 'Cannot accept an out_file and an argument' if @out_file && args.first
end

Instance Method Details

#runObject



30
31
32
33
34
35
36
37
38
# File 'lib/rubocop/schema/cli.rb', line 30

def run
  read_flag while @args.first&.start_with?('--')
  assign_outfile

  print "Generating #{@out_path}" if @out_path

  schema = report_duration(lowercase: @out_path) { Generator.new(spec.specs, document_loader).schema }
  @out_file.puts JSON.pretty_generate schema
end