I'm refreshing on 15.9 Command-Line Parsing and I note that there doesn't seem to be a way to say "this flag must be present." Am I missing something?
Here's the normal workaround:
#lang racket
(define name (make-parameter #f))
(define height (make-parameter #f))
(define phone-numbers (make-parameter '()))
(command-line
#:program "describe person"
#:once-each
[("-n" "--name") nm "Specify person's name (mandatory)" (name nm)]
[("-H" "--height") h "Specify height in cm" (height h)]
#:multi
[("-p" "--phone") p "Add another phone number" (phone-numbers (cons p (phone-numbers)))])
(when (not (name))
(displayln "You must specify the name")
(exit 0))
(displayln (~a "name: " (name)))
(displayln (~a "height in cm: " (height)))
(displayln (~a "phone num(s): " (phone-numbers)))
I could of course use a non-flagged argument after the flags, but I disprefer that option in cases where there are multiple mandatory items, for the same reason that we use keyword arguments on functions: remembering argument order can be a drag.
I agree that I don't see an obvious way to accomplish that with the current set of specifiers. Maybe a pull request to add a specifier to the command-line implementation would make sense?
Link to this section with
@secref["Command-Line_Parsing"
#:doc '(lib "scribblings/reference/reference.scrbl")]
Document source
https://github.com/racket/racket/tree/master/pkgs/racket-doc/scribblings/reference/reference.scrbl
I clicked the 'document source' link and got to the github repository on a page that has nothing whatsoever to do with command line parsing, which makes me think this is not the right place to make suggestions to the documentation.
If I want to locate the actual documentation, or even the implementation, do I have a better option than simply grep -r?
I agree that in this particular case these links aren't very helpful for someone who wants to contribute, it would be nice if this feature could be improved, but I am unsure whether that would be easy or difficult.
One trick I use in situations like this is:
I look for an identifier that looks fairly rare / unique
use that identifier with the github search
Here is an example, I used #:help-labels and searched within the racket/racket repository (depending on what code it is you may have to do a github wide search, in that case the identifier should be very unique so that this works): https://github.com/racket/racket/search?q=%23%3Ahelp-labels
Another approach is to use drracket's open Defining File but that is only helpful if you want to edit code, less helpful to find the actual scribble file that contains the documentation.
Finding the implementation is pretty easy: just hover over a use of command-line, right click, and use "Open Defining File". This should open the file containing the implementation of command-line. N.B. this assumes you're using DrRacket.
How difficult would it be to implement a "Open Documenting File"?
I really haven't looked into how all that scribble stuff works at all.
What would be needed?
find out whether a binding has documentation
if it has documentation find the source location where it gets documented
I think 1. should already be there considering drracket can show the documentation of functions etc..