Class: Audition::CLI

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

Constant Summary collapse

USAGE =
"usage: audition [options] TARGET " \
"(a .rb script, directory, config.ru dir, Rails root, " \
"gem dir, or installed gem name)"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout:, stderr:) ⇒ CLI

Returns a new instance of CLI.



23
24
25
26
# File 'lib/audition/cli.rb', line 23

def initialize(stdout:, stderr:)
  @stdout = stdout
  @stderr = stderr
end

Class Method Details

.run(argv, stdout: $stdout, stderr: $stderr) ⇒ Integer

Entry point used by exe/audition.

Parameters:

  • argv (Array<String>)

    command line arguments

  • stdout (IO) (defaults to: $stdout)
  • stderr (IO) (defaults to: $stderr)

Returns:

  • (Integer)

    exit code: 0 clean, 1 findings at or above the --fail-on threshold, 2 usage error



19
20
21
# File 'lib/audition/cli.rb', line 19

def self.run(argv, stdout: $stdout, stderr: $stderr)
  new(stdout: stdout, stderr: stderr).run(argv)
end

Instance Method Details

#run(argv) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/audition/cli.rb', line 28

def run(argv)
  options = parse(argv.dup)
  return options if options.is_a?(Integer)

  return print_capabilities(options) if options[:capabilities]

  target_arg = options[:args].first
  unless target_arg
    @stderr.puts(USAGE)
    return 2
  end

  target = Target.detect(target_arg)
  target = deps_target(target) if options[:deps]
  if target.type == :bundle
    sweep(target, options)
  else
    audit(target, options)
  end
rescue Error => e
  @stderr.puts("audition: #{e.message}")
  2
end