## process-commandline.api
# Compiled by:
#
src/lib/std/standard.lib# A Mythryl port of the SML port of GNU's getopt library.
#
# This port is derived from Sven Panne's
# <Sven.Panne@informatik.uni-muenchen.de>
# implementation of the getopt library in Haskell <http://www.haskell.org>
#
# The following comments are lifted from Sven's code:
#
# Two rather obscure features are missing: The Bash 2.0 non-option hack (if
# you don't already know it, you probably don't want to hear about it...)
# and the recognition of long options with a single dash (e.g. '-help' is
# recognised as '--help', as long as there is no short option 'h').
#
# Other differences between GNU's getopt and this implementation:
# * To enforce a coherent description of options and arguments, there are
# explanation fields in the option/argument descriptor.
# * Error messages are now more informative, but no longer POSIX
# compliant... :-(
#
#
#
# A difference from Sven's port: errors now invoke an error callback, rather
# than returning error strings while continuing processing options.
# The full generality of the latter does not seem justified.
### "The empires of the future
### are the empires of the mind."
###
### -- Winston Churchill
api Process_Commandline {
# What to do with options following non-options:
# RequireOrder: no option processing after first non-option
# Permute: freely intersperse options and non-options
# ReturnInOrder: wrap non-options into options
#
Nonleading_Options_Policy X
= NO_NONLEADING_OPTION_PROCESSING
| FREELY_INTERSPERSE_OPTIONS_AND_NONOPTIONS
| TURN_NONOPTIONS_INTO_OPTIONS String -> X;
# Description of an option argument:
# OPTION_ARGUMENT_NONE: No argument required
# OPTION_ARGUMENT_REQUIRED: Option requires an argument; the string is the argument name
# OPTION_ARGUMENT_OPTIONAL: Optional argument; the string is the argument name
#
Option_Argument X
= OPTION_ARGUMENT_NONE Void -> X
| OPTION_ARGUMENT_REQUIRED { name: String, wrap: String -> X }
| OPTION_ARGUMENT_OPTIONAL { name: String, wrap: Null_Or( String ) -> X };
# Description of a single option:
#
Option_Definition(X)
=
{
short: String,
long: List( String ),
arg: Option_Argument(X),
help: String
};
# Accept a header string and a list of option definitions.
#
# Return a string explaining the usage information.
# A newline will be added following the header,
# so it should not be newline terminated.
#
build_options_usage_string
:
{
header: String,
options: List( Option_Definition(X) )
}
->
String;
# Accept as arguments:
# o An arg_order to specify the non-options handling,
# o A list of option descriptions,
# o An error callback, and
# o A command line containing the options and arguments.
#
# Return a tuple of ([options], [non-options])
#
process_commandline
:
{
nonleading_options_policy: Nonleading_Options_Policy(X),
options: List( Option_Definition(X)),
error_callback: String -> Void
}
-> List( String )
-> ((List(X), List( String )));
};
## COPYRIGHT (c) 1998 Bell Labs, Lucent Technologies.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.