Class: Debendencies::CLI
- Inherits:
-
Object
- Object
- Debendencies::CLI
- Defined in:
- lib/debendencies/cli.rb
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
8 9 10 11 12 |
# File 'lib/debendencies/cli.rb', line 8 def initialize @options = { format: "oneline", } end |
Instance Method Details
#run ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/debendencies/cli.rb', line 14 def run option_parser.parse! require "json" if @options[:format] == "json" paths = ARGV if paths.empty? STDERR.puts option_parser exit 1 end debendencies = Debendencies.new(logger: get_logger) begin debendencies.scan(*paths) dependencies = debendencies.resolve rescue Error => e abort(e.) end case @options[:format] when "oneline" write_output(dependencies.map { |d| d.to_s }.join(", ")) when "multiline" write_output(dependencies.map { |d| d.to_s }.join("\n")) when "json" write_output(JSON.generate(dependencies.map { |d| d.as_json })) else abort "Invalid format: #{@options[:format]}" end end |