diff --git a/src/dnvm/CommandLineArguments.cs b/src/dnvm/CommandLineArguments.cs
index cd67f14..f61efe0 100644
--- a/src/dnvm/CommandLineArguments.cs
+++ b/src/dnvm/CommandLineArguments.cs
@@ -105,6 +105,9 @@ public sealed partial record SelfInstallArgs : DnvmSubCommand
[CommandOption("--skip-tracking", Description = "Skip channel tracking and SDK installation during self-install.")]
public bool? SkipTracking { get; init; } = null;
+
+ [CommandOption("--skip-env", Description = "Skip modifying shell profiles and user environment during self-install.")]
+ public bool? SkipEnv { get; init; } = null;
}
[Command("update", Summary = "Update the installed SDKs or dnvm itself.")]
diff --git a/src/dnvm/SelfInstallCommand.cs b/src/dnvm/SelfInstallCommand.cs
index 81e2ba0..04d4e44 100644
--- a/src/dnvm/SelfInstallCommand.cs
+++ b/src/dnvm/SelfInstallCommand.cs
@@ -40,6 +40,10 @@ public sealed record Options
/// Skip channel tracking and SDK installation during self-install.
///
public bool SkipTracking { get; init; } = false;
+ ///
+ /// Skip modifying shell profiles and the user environment during self-install.
+ ///
+ public bool SkipEnv { get; init; } = false;
}
private readonly DnvmEnv _env;
@@ -64,7 +68,8 @@ public static Task Run(DnvmEnv env, Logger logger, DnvmSubCommand.SelfIn
Yes = args.Yes ?? false,
Update = args.Update ?? false,
DestPath = args.DestPath,
- SkipTracking = args.SkipTracking ?? false
+ SkipTracking = args.SkipTracking ?? false,
+ SkipEnv = args.SkipEnv ?? false
});
}
@@ -150,7 +155,7 @@ public static async Task Run(DnvmEnv env, Logger logger, Options opt)
var updateUserEnv = true;
var sdkDirName = DnvmEnv.DefaultSdkDirName;
- if (!opt.Yes && MissingFromEnv(env, sdkDirName))
+ if (!opt.SkipEnv && !opt.Yes && MissingFromEnv(env, sdkDirName))
{
console.WriteLine("One or more paths are missing from the user environment. Attempt to update the user environment?");
console.Write("[Y/n]> ");
@@ -226,7 +231,7 @@ public async Task Run(string targetPath, Channel channel, SdkDirName new
SelectCommand.SelectDir(_logger, _env, oldDirName, newDirName);
// Set up path
- if (updateUserEnv)
+ if (updateUserEnv && !_opts.SkipEnv)
{
await UpdateEnv(_logger, _env, newDirName);
}
diff --git a/test/IntegrationTests/SelfInstallTests.cs b/test/IntegrationTests/SelfInstallTests.cs
index fc72950..2b5dd4e 100644
--- a/test/IntegrationTests/SelfInstallTests.cs
+++ b/test/IntegrationTests/SelfInstallTests.cs
@@ -79,6 +79,30 @@ public Task SelfInstallSkipTracking() => RunWithServer(async (mockServer, env) =
}
});
+ [ConditionalFact(typeof(UnixOnly))]
+ public Task SelfInstallSkipEnv() => RunWithServer(async (mockServer, env) =>
+ {
+ var zshrcPath = Path.Combine(env.UserHome, ".zshrc");
+ const string initialZshrcContent = "# Existing zsh config";
+ await File.WriteAllTextAsync(zshrcPath, initialZshrcContent);
+
+ var procResult = await DnvmRunner.RunAndRestoreEnv(
+ env,
+ DnvmExe,
+ $"selfinstall --feed-url {mockServer.PrefixString} -y -v --skip-env"
+ );
+
+ _testOutput.WriteLine(procResult.Out);
+ _testOutput.WriteLine(procResult.Error);
+ Assert.Equal(0, procResult.ExitCode);
+
+ var dnvmPath = env.DnvmHomeFs.ConvertPathToInternal(DnvmEnv.DnvmExePath);
+ Assert.True(File.Exists(dnvmPath));
+ Assert.False(env.DnvmHomeFs.FileExists(DnvmEnv.EnvPath));
+ Assert.Equal(initialZshrcContent, await File.ReadAllTextAsync(zshrcPath));
+ Assert.DoesNotContain("Scanning for shell files", procResult.Out);
+ });
+
[ConditionalFact(typeof(UnixOnly))]
public async Task SelfInstallDialog() => await RunWithServer(async (mockServer, env) =>
{
diff --git a/test/UnitTests/CommandLineTests.cs b/test/UnitTests/CommandLineTests.cs
index b36359c..85f8ddf 100644
--- a/test/UnitTests/CommandLineTests.cs
+++ b/test/UnitTests/CommandLineTests.cs
@@ -322,7 +322,8 @@ public void SelfInstallHelp(string param)
[ "selfinstall", param ]));
Assert.Equal("""
usage: dnvm selfinstall [-v | --verbose] [-f | --force] [--feed-url ]
-[-y] [--update] [--dest-path ] [--skip-tracking] [-h | --help]
+[-y] [--update] [--dest-path ] [--skip-tracking] [--skip-env] [-h |
+--help]
Install dnvm to the local machine.
@@ -335,6 +336,8 @@ Install dnvm to the local machine.
be called from dnvm.
--dest-path Set the destination path for the dnvm executable.
--skip-tracking Skip channel tracking and SDK installation during
+self-install.
+ --skip-env Skip modifying shell profiles and user environment during
self-install.
-h, --help Show help information.