Skip to content

Commit

Permalink
Update args replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
calebkiage committed Nov 1, 2023
1 parent 5b3c1a2 commit 1a0f0e9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.CommandLine.Parsing;
using System.Diagnostics.Tracing;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
Expand Down Expand Up @@ -43,16 +44,21 @@ class Program
static async Task<int> Main(string[] args)
{
// Replace `me ...` with `users ... --user-id me`
if (args[0] == "me") {
var newArgs = new string[args.Length + 2];
if (args[0] == "me")
{
var hasHelp = args.Any(static x => x.Contains("-h") || x.Contains("/?"));
var newArgs = hasHelp ? args : new string[args.Length + 2];
newArgs[0] = "users";
for (int i = 1; i < args.Length; i++)
{
newArgs[i] = args[i];
}
newArgs[args.Length] = "--user-id";
newArgs[args.Length + 1] = "me";
args = newArgs;
if (newArgs.Length > args.Length)
{
newArgs[args.Length] = "--user-id";
newArgs[args.Length + 1] = "me";
args = newArgs;
}
}

var builder = BuildCommandLine()
Expand Down

0 comments on commit 1a0f0e9

Please sign in to comment.