Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/coverage/inject/cli.cr
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
require "option_parser"

# require "tempfile"

module Coverage
module CLI
def self.run
output_format = "HtmlReport"
filenames = [] of String
targets = [] of String
print_only = false

OptionParser.parse! do |parser|
parser.banner = "Usage: crystal-cover [options] <filename>"
parser.banner = "Usage: crystal-coverage [options] <directories or filenames>"
parser.on("-h", "--help", "show this help") { puts parser; exit }
parser.on("-o FORMAT", "--output-format=FORMAT", "The output format used (default: HtmlReport): HtmlReport, Coveralls ") { |f| output_format = f }
parser.on("-p", "--print-only", "output the generated source code") { |_p| print_only = true }
parser.on("--use-require=REQUIRE", "change the require of cover library in runtime") { |r| Coverage::SourceFile.use_require = r }
parser.unknown_args do |args|
args.each do
filenames << ARGV.shift
targets << ARGV.shift
end
end
end

raise "You must choose a file to compile" unless filenames.any?
raise "You must choose at least one file to compile" unless targets.any?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anykeyh Maybe just printing this phrase is enough. Do you think it really have to be an Exception?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might use the new Log module to raise an Error message and exit the application instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea! I'll update it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anykeyh what do you think?


Coverage::SourceFile.outputter = "Coverage::Outputter::#{output_format.camelcase}"

filenames = targets.map do |target|
target += "/**/*.cr" if File.directory?(target)
Dir[target]
end.flatten.uniq

first = true
output = String::Builder.new(capacity: 2**18)

filenames.each do |f|
v = Coverage::SourceFile.new(path: f, source: ::File.read(f))
output << v.to_covered_source
Expand Down