Skip to content

Instantly share code, notes, and snippets.

@kflu
Created February 13, 2017 07:43
Show Gist options
  • Save kflu/41d29ed669a1b7894f48f0c3cf5d343d to your computer and use it in GitHub Desktop.
Save kflu/41d29ed669a1b7894f48f0c3cf5d343d to your computer and use it in GitHub Desktop.
Racket command line use
#| This script demos the use of command line library. Note the use
of parameters, and the effort of encapsulating them in the local
bound function variables.
|#
#lang racket
(define [file-to-compile argv]
(let ([verbose-mode (make-parameter #f)]
[profiling-on (make-parameter #f)]
[optimize-level (make-parameter 0)]
[link-flags (make-parameter null)])
(command-line
#:program "compiler"
#:argv argv
#:once-each
[("-v" "--verbose") "Compile with verbose messages"
(verbose-mode #t)]
[("-p" "--profile") "Compile with profiling"
(profiling-on #t)]
#:once-any
[("-o" "--optimize-1") "Compile with optimization level 1"
(optimize-level 1)]
["--optimize-2" (; show help on separate lines
"Compile with optimization level 2,"
"which includes all of level 1")
(optimize-level 2)]
#:multi
[("-l" "--link-flags") lf ; flag takes one argument
"Add a flag <lf> for the linker"
(link-flags (cons lf (link-flags)))]
#:args (filename) ; expect one command-line argument: <filename>
; return the argument as a filename to compile
`(,filename ,(verbose-mode)))))
(file-to-compile '("-v" "foo"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment