GitAuto: [FEATURE] Add Command to Set Environment Variable #67
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #38
What is the feature
The feature is a new command for a .NET tool project that allows users to set environment variables via the command-line interface (CLI). The command will accept two arguments: the variable value (required) and an optional target specifying where the variable should be set (
User
orMachine
scope).Why we need the feature
This feature is needed to simplify environment setup, especially in CI/CD pipelines or automated scripts. It provides flexibility by allowing users to specify the target scope (User or Machine) for the environment variable, making it easier to manage environment configurations programmatically.
How to implement and why
Create a new command in the CLI tool:
Environment.SetEnvironmentVariable
method to set the variable, with the target defaulting toUser
if not specified.Handle input validation:
VAR_NAME=value
).User
orMachine
.Implement platform-specific logic:
EnvironmentVariableTarget
.Provide feedback to the user:
Update documentation:
About backward compatibility
This feature is an addition and does not affect existing functionality, so backward compatibility is maintained. The default behavior of setting the environment variable for the current user ensures that existing workflows remain unchanged unless explicitly modified by the user.
Test these changes locally