((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/easy-args" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.") (tags "egg")) (section 2 "easy-args" (toc)) (section 2 "Description" (p "Handle command-line arguments as parameter objects.") (p (b "This egg is no longer maintained.") " Please refer to " (int-link "/eggref/4/srfi-37" "srfi-37") ", " (int-link "/eggref/4/args" "args") " or " (int-link "/eggref/4/getopt-long" "getopt-long") " for other command-line argument handling libraries for CHICKEN 4.")) (section 2 "Requirements" (p (int-link "/eggref/4/srfi-37" "srfi-37"))) (section 2 "API" (section 3 "define-arguments" (def (sig (syntax "(define-arguments (name [value [guard]]) ...)" (id define-arguments))) (p (tt "define-arguments") " defines parameter objects for the given command line option names and sets them according to the program's " (tt "command-line-arguments") " parameter.") (p "For each specified argument, " (tt "name") " should be an identifier or list of identifiers. The first of these will be bound to the newly-created parameter object. " (tt "value") ", if given, must be a boolean, string, number or symbol, and will be the default value of the parameter object. If no " (tt "value") " is given, " (tt "#f") " is used. If a procedure " (tt "guard") " is given, it is used as the parameter object's conversion procedure.") (p "Each " (tt "name") ", when prefixed by one dash (in the case of a single-character identifier) or two (for all others), will be used as a command-line flag to set the corresponding parameter object's value. If " (tt "name") " contains asterisks, they are stripped from the flag.") (p (tt "define-arguments") " reads and modifies Chicken's " (tt "command-line-arguments") " parameter, setting matched parameter objects to the specified values and removing their options from the list. Unmatched arguments are accumulated into an alist accessible by the " (tt "unmatched-arguments") " procedure. Upon completion, " (tt "command-line-arguments") " will contain any non-option arguments to the program. The return value is unspecified."))) (section 3 "invalid-argument-handler" (def (sig (parameter "invalid-argument-handler" (id invalid-argument-handler))) (p (tt "invalid-argument-handler") " is called when " (tt "define-arguments") " encounters an invalid command-line value. It is a procedure of three arguments: an error message (string), option name (string or character) and value (a string or " (tt "#t") "). By default, this procedure simply prints an error message and exits the program."))) (section 3 "unmatched-arguments" (def (sig (procedure "(unmatched-arguments)" (id unmatched-arguments))) (p "Returns an alist of the command-line arguments unmatched by " (tt "define-arguments") ". If called before " (tt "define-arguments") ", it will return an empty list.")))) (section 2 "Examples" (highlight scheme "(use easy-args extras)\n\n(define-arguments\n  (all-caps)\n  (prompt \"Your name? \")\n  ((exclamations e) 1))\n\n(display (prompt))\n\n(let ((message (string-join `(\"Hello,\" ,(read-line)))))\n  (if (all-caps)\n    (display (string-upcase message))\n    (display message)))\n\n(print (make-string (exclamations) #\\!))\n\n(if (not (null? (unmatched-arguments)))\n  (print (unmatched-arguments)))") (p "With the file above as " (tt "greeter.scm") ":") (pre " $ csc greeter.scm\n \n $ ./greeter\n Your name? [Henrietta]\n Hello, Henrietta!\n \n $ ./greeter --all-caps\n Your name? [Henrietta]\n HELLO, HENRIETTA!\n \n $ ./greeter --prompt 'Name: ' -e3\n Name: [Henrietta]\n Hello, Henrietta!!!\n \n $ ./greeter -w --unmatched=args\n Your name? Henrietta\n Hello, Henrietta!\n ((w . #t) (unmatched . args))")) (section 2 "History" (ul (li "0.6 Deprecated") (li "0.5 Use srfi-37, getopt-style flags") (li "0.4 Allow symbols") (li "0.1 Initial release"))) (section 2 "Author" (p (int-link "/users/evan-hanson" "Evan Hanson"))) (section 2 "License" (p "Public Domain")))