Skip to content

Instantly share code, notes, and snippets.

@nkpart
Forked from benhoskings/gist:1974
Created July 24, 2008 01:23
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nkpart/1985 to your computer and use it in GitHub Desktop.
undefined
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