Pass command line arguments to script with shebang line
LightAndLight opened this issue · comments
Example program (script.ipso
):
#! /usr/bin/env ipso
main : IO ()
main =
comp
bind args <- env.args
println <| debug args
The shebang means that ./script.ipso
results in a call to ipso ./script.ipso
. Currently I have to add --
to signal the start of arguments that should be passed to the script. But I can't write the shebang in a way that runs ipso ./script.ipso --
.
So we should have:
ipso -- a b c
- start the REPL, having passeda
,b
, andc
as argumentsipso script.ipso -- a b c
- runscript.ipso
, having passeda
,b
, andc
as argumentsipso script.ipso a b c
- runscript.ipso
, having passeda
,b
, andc
as arguments
This is the best I can come up with right now:
$ ipso --help
Usage: ipso [OPTIONS] [FILENAME] [ARGS]...
Arguments:
[FILENAME] The file to run. Starts a REPL if omitted
[ARGS]... Arguments to pass to the ipso program
Options:
--run <ENTRYPOINT> Run a specific IO action from the file. Defaults to "main"
--version Print the current version
-h, --help Print help information
$ ipso -- --help
error: file --help does not exist
test.ipso
:
#! /usr/bin/env -S ipso --
main : IO ()
main =
comp
bind args <- env.args
println <| debug args
$ ./test.ipso
[]
$ ./test.ipso --help
["--help"]
The --
signals the end of options, and subsequent words are treated as arguments. The first argument is the script name, and then the command line arguments.
This also works:
#! /usr/bin/env ipso
main : IO ()
main =
comp
bind args <- env.args
println <| debug args
$ ./test.ipso
[]
$ ./test.ipso --help
["--help"]