Skip to content

provide env to commands and try to start provided path#10302

Merged
sholderbach merged 2 commits intonushell:mainfrom
geniusisme:gi/env-in-start
Sep 12, 2023
Merged

provide env to commands and try to start provided path#10302
sholderbach merged 2 commits intonushell:mainfrom
geniusisme:gi/env-in-start

Conversation

@geniusisme
Copy link
Copy Markdown
Contributor

@geniusisme geniusisme commented Sep 10, 2023

fixes #8551

Description

Use open::commands function to get list of command available for starting given path. run commands directly, providing environment, until one of them is successful.

example of output if start was not successful:

~\code\nushell> start ..\nustart\a.myext                                                                    09/10/2023 06:11:54 PM
Error: nu::shell::external_command

  × External command failed
   ╭─[entry #1:1:1]
 1 │ start ..\nustart\a.myext
   ·       ─────────┬────────
   ·                ╰── No command found to start with this path
   ╰────
  help: Try different path or install appropriate command

        Command "cmd" "/c" "start" "" "..\nustart\a.myext" failed with ExitStatus(ExitStatus(1))

User-Facing Changes

start command now provides environment to the external command. This is how it worked in nu 0.72, see linked issue.

Tests + Formatting

start command didn't have any tests and this PR does not add any. Integration-level tests will require setup specific to OS and potentially change global environment on testing machine. For unit-level test it is possible to test try_commands function. But is still runs external commands, and robust test will require apriori knowledge which commands are necessary successful to run and which are not.

Do docs need updating after this PR?

@amtoine amtoine added the platform:windows Issues which are specific to Windows label Sep 10, 2023
@amtoine
Copy link
Copy Markdown
Member

amtoine commented Sep 10, 2023

Do docs need updating after this PR?

because your changes only touch a single command, the documentation that is rendered on the website will be updated automatically next release 😋

Copy link
Copy Markdown
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

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

Edited: removed inaccurate understanding

Comment on lines +164 to +165
Ok(status) => Err(format!("\nCommand {cmd:?} failed with {:?}", status)),
Err(err) => Err(format!("\nCommand {cmd:?} failed with {:?}", err)),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Debug formatting is debug formatting and shouldn't necessarily be used for regular user output.

@geniusisme
Copy link
Copy Markdown
Contributor Author

2. At the same time after this PR `start` will launch multiple commands until it deems the result of them succesful. (There could be side effects to that)

This behavior did not change. It is exactly what open crate is doing under the hood:
https://github.com/Byron/open-rs/blob/main/src/lib.rs#L144

@sholderbach
Copy link
Copy Markdown
Member

This behavior did not change. It is exactly what open crate is doing under the hood: Byron/open-rs@main/src/lib.rs#L144

Oh sorry, yes you are right. I stand corrected.

What prompted me with the comments around error handling is that in the output above, the command is not represented in a form you could run:

Command "cmd" "/c" "start" "" "..\nustart\a.myext" failed with ExitStatus(ExitStatus(1))

It would be great if this could represent a form that would be valid to execute in nushell.

@geniusisme
Copy link
Copy Markdown
Contributor Author

geniusisme commented Sep 10, 2023

It would be great if this could represent a form that would be valid to execute in nushell.

I agree. Using debug formatter was a poor choice, will change that.

@sholderbach
Copy link
Copy Markdown
Member

Awesome, thanks!

@geniusisme
Copy link
Copy Markdown
Contributor Author

This is how exapamle from OP looks like now:

~\code\nushell> start ..\nustart\a.myext                                                                    09/12/2023 01:37:55 PM
Error: nu::shell::external_command

  × External command failed
   ╭─[entry #1:1:1]
 1 │ start ..\nustart\a.myext
   ·       ─────────┬────────
   ·                ╰── No command found to start with this path
   ╰────
  help: Try different path or install appropriate command

        Command `cmd /c start "" "..\nustart\a.myext"` failed with exit code: 1

@sholderbach
Copy link
Copy Markdown
Member

Awesome looks good! That empty string in the example still looks a bit weird but as it is a failure... hey)

@sholderbach sholderbach merged commit 9e1e2a4 into nushell:main Sep 12, 2023
@geniusisme geniusisme deleted the gi/env-in-start branch September 12, 2023 12:07
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Dec 14, 2023
fixes nushell#8551

# Description
Use `open::commands` function to get list of command available for
starting given path. run commands directly, providing environment, until
one of them is successful.

example of output if start was not successful:
```
~\code\nushell> start ..\nustart\a.myext                                                                    09/12/2023 01:37:55 PM
Error: nu::shell::external_command

  × External command failed
   ╭─[entry #1:1:1]
 1 │ start ..\nustart\a.myext
   ·       ─────────┬────────
   ·                ╰── No command found to start with this path
   ╰────
  help: Try different path or install appropriate command

        Command `cmd /c start "" "..\nustart\a.myext"` failed with exit code: 1
```

# User-Facing Changes
`start` command now provides environment to the external command. This
is how it worked in `nu 0.72`, see linked issue.

# Tests + Formatting
`start` command didn't have any tests and this PR does not add any.
Integration-level tests will require setup specific to OS and
potentially change global environment on testing machine. For unit-level
test it is possible to test `try_commands` function. But is still runs
external commands, and robust test will require apriori knowledge which
commands are necessary successful to run and which are not.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform:windows Issues which are specific to Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nushell no longer provides environment for "start" command in windows

3 participants