Class: CmdLineOptParser
- Inherits:
-
Object
- Object
- CmdLineOptParser
- Defined in:
- lib/countloc.rb
Class Method Summary collapse
-
.parse(args) ⇒ Object
Return a structure describing the options.
- .usage ⇒ Object
Class Method Details
.parse(args) ⇒ Object
Return a structure describing the options
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/countloc.rb', line 426 def self.parse(args) # The options set on the command line will be collected in "options" # Setup the defaults here = {} [:recurse] = false [:quiet] = false [:mode] = :ruby [:defaultMode] = true [:csv] = false [:csvFilename] = 'countloc.csv' [:html] = false [:htmlFilename] = 'countloc.html' [:useUserFileTypes] = false begin OptionParser.new do |opts| opts. = usage opts.on('-r', '--recurse', 'Recurse into subdirectories') do [:recurse] = true end opts.on('-v', '--version', 'Display version number') do puts "#{File.basename($0)}, version: #{CountLOC::VERSION}" exit end opts.on('-q', '--quiet', "Don't write results to stdout") do [:quiet] = true end opts.on('-m', '--mode mode', [:ruby, :python, :c, :cpp, :csharp, :java, :vb], "Set the language mode.", "All languages are used by default", "if the mode option is omitted.", "Supported modes: ", " ruby, python,", " c, cpp, csharp,", " java, vb") do |mode| [:mode] = mode [:defaultMode] = false end opts.on('--csv csvFilename', 'Generate csv file') do |csvFilename| [:csvFilename] = csvFilename [:csv] = true end opts.on('--html htmlFilename', 'Generate html file') do |htmlFilename| [:htmlFilename] = htmlFilename [:html] = true end opts.on('--file-types fileTypes', "File types to be included.", "Default is dependant upon language mode:", " ruby: *.rb", " python: *.py", " c: *.h, *.c", " cpp: *.h, *.hpp, *.cpp, *.c, *.inl", " csharp: *.cs", " java: *.java", " vb: *.vb", "Defaults are overridden using this option.") do |fileTypes| [:fileTypes] = fileTypes.split() [:useUserFileTypes] = true end opts.on_tail('-h', '--help', 'Display this help and exit') do puts opts exit end end.parse!(args) rescue puts "Error: " + $!.to_s exit end end |
.usage ⇒ Object
419 420 421 |
# File 'lib/countloc.rb', line 419 def self.usage "Usage: #{File.basename($0)} [-h|--help] [options] <file> ... <file>" end |