Class: CodeInventory::CLI::App

Inherits:
Thor
  • Object
show all
Defined in:
lib/codeinventory/cli.rb,
lib/codeinventory/cli/csv.rb,
lib/codeinventory/cli/json.rb

Instance Method Summary collapse

Instance Method Details

#csv(filename) ⇒ Object



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

def csv(filename)
  file = Pathname.new(filename)
  unless File.exist? file
    puts "No such file: #{file}"
    exit 1
  end
  source = CodeInventory::CSVFile.new(file)
  inventory = CodeInventory::Inventory.new(source)
  projects = inventory.projects
  puts JSON.pretty_generate(projects)
end

#json(filename) ⇒ Object



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

def json(filename)
  file = Pathname.new(filename)
  unless File.exist? file
    puts "No such file: #{file}"
    exit 1
  end
  source = CodeInventory::JSONFile.new(file)
  inventory = CodeInventory::Inventory.new(source)
  projects = inventory.projects
  puts JSON.pretty_generate(projects)
end