Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command doesn't allow specification of an "end of flags" marker #24

Open
hugoduncan opened this issue Sep 4, 2013 · 4 comments
Open
Assignees
Labels
forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system.

Comments

@hugoduncan
Copy link

Some programs take option like arguments (i.e. options starting with --) as data. In other option processing libraries, -- can be used to explicitly mark the end of options to be processed.

While we can workaround this by manually splitting the argument list before passing it to Command.run, it would be great to see support for this in Command.

@avsm
Copy link
Contributor

avsm commented Sep 4, 2013

Yes, this came up in earlier discussions about supporting "-" as a valid filename. It can be current be written by using the Command.Spec.escape flag (which can only be passed once) to escape the parser and pass through all remaining arguments.

It's worth considering if -- should be the default escape flag, which is present unless another escape flag supersedes it.

-anil

On 4 Sep 2013, at 11:39, Hugo Duncan notifications@github.com wrote:

Some programs take option like arguments (i.e. options starting with --) as data. In other option processing libraries, -- can be used to explicitly mark the end of options to be processed.

While we can workaround this by manually splitting the argument list before passing it to Command.run, it would be great to see support for this in Command.


Reply to this email directly or view it on GitHub.

@hugoduncan
Copy link
Author

Thanks for pointing to escape. I'm trying to use it but don't seem to be getting it right - would you have an example (I can't see one in the examples/command/main.ml)?

@ghost
Copy link

ghost commented Sep 4, 2013

You have to create a parameter named "--". For instance:

open Core.Std

let main args () =
  let args = Option.value args ~default:[] in
  List.iter args ~f:print_endline
;;

let () =
  let spec =
    Command.Spec.(empty
                  +> flag "--" escape ~doc:" stop processing command line arguments")
  in
  Command.run (Command.basic ~summary:"Blah." spec main)
$ ./foo -- a -b c
a
-b
c

@hugoduncan
Copy link
Author

Ahh, the escape flag returns the anon arguments - I was assuming it would be returning () and an +> anon would still be necessary. I actually have a couple of anon arguments, so would loose that ability when using the -- flag.

When invoking the above without -- I get errors however:

$ ./foo a b c
...
too many anonymous arguments

My assumption was that ./foo a b c and ./foo -- a b c would be equivalent.

@ghost ghost assigned rnml Dec 2, 2013
RadicalZephyr added a commit to RadicalZephyr/postfix-ocaml that referenced this issue Nov 16, 2014
This doesn't work because the Command library has some deficiencies...

One of them being that it's hard to stop processing arguments as flags
and then continue processing them. janestreet/core#24 has more info
about the way this currently works.
@github-iron github-iron added the forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system. label May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system.
Projects
None yet
Development

No branches or pull requests

4 participants