parrotcode: parse long and short command line options | |
Contents | Libraries |
library/Getopt/Long.pir - parse long and short command line options
# get the relevant sub
load_bytecode "Getopt/Long.pbc"
.local pmc get_options
find_global get_options, "Getopt::Long", "get_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 Parrot library can be used for parsing command line options. The subroutine get_options() is exported into the namespace 'Getopt::Long'.
get_options
in Getopt::Long
This should work like the Perl5 module Getopt::Long. Takes an array of options and an array of specifications.
A Hash PMC is returned.
- 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.
|