cli icon indicating copy to clipboard operation
cli copied to clipboard

Is there a way to support --switch=parameter syntax ??

Open rwilcox opened this issue 4 years ago • 4 comments

Given the following program --help generates help text that doesn't seem to support --parameter=text format, but --parameter text

#lang cli

(flag (file  in-file-path)
      ("-f" "--file" "filepath")
      (file in-file-path))

(program (hello)
  (displayln (file))
)

(run hello)

CLI output:

PS ... > D:\Racket\Racket.exe .\tmp.rkt --help
usage: hello [ <option> ... ]


<option> is one of


  -f <in-file-path>, --file <in-file-path>
     filepath to write the changelog to. Can NOTE use --file=foo must use --file foo
  --help, -h
     Show this help
  --
     Do not treat any remaining argument as a switch (at this level)

 *   Asterisks indicate options allowed multiple times.

 Multiple single-letter switches can be combined after
 one `-`. For example, `-h-` is the same as `-h --`.

PS ...> D:\Racket\Racket.exe .\tmp.rkt --file hello
hello
PS ...> D:\Racket\Racket.exe .\tmp.rkt --file=hello
hello: unknown switch: --file=hello
PS C:\Users\aias\Documents\Development\simple_changelog>

(but thank you very much for making this little language!)

rwilcox avatar Sep 12 '21 20:09 rwilcox

Hi @rwilcox ! This package does not parse the command line syntax directly but instead simply leverages the command line arguments and flags reported by Racket's built-in current-command-line-arguments parameter. I did a quick google search to get a sense of how common the = syntax is, and I couldn't really say. At least one link mentioned it, but other links seemed to be unaware of it. Do you happen to know if it is considered a UNIX standard? If so, you may want to open an issue on the Racket repo directly to recognize this syntax in the core command line utilities. What do you think?

countvajhula avatar Sep 14 '21 07:09 countvajhula

It’s in the libc docs, so I’m guessing it’s pretty common 😄

But OK, I may take a look at writing a command line program with the core utils, repro the issue and open a bug with Racket, that’s a good idea.

rwilcox avatar Sep 14 '21 09:09 rwilcox

You can probably just use the example in the docs on the built-in command line utilities, which should be runnable as is. E.g. "link-flags" there takes an argument at the command line.

countvajhula avatar Sep 14 '21 23:09 countvajhula

This has been on my radar for a while, but finally did something about it: https://github.com/racket/racket/issues/4106

rwilcox avatar Dec 19 '21 21:12 rwilcox