Class: Yamlint::Cli

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV) ⇒ Cli

Returns a new instance of Cli.



9
10
11
12
13
14
15
16
17
18
# File 'lib/yamlint/cli.rb', line 9

def initialize(argv = ARGV)
  @argv = argv
  @options = {
    config: nil,
    format: 'colored',
    fix: false,
    dry_run: false,
    strict: false
  }
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/yamlint/cli.rb', line 7

def options
  @options
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/yamlint/cli.rb', line 20

def run
  parse_options
  command = @argv.shift || 'lint'

  case command
  when 'lint', 'l'
    run_lint
  when 'format', 'fmt', 'fix'
    run_format
  when 'version', '-v', '--version'
    puts "yamlint #{VERSION}"
    0
  when 'help', '-h', '--help'
    puts help_text
    0
  else
    if File.exist?(command) || File.directory?(command)
      @argv.unshift(command)
      run_lint
    else
      warn "Unknown command: #{command}"
      warn help_text
      1
    end
  end
end