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

pass args to scripts #49

Merged
merged 27 commits into from
Aug 5, 2023
Merged

pass args to scripts #49

merged 27 commits into from
Aug 5, 2023

Conversation

Yakiyo
Copy link
Contributor

@Yakiyo Yakiyo commented Jul 28, 2023

Pass any additional arguments passed after script name in command invocation to the script.

Resolves #48

- test wether pn properly prints and outputs additional args passed to echo
@Yakiyo
Copy link
Contributor Author

Yakiyo commented Jul 30, 2023

Any status on this?

@zkochan zkochan requested a review from KSXGitHub August 1, 2023 22:49
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@KSXGitHub KSXGitHub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the arguments that contain whitespaces? Don't we need to escape them before passing the command to sh -c?

Related crates: https://docs.rs/shell-escape/0.1.5/shell_escape/

This crate is better: https://docs.rs/shell-quote/0.3.0/shell_quote/sh/fn.escape_into.html

@Yakiyo
Copy link
Contributor Author

Yakiyo commented Aug 3, 2023

What about the arguments that contain whitespaces? Don't we need to escape them before passing the command to sh -c?

Related crates: https://docs.rs/shell-escape/0.1.5/shell_escape/

Not sure what that would look like. care to give an example? How does pnpm do it?

@KSXGitHub
Copy link
Contributor

KSXGitHub commented Aug 3, 2023

Not sure what that would look like. care to give an example? How does pnpm do it?

pnpm for sure handles whitespace.

proof

But for how pnpm did it, you must ask @zkochan.

If you ask me, I have already answered: Just use the crate I suggested, I don't really care how exactly pnpm did it.

src/main.rs Outdated Show resolved Hide resolved
@KSXGitHub
Copy link
Contributor

KSXGitHub commented Aug 3, 2023

Just use the crate I suggested

Actually, I think this crate is better: https://docs.rs/shell-quote/0.3.0/shell_quote/sh/fn.escape_into.html

You do have to change the type of RunArgs::args back to Vec<OsString> though.

@Yakiyo
Copy link
Contributor Author

Yakiyo commented Aug 3, 2023

pnpm for sure handles whitespace.

i tried it out a few seconds ago but clap handles it.
passing pn run test "Hello World" "! !" takes it as two args instead of 4.

@KSXGitHub
Copy link
Contributor

i tried it out a few seconds ago but clap handles it.
passing pn run test "Hello World" "! !" takes it as two args instead of 4.

Clap handles it but the command you pass to sh -c doesn't.

screenshot

@Yakiyo
Copy link
Contributor Author

Yakiyo commented Aug 3, 2023

okay i understand the issue now
image

@KSXGitHub
Copy link
Contributor

If you used my list-args.js, the issue would have been clearer.

Also, please use the shell-quote crate as suggested here.

@Yakiyo
Copy link
Contributor Author

Yakiyo commented Aug 4, 2023

@KSXGitHub not sure if i did anything wrong but it doesnt seem to work

image

and based on the ci, shell quote is failing to build on windows.

@Yakiyo
Copy link
Contributor Author

Yakiyo commented Aug 4, 2023

env::args_os itself is stripping away the quotes
image

@KSXGitHub
Copy link
Contributor

KSXGitHub commented Aug 4, 2023

shell quote is failing to build on windows.

This was an oversight on my part. I was not aware that shell-quote is not cross-platform. Let's try os_display.

Also, changing the type of RunArgs::args to Vec<OsString> seems to lead to verbose code, let's reverse that.

@Yakiyo Yakiyo requested a review from KSXGitHub August 5, 2023 14:58
Copy link
Contributor

@KSXGitHub KSXGitHub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yakiyo
Copy link
Contributor Author

Yakiyo commented Aug 5, 2023

See Yakiyo#1

merged

@KSXGitHub
Copy link
Contributor

Windows CI fails

CLRF strikes again.

tests/test_main.rs Outdated Show resolved Hide resolved
@KSXGitHub KSXGitHub requested a review from zkochan August 5, 2023 16:13
Copy link
Contributor

@KSXGitHub KSXGitHub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feat: use `Cow` to reduce allocation
@Yakiyo
Copy link
Contributor Author

Yakiyo commented Aug 5, 2023

Can you merge this? Yakiyo#2

done

@zkochan zkochan merged commit 0bd5a5c into pnpm:main Aug 5, 2023
5 checks passed
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

Successfully merging this pull request may close these issues.

Pass additional command line arguments when running scripts
3 participants