parrotcode: parse long and short command line options | |
Contents | Libraries |
library/Getopt/Long.imc - parse long and short command line options
# Assemble option specification
.local pmc opt_spec
opt_spec = new ResizableStringArray
push opt_spec, "bool"
push opt_spec, "string=s"
push opt_spec, "integer=i"
# the program name is the first element in argv
.local string program_name
program_name = shift argv
# Make a copy of argv, because this can easier be handled in get_options()
.local pmc argv_clone
argv_clone = clone argv
# Parse the command line params
.local pmc opt
( opt ) = _get_options( argv_clone, opt_spec )
.local int is_defined
is_defined = defined opt["bool"]
.local int integer
integer = opt["integer"]
.local string s
s = opt["string"]
This PIR library can be used for parsing command line options. A single subroutine, _get_options(), is provided.
This should work like the Perl5 module Getopt::Long. Takes an array of options and an array of specifications.
A Hash PMC is returned.
- Put the code into the namespace 'Getopt::Long'. - Remove need to clone argument vector - Make it work for all cases, short options, long options and bundling. - Recognise type of return value: string, integer, binary, array, hash. - Get started on error reporting. - Provide more options
Bernhard Schmalhofer - Bernhard.Schmalhofer@biomax.de
The Perl5 module Getopt::Long. examples/assembly/getopt_demo.imc
Copyright (C) 2003-2005 The Perl Foundation. All rights reserved. This program is free software. It is subject to the same license as The Parrot Interpreter.
|