Skip to content

Commit 3a7fa27

Browse files
committed
feat: Support multiple commands and --libusb option
Change command-line parsing to collect multiple commands with their own argument lists instead of treating all remaining args as one command. Commands and their args are stored in a pendingCommands list and executed sequentially; help is shown if no commands were provided. Add a --libusb flag to set UsbManager.ForceLibUsb. Preserve exception handling and debug logging for each command execution.
1 parent aec0ae1 commit 3a7fa27

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

FastbootCLI/Program.cs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ static void Main(string[] args)
2121
if (args.Length == 0) { ShowHelp(); return; }
2222

2323
int i = 0;
24-
List<string> commandArgs = new List<string>();
24+
List<(string Command, List<string> Args)> pendingCommands = new List<(string, List<string>)>();
25+
2526
while (i < args.Length)
2627
{
2728
string arg = args[i++];
@@ -43,23 +44,43 @@ static void Main(string[] args)
4344
sparseLimit = ParseSize(sizeStr);
4445
}
4546
else if (arg == "--debug") FastbootDebug.IsEnabled = true;
47+
else if (arg == "--libusb") UsbManager.ForceLibUsb = true;
4648
else if (arg == "--version" || arg == "version") { Console.WriteLine("fastboot version 1.2.5"); return; }
4749
else if (arg == "-h" || arg == "--help" || arg == "help") { ShowHelp(); return; }
4850
else if (!arg.StartsWith("-"))
4951
{
52+
// This is a command (like 'devices', 'flash', 'getvar')
5053
string command = arg;
51-
commandArgs = args.Skip(i).ToList();
52-
try { ExecuteCommand(command, commandArgs); }
53-
catch (Exception ex)
54+
55+
// Collect arguments for this specific command until next arg starting with '-'
56+
List<string> commandArgs = new List<string>();
57+
while (i < args.Length && !args[i].StartsWith("-"))
5458
{
55-
if (FastbootDebug.IsEnabled) Console.Error.WriteLine("[DEBUG] Exception: " + ex);
56-
Console.Error.WriteLine("fastboot: error: " + ex.Message);
57-
Environment.Exit(1);
59+
commandArgs.Add(args[i++]);
5860
}
59-
return;
61+
pendingCommands.Add((command, commandArgs));
62+
}
63+
}
64+
65+
if (pendingCommands.Count == 0)
66+
{
67+
ShowHelp();
68+
return;
69+
}
70+
71+
foreach (var cmd in pendingCommands)
72+
{
73+
try
74+
{
75+
ExecuteCommand(cmd.Command, cmd.Args);
76+
}
77+
catch (Exception ex)
78+
{
79+
if (FastbootDebug.IsEnabled) Console.Error.WriteLine("[DEBUG] Exception: " + ex);
80+
Console.Error.WriteLine("fastboot: error: " + ex.Message);
81+
Environment.Exit(1);
6082
}
6183
}
62-
ShowHelp();
6384
}
6485

6586
static long ParseSize(string sizeStr)

0 commit comments

Comments
 (0)