Skip to content

Commit

Permalink
fix: Arguments to Options
Browse files Browse the repository at this point in the history
  • Loading branch information
gnios committed Nov 21, 2024
1 parent e21693b commit da423b3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Gnios.Cli/Commands/AzureDevops/AzureDevopsRootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public AzureDevopsRootCommand(AppConfiguration appConfig)
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

var syncCommand = new SyncCommand(baseDirectory, appConfig);
var searchCommand = new SearchCommand(baseDirectory, appConfig, syncCommand);
var searchCommand = new SearchCommand(baseDirectory, syncCommand);
AddCommand(syncCommand);
AddCommand(searchCommand);
}
Expand Down
22 changes: 19 additions & 3 deletions Gnios.Cli/Commands/AzureDevops/SearchCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.IO;
using System.CommandLine.NamingConventionBinder;
using System.Text.RegularExpressions;
using ConsoleTables;
Expand All @@ -12,13 +14,27 @@ public class SearchCommand : Command
{
private readonly SyncCommand _syncCommand;

public SearchCommand(string baseDirectory, AppConfiguration appConfig, SyncCommand syncCommand)
public SearchCommand(string baseDirectory, SyncCommand syncCommand)
: base("search", "Search for a variable group and variables")
{
_syncCommand = syncCommand;
AddArgument(new Argument<string>("variableGroupName", "The name of the variable group to search for"));
AddArgument(new Argument<string>("variableName", () => string.Empty, "The name of the variable to search for"));
AddOption(new Option<string>( new[] { "-vg", "--variableGroup" }, "VariableGroupName: The name of the variable group to search for"));
AddOption(new Option<string>(new[] { "-vn", "--variableName" }, () => string.Empty, "VariableName: The name of the variable to search for"));
Handler = CommandHandler.Create<string, string>(async (variableGroupName, variableName) => await SearchVariableGroupAndVariables(variableGroupName, variableName, baseDirectory));

Handler = CommandHandler.Create<string, string, InvocationContext>(async (variableGroup, variableName, context) =>
{
if (string.IsNullOrEmpty(variableGroup))
{
context.Console.Out.WriteLine("Options are required. Showing help:");
string[] args = ["-?"];
await this.InvokeAsync(args);
}
else
{
await SearchVariableGroupAndVariables(variableGroup, variableName, baseDirectory);
}
});
}

private async Task SearchVariableGroupAndVariables(
Expand Down
4 changes: 2 additions & 2 deletions Gnios.Cli/ConsoleApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public async Task<int> Run(string[] args)
new AzureDevopsRootCommand(_appConfig)
};

// string[] debugArgs = {"configure"};
// return await rootCommand.InvokeAsync(debugArgs);
string[] debugArgs = {"devops","search", "-vg", "MyVariableGroup", "-vn", "MyVariableName"};
return await rootCommand.InvokeAsync(debugArgs);
return await rootCommand.InvokeAsync(args);

Check warning on line 30 in Gnios.Cli/ConsoleApplication.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected

Check warning on line 30 in Gnios.Cli/ConsoleApplication.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected

Check warning on line 30 in Gnios.Cli/ConsoleApplication.cs

View workflow job for this annotation

GitHub Actions / build

Unreachable code detected
}
}
1 change: 1 addition & 0 deletions Gnios.Cli/Gnios.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<Nullable>enable</Nullable>
<Version>0.1.0</Version>
<SelfContained>true</SelfContained>
<AssemblyName>Gnios</AssemblyName>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)' != 'Debug'">
Expand Down
11 changes: 11 additions & 0 deletions Gnios.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Gnios.Cli": {
"commandName": "Project",
"environmentVariables": {

}
}
}
}

0 comments on commit da423b3

Please sign in to comment.