Skip to content

Commit

Permalink
Update src/dotnet_mytool/Program.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
gitauto-ai[bot] authored Nov 18, 2024
1 parent ec7033f commit 1828819
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/dotnet_mytool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ static int Main(string[] args)
new Argument<string>("variable", "The environment variable in the format VAR_NAME=value"),
new Option<string>("--target", () => "User", "The target scope: User or Machine")
};
setEnvCommand.Handler = CommandHandler.Create<string, string>((variable, target) =>
{
var parts = variable.Split('=');
if (parts.Length != 2)

Check failure on line 20 in src/dotnet_mytool/Program.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/dotnet_mytool/Program.cs#L20

Add curly braces around the nested statement(s) in this 'if' block.

static void SetEnvironmentVariable(string variable, string value, string target)
{
EnvironmentVariableTarget envTarget = target.Equals("Machine", StringComparison.OrdinalIgnoreCase)
? EnvironmentVariableTarget.Machine
: EnvironmentVariableTarget.User;

Environment.SetEnvironmentVariable(variable, value, envTarget);
Console.WriteLine($"Environment variable {variable} set to {value} for {target}.");
}
{

Check warning on line 31 in src/dotnet_mytool/Program.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/dotnet_mytool/Program.cs#L31

This line will not be executed conditionally; only the first line of this 10-line block will be. The rest will execute unconditionally.
Console.WriteLine("Invalid format. Use VAR_NAME=value.");
return;
}

rootCommand.AddCommand(setEnvCommand);

Expand Down

0 comments on commit 1828819

Please sign in to comment.