Class: LibyearRb::CLI

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

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
# File 'lib/libyear_rb/cli.rb', line 9

def initialize(argv = ARGV)
  @argv = argv.dup
  @options = {
    formatter: Formatter.for("plaintext"),
    indirect: true,
    sorters: Sorter.parse(Sorter::DEFAULT_SPEC)
  }
  parse_options!
end

Instance Method Details

#runObject



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

def run
  LibyearRb.logger = Logger.new($stderr) if @options[:verbose]

  lockfile_contents = read_lockfile
  results = Runner.new.run(lockfile_contents, as_of: @options[:as_of])
  sorted_results = Sorter.sort(results, @options.fetch(:sorters))

  @options.fetch(:formatter).new(indirect: @options.fetch(:indirect)).generate(sorted_results)
end