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