igor-petruk / scriptisto

A language-agnostic "shebang interpreter" that enables you to write scripts in compiled languages.
Apache License 2.0
909 stars 25 forks source link

Executing 'bin/xy.rs' runs scriptisto itself, instead of script ('./bin/xy.rs' works as expected) #26

Closed d4h0 closed 3 years ago

d4h0 commented 3 years ago

Expected Behavior

Executing bin/xy.rs executes the target script.

Actual Behavior

scriptisto itself is executed.

This works:

[dh@arch]$ ./bin/cli.rs
Hello, Rust! Command line options: Opt { input: None } 

This doesn't work (notice the missing "./"):

[dh@arch]$ bin/cli.rs 
scriptisto 0.6.10
A 'shebang-interpreter' for compiled languages

USAGE:
    scriptisto [ARGS] [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <script-src>    A path to a script to run. If specified, first character must be "." or "/"
    <args>...       Additional arguments passed to a script

SUBCOMMANDS:
    build       Build a script without running
    cache       Build cache operations
    help        Prints this message or the help of the given subcommand(s)
    new         Prints an example starting script in a programming language of your choice
    template    Manage custom script templates
[dh@arch abalet.com]$ 

Steps to Reproduce the Problem

  1. Run: mkdir bin
  2. Run: scriptisto new rust bin/foo.rs
  3. Run: chmod +x bin/foo.rs
  4. Run: bin/foo.rs

Specifications

ngirard commented 3 years ago

Hey @igor-petruk,

would you mind releasing a new version that takes advantage of the fix ?

Cheers !

igor-petruk commented 3 years ago

Hi,

I tried, but then I had to yank it. I think I've broken the argument passing. I am trying to fix it now

ngirard commented 3 years ago

Oh. Good luck with that & thanks for your feedback !

igor-petruk commented 3 years ago

Ok, now I think it is ok, I've done the release.

The code is somewhat ugly, so I anticipate to split the tool in two binaries, making a separate scriptisto-run binary purely as the shebang interpreter, that can unambiguously know that it is not suppose to invoke structopt ever. For now there is a lot of guesswork. This should also make the runtime faster

ngirard commented 3 years ago

The code is somewhat ugly, so I anticipate to split the tool in two binaries, making a separate scriptisto-run binary purely as the shebang interpreter, that can unambiguously know that it is not suppose to invoke structopt ever.

An alternative would be to keep one binary and behave differently according to the invocation name, like BusyBox / RustyBox.