{"size": 1824, "ext": "scrbl", "max_stars_repo_path": "doc/utils/getopt.scrbl", "max_stars_repo_name": "david135/sagittarius-scheme", "max_stars_repo_stars_event_min_datetime": "2015-11-07T07:13:35.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-15T03:35:14.000Z", "max_issues_repo_path": "doc/utils/getopt.scrbl", "max_issues_repo_name": "david135/sagittarius-scheme", "max_issues_repo_issues_event_min_datetime": "2016-04-28T21:59:59.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-01T08:42:21.000Z", "max_forks_repo_path": "doc/utils/getopt.scrbl", "max_forks_repo_name": "david135/sagittarius-scheme", "max_forks_repo_forks_event_min_datetime": "2016-12-28T12:41:23.000Z", "max_forks_repo_forks_event_max_datetime": "2020-02-26T20:52:02.000Z"}
{"max_stars_count": 39, "max_issues_count": 3, "max_forks_count": 4, "avg_line_length": 33.7777777778, "max_line_length": 79, "alphanum_fraction": 0.701754386}
@; -*- mode:scribble; coding: utf-8; -*-

@subsection[:tag "getopt"]{(getopt) - Parsing command-line options}

@define[Library]{@name{(getopt)}}
@desc{This library defines a convenient way to parse command-line options.

The library exports a thin wrapper of @secref["srfi"]{SRFI-37: args-fold}.
}

@define[Macro]{@name{with-args}
 @args{args (bind-spec @dots{} [. rest]) body @dots{}}}
@desc{This macro wraps @code{args-fold} provided by SRFI-37. It takes a list
of arguments, @var{args}, and scans it to find Unix-style command-line
options and binds their values to local variables according to @var{bind-spec},
then executes @var{body}.

Following is the example how to use;

@codeblock{
(define (usage args) ...)

(define (main args)
  (with-args args
     ((verbose (#\v "verbose") #f #f)
      (file    (#\f "file") #t (usage args))
      (debug-level   (#\d "debug-level") #t "0")
      . rest)
    ...))
}

The @var{bind-spec} must be one of the following forms;

@itemlist[
 @item{@var{(var (short long) value-required? default)}}
 @item{@var{(var (short long) @code{*} default)}}
]

@var{var} is variable name. @var{short} must be a character represents the
short argument name. @var{long} must be a string represents the long argument
name. @var{value-required?} specifies whether or not the optional argument
has the value. @var{default} is the default form of the variable so it will
be evaluated when the input @var{args} didn't have the specified option.

If the second form is used, the @code{*} is syntactic keyword and the
passed value will be packed to list. Thus the script can take more than one
the same options.

If @var{rest} is not presented and @var{args} contains non listed argument,
then it raises an @code{&assertion}. If it is, then it will pack the rest of
non listed argument as a list.

}
