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

Make positional-arguments default to true next edition #1367

Open
casey opened this issue Oct 13, 2022 · 6 comments
Open

Make positional-arguments default to true next edition #1367

casey opened this issue Oct 13, 2022 · 6 comments

Comments

@casey
Copy link
Owner

casey commented Oct 13, 2022

To recap, set positional-arguments allows accessing arguments with$N:

$ cat justfile
set positional-arguments

foo bar:
  echo $1
$ just foo x
echo $1
x

This can be very convenient, since it lets you avoid word splitting and possibly extra layers of quoting. I wanted to make this default to true when it was initially implemented, since it's very useful. However, it used to break powershell, and since powershell is widely used, this wouldn't be a suitable default.

However, it appears that powershell now allows this:

$ pwsh --version
PowerShell 7.2.6
$ cat justfile
set shell := ['pwsh', '-Command']

set positional-arguments

foo bar:
  echo $1
$ just foo x
echo $1
x

So, positional-arguments is again a contender to default to true when the next edition is released.

@eRaMvn
Copy link

eRaMvn commented Dec 11, 2022

My apologies, but from your code

$ cat justfile
set shell := ['pwsh', '-Command']

set positional-arguments

foo bar:
  echo $1
$ just foo x
echo $1
foo
x

Should this be the expected behavior?

$ just foo x
echo $1
x

Printing $1 should only prints x right

@casey
Copy link
Owner Author

casey commented Dec 15, 2022

@eRaMvn Good catch! Yup, that's correct, I fixed it.

@eRaMvn
Copy link

eRaMvn commented Dec 15, 2022

so when I played around with powershell, the output is exactly what you printed above

$ just foo x
echo $1
foo
x

so maybe there is a bug

@casey
Copy link
Owner Author

casey commented Dec 17, 2022

Weird! It doesn't do this with sh:

set positional-arguments

foo bar:
  echo $1
$ just foo x
echo $1
x

What about if you do:

foo bar:
  echo "$1"

I'm curious if for some reason $1 is including the recipe name, which should be in $0 and not $1.

@eRaMvn
Copy link

eRaMvn commented Dec 19, 2022

Yeah, I think there is a bug for pwsh. I don't know rust well enough to make a PR
image

When I do "$1" the behavior is the same
image

Same for $0
image

@cspotcode
Copy link

This is not a pwsh bug per-se, it's a misunderstanding of how positionals work. I wrote about it in detail in #1592, I hope it helps.

The usefulness of positional-arguments relies on assumptions about bash and friends that are not true for powershell. It assumes common posix $@, $1, syntax for positionals. It assumes the shell will accept a command as a single string (single entry of its argv array) and keep it separate from any trailing positionals, capturing them into an $@ array. Powershell does not do this at all. When we think that it's accepting positionals, it's not. Rather, it's combining all positionals into a single command, interpreting all of it as powershell syntax to be executed.

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

No branches or pull requests

3 participants