From f10d73dfb5ca9b9bd20c79801b18db82bfa39a85 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 26 Feb 2024 11:57:21 +0100 Subject: [PATCH] Explain how to use printenv more safely (#1585) --- src/alr/alr-commands-printenv.adb | 12 ++++++++++-- src/alr/alr-commands.adb | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/alr/alr-commands-printenv.adb b/src/alr/alr-commands-printenv.adb index 89d06be8..af986ec7 100644 --- a/src/alr/alr-commands-printenv.adb +++ b/src/alr/alr-commands-printenv.adb @@ -65,9 +65,17 @@ package body Alr.Commands.Printenv is " This command can be used to setup a build environment," & " for instance before starting an IDE.") .New_Line + .Append ("When using " & TTY.Terminal ("alr printenv") & " in scripts, " + & "to ensure no unwanted output is intermixed with the environment " + & "definitions, the recommendation is to run it twice and and use the " + & "output of the second run in quiet non-interactive mode. This is " + & "because running " & TTY.Terminal ("alr printenv") & " after " + & "manifest editions may trigger an automatic synchronization that " + & "could produce extra output not intended as environment variables.") + .New_line .Append ("Examples:") - .Append (" - eval $(alr printenv --unix)") - .Append (" - alr printenv --powershell | Invoke-Expression") + .Append (" - eval $(alr -n -q printenv --unix)") + .Append (" - alr -n -q printenv --powershell | Invoke-Expression") ); -------------------- diff --git a/src/alr/alr-commands.adb b/src/alr/alr-commands.adb index b3f2dddf..3917bdf6 100644 --- a/src/alr/alr-commands.adb +++ b/src/alr/alr-commands.adb @@ -315,9 +315,11 @@ package body Alr.Commands is end if; -- Unless the command is precisely to configure the toolchain, ask the - -- user for its preference at this time. + -- user for its preference at this time. We also don't ask during `alr + -- printenv`, whose output is likely being redirected. if Cmd not in Commands.Toolchain.Command'Class and then + Cmd not in Commands.Printenv.Command'Class and then Alire.Toolchains.Assistant_Enabled then Alire.Toolchains.Assistant (Conf.Global, First_Run => True); -- 2.39.5