mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Use execution context splitting on args
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using SabreTools.Core;
|
||||
using SabreTools.Features;
|
||||
using SabreTools.Help;
|
||||
@@ -38,6 +39,9 @@ namespace SabreTools
|
||||
LoggerImpl.ThrowOnError = false;
|
||||
LoggerImpl.Start();
|
||||
|
||||
// Reformat the arguments
|
||||
args = ReformatArguments(args);
|
||||
|
||||
// Create a new Help object for this program
|
||||
_help = RetrieveHelp();
|
||||
|
||||
@@ -150,6 +154,27 @@ namespace SabreTools
|
||||
return;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reformat arguments incorrectly split in quotes
|
||||
/// </summary>
|
||||
private static string[] ReformatArguments(string[] args)
|
||||
{
|
||||
// Handle empty arguments
|
||||
if (args.Length == 0)
|
||||
return args;
|
||||
|
||||
// Recombine arguments using a single space
|
||||
string argsString = string.Join(" ", args).Trim();
|
||||
|
||||
// Split the string using Regex
|
||||
var matches = Regex.Matches(argsString, @"([a-zA-Z0-9\-]*=)?[\""].+?[\""]|[^ ]+", RegexOptions.Compiled);
|
||||
|
||||
// Get just the values from the matches
|
||||
var matchArr = new Match[matches.Count];
|
||||
matches.CopyTo(matchArr, 0);
|
||||
return Array.ConvertAll(matchArr, m => m.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a Help object for this program
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user