-
Notifications
You must be signed in to change notification settings - Fork 3
Collect environment #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
1c9363c
742f554
709e8c4
6375955
c3a8c03
331051f
649b880
d7a3a56
4ce1f53
6eeac63
9309643
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,4 +83,59 @@ public IEnumerable<ICommandDescription> GetAllCommands() | |
| { | ||
| return new List<ICommandDescription>(_commands.Values); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public IControllerEnvironmentContext GetEnvironment(ICommandFactory commandFactory) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(commandFactory); | ||
|
|
||
| var controllerEnvironment = new ControllerEnvironmentContext(); | ||
| foreach (var commandDescription in GetAllCommands()) | ||
| { | ||
| ApplyDefaultEnvironment(controllerEnvironment, commandDescription, commandFactory); | ||
| } | ||
|
|
||
| return controllerEnvironment; | ||
| } | ||
|
|
||
| private static void ApplyDefaultEnvironment(IControllerEnvironmentContext controllerEnvironment, ICommandDescription commandDescription, ICommandFactory commandFactory, int depth = 0) | ||
| { | ||
| depth++; | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(commandDescription.FullTypeName)) | ||
| { | ||
| AddCommandDefaults(controllerEnvironment, commandDescription, commandFactory); | ||
| } | ||
|
|
||
| if (commandDescription.SubCommands.Count == 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (depth > 1) return; | ||
| foreach (var subCommand in commandDescription.SubCommands.Values) | ||
| { | ||
| AddCommandDefaults(controllerEnvironment, subCommand, commandFactory); | ||
| } | ||
| } | ||
|
Comment on lines
101
to
117
|
||
|
|
||
| private static void AddCommandDefaults(IControllerEnvironmentContext controllerEnvironment, ICommandDescription commandDescription, ICommandFactory commandFactory) | ||
| { | ||
| var commandInstance = commandFactory.CreateCommand(commandDescription.FullTypeName, commandDescription.PackageDescription.FullPath); | ||
| try | ||
| { | ||
| var defaultEnvironment = commandInstance.GetDefaultEnvironment(); | ||
| if (defaultEnvironment.Count == 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var commandName = NamesValidator.GetValidCommandName(commandDescription.BaseCommand); | ||
| controllerEnvironment.UpdateEnvironment(defaultEnvironment, commandName); | ||
| } | ||
| finally | ||
| { | ||
| commandInstance.DisposeAsync().AsTask().GetAwaiter().GetResult(); | ||
Xcaciv marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -149,17 +149,28 @@ public Dictionary<string, string> GetEnvironment() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// environment variables are returned.</param> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// <returns>A dictionary containing the environment variables for the specified command name. Returns an empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// dictionary if the command name does not exist in the command environment.</returns> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public Dictionary<string, string> GetEnvironment(string commandName) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public Dictionary<string, string> GetEnvironment(string commandName, bool prefix = true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (String.IsNullOrEmpty(commandName)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return this._environment.GetEnvironment(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return _commandEnvironment.TryGetValue(commandName, out var commandEnv) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? new Dictionary<string, string>(commandEnv) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : new Dictionary<string, string>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (_commandEnvironment.TryGetValue(commandName, out var commandEnv)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!prefix) return commandEnv.ToDictionary(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Add command prefix to keys when retrieving | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var commandPrefix = string.Concat(commandName, "_"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foreach (var (key, value) in commandEnv) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var prefixedKey = key.StartsWith(commandPrefix, StringComparison.OrdinalIgnoreCase) ? key : commandPrefix + key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result[prefixedKey] = value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new Dictionary<string, string>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!prefix) return commandEnv.ToDictionary(); | |
| // Add command prefix to keys when retrieving | |
| var commandPrefix = string.Concat(commandName, "_"); | |
| var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |
| foreach (var (key, value) in commandEnv) | |
| { | |
| var prefixedKey = key.StartsWith(commandPrefix, StringComparison.OrdinalIgnoreCase) ? key : commandPrefix + key; | |
| result[prefixedKey] = value; | |
| } | |
| return result; | |
| } | |
| return new Dictionary<string, string>(); | |
| if (!prefix) | |
| { | |
| var result = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |
| foreach (var environmentEntry in commandEnv) | |
| { | |
| result[environmentEntry.Key] = environmentEntry.Value; | |
| } | |
| return result; | |
| } | |
| // Add command prefix to keys when retrieving | |
| var commandPrefix = string.Concat(commandName, "_"); | |
| var resultWithPrefix = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); | |
| foreach (var (key, value) in commandEnv) | |
| { | |
| var prefixedKey = key.StartsWith(commandPrefix, StringComparison.OrdinalIgnoreCase) ? key : commandPrefix + key; | |
| resultWithPrefix[prefixedKey] = value; | |
| } | |
| return resultWithPrefix; | |
| } | |
| return new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); |
Outdated
Copilot
AI
Feb 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XML remarks for UpdateEnvironment(Dictionary<string,string>, string commandName) still describe splitting updates into command-specific (prefixed) vs shared/global, but the implementation now stores all keys in the command-specific dictionary and never updates _environment. Please update the documentation to match the new behavior, or restore the prior behavior if shared/global updates are still intended.
Uh oh!
There was an error while loading. Please reload this page.