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

Patch to add "Rest" option to ocaml toplevel #4671

Closed
vicuna opened this issue Dec 14, 2008 · 8 comments
Closed

Patch to add "Rest" option to ocaml toplevel #4671

vicuna opened this issue Dec 14, 2008 · 8 comments

Comments

@vicuna
Copy link

vicuna commented Dec 14, 2008

Original bug ID: 4671
Reporter: mwahab
Assigned to: @diml
Status: feedback (set by @diml on 2017-01-05T13:40:32Z)
Resolution: open
Priority: normal
Severity: feature
Version: 3.11.0+beta
Category: toplevel
Tags: patch
Monitored by: @whitequark @glondu

Bug description

It would be useful to be able to pass command line options to
libraries linked into the ocaml toplevel. Attached is a patch to add
the Arg.Rest option '--' to the ocaml toplevel and function
Toploop.get_cli_strings to get the strings after the -- option.

Additional information

Example usage:

ocaml -I +camlp4 -- other options

Toploop.get_cli_strings();;

  • : string list = ["other"; "options"]

Patch is against CVS head

File attachments

@vicuna
Copy link
Author

vicuna commented Jan 5, 2017

Comment author: @diml

Do you have a use case for this? If all libraries see the same command line, it might not be clear how to dispatch arguments. Another way would be to allow libraries to register new command line arguments for the toplevel.

@vicuna vicuna assigned ghost Mar 14, 2019
@github-actions
Copy link

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

@github-actions github-actions bot added the Stale label May 18, 2020
@whitequark
Copy link
Member

I still think this would be useful for scripting in OCaml.

@gasche
Copy link
Member

gasche commented May 18, 2020

Note: there already is a different mechanism for this when calling ocaml with a "script file": only the arguments after the script file will be part of Sys.argv.

$ echo Array.iter print_endline Sys.argv > test.ml

$ ocaml -I ~
        OCaml version 4.09.0
# #use "test.ml";;
/home/gasche/.opam/4.09.0/bin/ocaml
-I
/home/gasche
- : unit = ()

$ ocaml -I ~ test.ml foo bar
test.ml
foo
bar

$ cat test.ml | ocaml -I ~ "" foo bar

foo
bar

$ cat test.ml | ocaml -I ~ -stdin foo bar
-stdin
foo
bar

Given this facility, I am a bit hesitant to add a new mechanism as suggested in this feature wish.

@xavierleroy
Copy link
Contributor

Yes, the feature wish is about interactive use, as far as I understand; scripting is already OK.

@gasche
Copy link
Member

gasche commented May 18, 2020

Maybe we could follow the suggestion of allowing -- <extra args>, and then use the same (slightly hackish) behavior as for scripting, namely overriding Sys.argv. This is close to what we are already doing, and it is backward-compatible: invocations without -- still see all arguments as today.

@whitequark
Copy link
Member

That sounds very nice.

@github-actions
Copy link

This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants