Changeset 25703 in project for release


Ignore:
Timestamp:
12/14/11 07:32:23 (10 years ago)
Author:
Jim Ursetto
Message:

args 1.4.3: Use program-name instead of (car (argv)); add notes in examples

Location:
release/4/args/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/4/args/trunk/args-examples.scm

    r17555 r25703  
    11(module main ()
    22
    3   (import scheme chicken)
     3  (import scheme (rename chicken (program-name $0)))
    44  (require-library extras ports data-structures)
    55  (import (only extras printf))
     
    1313  (list (args:make-option (c cookie)    #:none     "give me cookie"
    1414          (print "cookie was tasty"))
    15         (args:make-option (d)           (optional: "LEVEL")  "debug level [default: 1]")
     15        (args:make-option (d debug)           (optional: "LEVEL")  "debug level [default: 1]")
    1616        (args:make-option (e elephant)  #:required "flatten the argument"
    1717          (print "elephant: arg is " arg))
     
    2929  (with-output-to-port (current-error-port)
    3030    (lambda ()
    31       (print "Usage: " (car (argv)) " [options...] [files...]")
     31      (print "Usage: " ($0) " [options...] [files...]")
    3232      (newline)
    3333      (print (args:usage opts))
     
    3939
    4040;;(define args (command-line-arguments))
    41 (define args (list "--cookie" "-d" "b.c" "--abc" "-e" "test" "-e" "hello" "e.c" "f.c"))
     41(define args (list "--cookie" "-d" "b.c" "--abc" "-e" "test" "-e" "hello" "e.c" "f.c" "-f"))
    4242
    4343;;; Process arguments and collate options and arguments into OPTIONS alist,
    4444;;; and operands (filenames) into OPERANDS.  You can handle options as
    4545;;; they are processed, or afterwards.
     46
     47;;; Note that missing required args can only be detected if their option appears last,
     48;;; and optional args must not be separated from their option by a space
     49;;; (e.g. -d2 or --debug=2, not -d 2 or --debug 2).
    4650
    4751(define options)
     
    5963;;  elephant: arg is test
    6064;;  elephant: arg is hello
     65;;  args-examples.scm: option f requires an argument
    6166;;  A, B, C, D, E, &c.
    6267;;  hello
  • release/4/args/trunk/args.scm

    r17555 r25703  
    112112                                    (fprintf (current-error-port)
    113113                                             "~A: unrecognized option: ~A\n"
    114                                              (car (argv)) name)
     114                                             (program-name) name)
    115115                                    (if help-option
    116116                                        ((option-processor (args:option-option help-option))
     
    262262          (%append   (r 'append))
    263263          (%map     (r 'map))
    264           (argv     (r 'argv))
    265264          (fprintf  (r 'fprintf))
    266265          (current-error-port    (r 'current-error-port))
     
    287286                          (,fprintf (,current-error-port)
    288287                                   "~A: option ~A requires an argument\n"
    289                                    (,%car (,argv)) name)
     288                                   (,(r 'program-name)) name)
    290289                          (,%values options operands))
    291290                        (,%begin
  • release/4/args/trunk/args.setup

    r17555 r25703  
    1010 'args
    1111 `(,(dynld-name "args") ,(dynld-name "args.import") )
    12  `((version 1.4.2)
     12 `((version 1.4.3)
    1313   (documentation "args.html")
    1414   ))
Note: See TracChangeset for help on using the changeset viewer.