-
-
Save nkpart/1985 to your computer and use it in GitHub Desktop.
undefined
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PedAssignOptions < Struct.new(:links_file, :access_file, :walk_int_file, :output_file); end | |
class ParseFail < Struct.new(:reason); end | |
class ArgvParser | |
def parse argv | |
if argv.size == 1 and ['-h','--help'].include? argv.first then | |
return :help | |
end | |
if argv.length != PedAssignOptions.members.size then | |
return ParseFail.new("Incorrect number of arguments, got #{argv.size} expected #{PedAssignOptions.members.size}") | |
end | |
missing_files = get_missing_files(argv[0..-2]) | |
if !missing_files.empty? then | |
return ParseFail.new("Could not find files: #{missing_files.join(',')}") | |
end | |
return parse_it(argv) | |
end | |
private | |
def parse_it argv | |
return PedAssignOptions.new(*argv) | |
end | |
def get_missing_files files | |
files.select { |f| !File.exist?(f) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment