Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/dnvm/CommandLineArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]
Expand Down
11 changes: 8 additions & 3 deletions src/dnvm/SelfInstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public sealed record Options
/// Skip channel tracking and SDK installation during self-install.
/// </summary>
public bool SkipTracking { get; init; } = false;
/// <summary>
/// Skip modifying shell profiles and the user environment during self-install.
/// </summary>
public bool SkipEnv { get; init; } = false;
}

private readonly DnvmEnv _env;
Expand All @@ -64,7 +68,8 @@ public static Task<Result> 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
});
}

Expand Down Expand Up @@ -150,7 +155,7 @@ public static async Task<Result> 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]> ");
Expand Down Expand Up @@ -226,7 +231,7 @@ public async Task<Result> 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);
}
Expand Down
24 changes: 24 additions & 0 deletions test/IntegrationTests/SelfInstallTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
{
Expand Down
5 changes: 4 additions & 1 deletion test/UnitTests/CommandLineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ public void SelfInstallHelp(string param)
[ "selfinstall", param ]));
Assert.Equal("""
usage: dnvm selfinstall [-v | --verbose] [-f | --force] [--feed-url <feedUrl>]
[-y] [--update] [--dest-path <destPath>] [--skip-tracking] [-h | --help]
[-y] [--update] [--dest-path <destPath>] [--skip-tracking] [--skip-env] [-h |
--help]

Install dnvm to the local machine.

Expand All @@ -335,6 +336,8 @@ Install dnvm to the local machine.
be called from dnvm.
--dest-path <destPath> 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.

Expand Down
Loading