Class: CodeInventory::CLI::App

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

Instance Method Summary collapse

Instance Method Details

#combine(agency, *filenames) ⇒ Object



10
11
12
13
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/codeinventory/cli/combine.rb', line 10

def combine(agency, *filenames)
  if filenames.count == 0
    puts "You must provide at least one code.json file"
    exit 1
  end
  combined = {
    "version" => "2.0.0",
    "agency" => agency,
    "measurementType" => {
      "method" => "modules"
    },
    "releases" => []
  }
  filenames.each do |filename|
    if !File.exist? filename
      puts "File not found: #{filename}"
      exit 1
    end
    inventory = JSON.load(File.new(filename))
    projects = inventory["releases"]
    if options[:replace]
      projects.each do |project|
        project["organization"] = inventory["agency"] if !inventory["agency"].nil?
      end
    end
    combined["releases"].concat(projects)
  end
  if options["pretty"]
    puts JSON.pretty_generate(combined)
  else
    puts combined.to_json
  end
end

#csv(agency, filename) ⇒ Object



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

def csv(agency, 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)
  output = inventory.generate(agency, "2.0.0")
  puts JSON.pretty_generate(output)
end

#json(agency, filename) ⇒ Object



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

def json(agency, 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)
  output = inventory.generate(agency, "2.0.0")
  puts JSON.pretty_generate(output)
end

#versionObject



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

def version
  puts CodeInventory::VERSION
end