mirror of
https://github.com/whoeevee/ivinject.git
synced 2026-01-08 23:25:03 +00:00
migration to System.CommandLine 2.0.0-beta5+
This commit is contained in:
@@ -12,123 +12,117 @@ internal class IviRootCommand : RootCommand
|
||||
var value = result.Tokens[0].Value;
|
||||
|
||||
if (!RegularExpressions.ApplicationPackage().IsMatch(value))
|
||||
result.ErrorMessage = "The application package must be either an .app bundle or an .ipa$ archive.";
|
||||
result.AddError("The application package must be either an .app bundle or an .ipa$ archive.");
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
private readonly Argument<string> _targetArgument = new(
|
||||
name: "target",
|
||||
description: "The application package, either .app bundle or ipa$",
|
||||
parse: ParseAppPackageResult
|
||||
);
|
||||
private readonly Argument<string> _targetArgument = new("target")
|
||||
{
|
||||
Description = "The application package, either .app bundle or ipa$",
|
||||
CustomParser = ParseAppPackageResult
|
||||
};
|
||||
|
||||
private readonly Argument<string> _outputArgument = new(
|
||||
name: "output",
|
||||
description: "The output application package, either .app bundle or ipa$",
|
||||
parse: ParseAppPackageResult
|
||||
);
|
||||
private readonly Argument<string> _outputArgument = new("output")
|
||||
{
|
||||
Description = "The output application package, either .app bundle or ipa$",
|
||||
CustomParser = ParseAppPackageResult
|
||||
};
|
||||
|
||||
private readonly Option<bool> _overwriteOutputOption = new(
|
||||
"--overwrite",
|
||||
"Overwrite the output if it already exists"
|
||||
);
|
||||
private readonly Option<bool> _overwriteOutputOption = new("--overwrite")
|
||||
{
|
||||
Description = "Overwrite the output if it already exists"
|
||||
};
|
||||
|
||||
private readonly Option<CompressionLevel> _compressionLevelOption = new(
|
||||
"--compression-level",
|
||||
description: "The compression level for ipa$ archive output",
|
||||
getDefaultValue: () => CompressionLevel.Fastest
|
||||
);
|
||||
private readonly Option<CompressionLevel> _compressionLevelOption = new("--compression-level")
|
||||
{
|
||||
Aliases = { "--level" },
|
||||
Description = "The compression level for ipa$ archive output",
|
||||
DefaultValueFactory = _ => CompressionLevel.Fastest
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
private readonly Option<IEnumerable<FileInfo>> _itemsOption = new("--items")
|
||||
{
|
||||
Description = "The entries to inject (Debian packages, Frameworks, and Bundles)",
|
||||
Aliases = { "-i" },
|
||||
AllowMultipleArgumentsPerToken = true
|
||||
};
|
||||
|
||||
private readonly Option<FileInfo> _provisioningProfileOption = new(
|
||||
"--profile",
|
||||
"Provisioning profile to extract entitlements, signing identity, and bundle ID"
|
||||
);
|
||||
private readonly Option<FileInfo> _provisioningProfileOption = new("--profile")
|
||||
{
|
||||
Aliases = { "-p" },
|
||||
Description = "Provisioning profile to extract entitlements, signing identity, and bundle ID"
|
||||
};
|
||||
|
||||
private readonly Option<bool> _profileBundleIdOption = new(
|
||||
"--profile-bundle-id",
|
||||
"Replace the bundle ID with the one in the provisioning profile"
|
||||
);
|
||||
private readonly Option<bool> _profileBundleIdOption = new("--profile-bundle-id")
|
||||
{
|
||||
Description = "Replace the bundle ID with the one in the provisioning profile"
|
||||
};
|
||||
|
||||
private readonly Option<string> _codesignIdentityOption = new(
|
||||
"--sign",
|
||||
"The identity for code signing (use \"-\" for ad hoc, a.k.a. fake signing)"
|
||||
);
|
||||
private readonly Option<string> _codesignIdentityOption = new("--sign")
|
||||
{
|
||||
Aliases = { "-s" },
|
||||
Description = "The identity for code signing (use \"-\" for ad hoc, a.k.a. fake signing)"
|
||||
};
|
||||
|
||||
private readonly Option<FileInfo> _codesignEntitlementsOption = new(
|
||||
"--entitlements",
|
||||
"The file containing entitlements that will be written into main executables"
|
||||
);
|
||||
private readonly Option<FileInfo> _codesignEntitlementsOption = new("--entitlements")
|
||||
{
|
||||
Aliases = { "-e" },
|
||||
Description = "The file containing entitlements that will be written into main executables"
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
private readonly Option<string> _customBundleIdOption = new(
|
||||
"--bundle-id",
|
||||
"The custom identifier that will be applied to application bundles"
|
||||
);
|
||||
private readonly Option<string> _customBundleIdOption = new("--bundle-id")
|
||||
{
|
||||
Aliases = { "-b" },
|
||||
Description = "The custom identifier that will be applied to application bundles"
|
||||
};
|
||||
|
||||
private readonly Option<bool> _enableDocumentsSupportOption = new(
|
||||
"--enable-documents-support",
|
||||
"Enables documents support (file sharing) for the application"
|
||||
);
|
||||
private readonly Option<bool> _enableDocumentsSupportOption = new("--enable-documents-support")
|
||||
{
|
||||
Aliases = { "-d" },
|
||||
Description = "Enables documents support (file sharing) for the application"
|
||||
};
|
||||
|
||||
private readonly Option<bool> _removeSupportedDevicesOption = new(
|
||||
"--remove-supported-devices",
|
||||
"Removes supported devices property"
|
||||
);
|
||||
private readonly Option<bool> _removeSupportedDevicesOption = new("--remove-supported-devices")
|
||||
{
|
||||
Aliases = { "-u" },
|
||||
Description = "Removes supported devices property"
|
||||
};
|
||||
|
||||
private readonly Option<IEnumerable<string>> _directoriesToRemoveOption = new("--remove-directories")
|
||||
{
|
||||
Aliases = { "-r" },
|
||||
Description = "Directories to remove in the app package, e.g. PlugIns, Watch, AppClip",
|
||||
AllowMultipleArgumentsPerToken = true
|
||||
};
|
||||
|
||||
internal IviRootCommand() : base("The most demure iOS app injector and signer")
|
||||
{
|
||||
_itemsOption.AddAlias("-i");
|
||||
Arguments.Add(_targetArgument);
|
||||
Arguments.Add(_outputArgument);
|
||||
Options.Add(_overwriteOutputOption);
|
||||
Options.Add(_compressionLevelOption);
|
||||
|
||||
_provisioningProfileOption.AddAlias("-p");
|
||||
_codesignIdentityOption.AddAlias("-s");
|
||||
_codesignEntitlementsOption.AddAlias("-e");
|
||||
_compressionLevelOption.AddAlias("--level");
|
||||
Options.Add(_itemsOption);
|
||||
Options.Add(_provisioningProfileOption);
|
||||
Options.Add(_profileBundleIdOption);
|
||||
Options.Add(_codesignIdentityOption);
|
||||
Options.Add(_codesignEntitlementsOption);
|
||||
|
||||
_customBundleIdOption.AddAlias("-b");
|
||||
_enableDocumentsSupportOption.AddAlias("-d");
|
||||
_removeSupportedDevicesOption.AddAlias("-u");
|
||||
_directoriesToRemoveOption.AddAlias("-r");
|
||||
Options.Add(_customBundleIdOption);
|
||||
Options.Add(_enableDocumentsSupportOption);
|
||||
Options.Add(_removeSupportedDevicesOption);
|
||||
Options.Add(_directoriesToRemoveOption);
|
||||
|
||||
AddArgument(_targetArgument);
|
||||
AddArgument(_outputArgument);
|
||||
AddOption(_overwriteOutputOption);
|
||||
AddOption(_compressionLevelOption);
|
||||
|
||||
AddOption(_itemsOption);
|
||||
AddOption(_provisioningProfileOption);
|
||||
AddOption(_profileBundleIdOption);
|
||||
AddOption(_codesignIdentityOption);
|
||||
AddOption(_codesignEntitlementsOption);
|
||||
|
||||
AddOption(_customBundleIdOption);
|
||||
AddOption(_enableDocumentsSupportOption);
|
||||
AddOption(_removeSupportedDevicesOption);
|
||||
AddOption(_directoriesToRemoveOption);
|
||||
|
||||
this.SetHandler(async (iviParameters, loggerFactory) =>
|
||||
SetAction(async parseResult =>
|
||||
{
|
||||
var commandProcessor = new IviRootCommandProcessor(loggerFactory);
|
||||
await commandProcessor.ProcessRootCommand(iviParameters);
|
||||
},
|
||||
new IviRootCommandParametersBinder(
|
||||
var binder = new IviRootCommandParametersBinder(
|
||||
_targetArgument,
|
||||
_outputArgument,
|
||||
_overwriteOutputOption,
|
||||
@@ -142,8 +136,11 @@ internal class IviRootCommand : RootCommand
|
||||
_enableDocumentsSupportOption,
|
||||
_removeSupportedDevicesOption,
|
||||
_directoriesToRemoveOption
|
||||
),
|
||||
new LoggerFactoryBinder()
|
||||
);
|
||||
var iviParameters = binder.GetBoundValue(parseResult);
|
||||
var commandProcessor = new IviRootCommandProcessor();
|
||||
await commandProcessor.ProcessRootCommand(iviParameters);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Binding;
|
||||
using System.IO.Compression;
|
||||
using ivinject.Features.Command.Models;
|
||||
using ivinject.Features.Injection.Models;
|
||||
@@ -20,38 +19,39 @@ internal class IviRootCommandParametersBinder(
|
||||
Option<bool> enableDocumentsSupportOption,
|
||||
Option<bool> removeSupportedDevicesOption,
|
||||
Option<IEnumerable<string>> directoriesToRemoveOption
|
||||
) : BinderBase<IviParameters>
|
||||
)
|
||||
{
|
||||
protected override IviParameters GetBoundValue(BindingContext bindingContext)
|
||||
public IviParameters GetBoundValue(ParseResult parseResult)
|
||||
{
|
||||
var targetAppPackage =
|
||||
bindingContext.ParseResult.GetValueForArgument(targetArgument);
|
||||
parseResult.GetValue(targetArgument)!;
|
||||
var outputAppPackage =
|
||||
bindingContext.ParseResult.GetValueForArgument(outputArgument);
|
||||
parseResult.GetValue(outputArgument)!;
|
||||
|
||||
var overwriteOutput =
|
||||
bindingContext.ParseResult.GetValueForOption(overwriteOutputOption);
|
||||
parseResult.GetValue(overwriteOutputOption);
|
||||
var compressionLevel =
|
||||
bindingContext.ParseResult.GetValueForOption(compressionLevelOption);
|
||||
parseResult.GetValue(compressionLevelOption);
|
||||
|
||||
var items =
|
||||
bindingContext.ParseResult.GetValueForOption(itemsOption);
|
||||
parseResult.GetValue(itemsOption);
|
||||
var provisioningProfile =
|
||||
bindingContext.ParseResult.GetValueForOption(provisioningProfileOption);
|
||||
parseResult.GetValue(provisioningProfileOption);
|
||||
var profileBundleId =
|
||||
bindingContext.ParseResult.GetValueForOption(profileBundleIdOption);
|
||||
parseResult.GetValue(profileBundleIdOption);
|
||||
var codesignIdentity =
|
||||
bindingContext.ParseResult.GetValueForOption(codesignIdentityOption);
|
||||
parseResult.GetValue(codesignIdentityOption);
|
||||
var codesignEntitlements =
|
||||
bindingContext.ParseResult.GetValueForOption(codesignEntitlementsOption);
|
||||
parseResult.GetValue(codesignEntitlementsOption);
|
||||
|
||||
var customBundleId =
|
||||
bindingContext.ParseResult.GetValueForOption(customBundleIdOption);
|
||||
parseResult.GetValue(customBundleIdOption);
|
||||
var enableDocumentsSupport =
|
||||
bindingContext.ParseResult.GetValueForOption(enableDocumentsSupportOption);
|
||||
parseResult.GetValue(enableDocumentsSupportOption);
|
||||
var removeSupportedDevices =
|
||||
bindingContext.ParseResult.GetValueForOption(removeSupportedDevicesOption);
|
||||
parseResult.GetValue(removeSupportedDevicesOption);
|
||||
var directoriesToRemove =
|
||||
bindingContext.ParseResult.GetValueForOption(directoriesToRemoveOption);
|
||||
parseResult.GetValue(directoriesToRemoveOption);
|
||||
|
||||
IviSigningInfo? signingInfo = null;
|
||||
IviPackagingInfo? packagingInfo = null;
|
||||
|
||||
@@ -16,8 +16,10 @@ internal class IviRootCommandProcessor
|
||||
private readonly InjectionManager _injectionManager;
|
||||
private readonly CodesigningManager _codesigningManager;
|
||||
|
||||
internal IviRootCommandProcessor(ILoggerFactory loggerFactory)
|
||||
internal IviRootCommandProcessor()
|
||||
{
|
||||
var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
|
||||
|
||||
_logger = loggerFactory.CreateLogger("Main");
|
||||
_packageManager = new PackageManager(
|
||||
loggerFactory.CreateLogger("PackageManager")
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using System.CommandLine.Binding;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace ivinject.Features.Command;
|
||||
|
||||
internal class LoggerFactoryBinder : BinderBase<ILoggerFactory>
|
||||
{
|
||||
protected override ILoggerFactory GetBoundValue(BindingContext bindingContext)
|
||||
=> GetLoggerFactory();
|
||||
private static ILoggerFactory GetLoggerFactory()
|
||||
{
|
||||
var loggerFactory = LoggerFactory.Create(builder =>
|
||||
builder.AddConsole());
|
||||
|
||||
return loggerFactory;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,6 @@ internal static class Program
|
||||
|
||||
private static async Task<int> Main(string[] args)
|
||||
{
|
||||
return await RootCommand.InvokeAsync(args);
|
||||
return await RootCommand.Parse(args).InvokeAsync();
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.0-preview.3.25171.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.0-preview.3.25171.5" />
|
||||
<PackageReference Include="plist-cil" Version="2.2.0" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-rc.1.25451.107" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.0-rc.1.25451.107" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.0-rc.1.25451.107" />
|
||||
<PackageReference Include="plist-cil" Version="2.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user