Browse Source

Update CommandLineUtils, switch to OnExecuteAsync (although async is not yet used)

pull/3035/head
Christoph Wille 2 years ago
parent
commit
5156a9db00
  1. 6
      ICSharpCode.ILSpyCmd/ICSharpCode.ILSpyCmd.csproj
  2. 15
      ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs

6
ICSharpCode.ILSpyCmd/ICSharpCode.ILSpyCmd.csproj

@ -49,11 +49,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="3.1.0" /> <PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="4.0.2" />
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
<PackageReference Include="System.Runtime.Handles" Version="4.3.0" />
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
<PackageReference Include="System.Text.Encoding.Extensions" Version="4.3.0" />
</ItemGroup> </ItemGroup>
<Target Name="ILSpyUpdateAssemblyInfo" AfterTargets="ResolveProjectReferences"> <Target Name="ILSpyUpdateAssemblyInfo" AfterTargets="ResolveProjectReferences">

15
ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs

@ -8,6 +8,7 @@ using System.Linq;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Reflection.PortableExecutable; using System.Reflection.PortableExecutable;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using ICSharpCode.Decompiler; using ICSharpCode.Decompiler;
using ICSharpCode.Decompiler.CSharp; using ICSharpCode.Decompiler.CSharp;
@ -48,7 +49,7 @@ Examples:
MemberName = nameof(DecompilerVersion))] MemberName = nameof(DecompilerVersion))]
class ILSpyCmdProgram class ILSpyCmdProgram
{ {
public static int Main(string[] args) => CommandLineApplication.Execute<ILSpyCmdProgram>(args); public static Task<int> Main(string[] args) => CommandLineApplication.ExecuteAsync<ILSpyCmdProgram>(args);
[FilesExist] [FilesExist]
[Required] [Required]
@ -106,7 +107,7 @@ Examples:
[Option("--nested-directories", "Use nested directories for namespaces.", CommandOptionType.NoValue)] [Option("--nested-directories", "Use nested directories for namespaces.", CommandOptionType.NoValue)]
public bool NestedDirectories { get; } public bool NestedDirectories { get; }
private int OnExecute(CommandLineApplication app) private Task<int> OnExecuteAsync(CommandLineApplication app)
{ {
TextWriter output = System.Console.Out; TextWriter output = System.Console.Out;
string outputDirectory = ResolveOutputDirectory(OutputDirectory); string outputDirectory = ResolveOutputDirectory(OutputDirectory);
@ -124,7 +125,7 @@ Examples:
{ {
string projectFileName = Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(InputAssemblyNames[0]) + ".csproj"); string projectFileName = Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(InputAssemblyNames[0]) + ".csproj");
DecompileAsProject(InputAssemblyNames[0], projectFileName); DecompileAsProject(InputAssemblyNames[0], projectFileName);
return 0; return Task.FromResult(0);
} }
var projects = new List<ProjectItem>(); var projects = new List<ProjectItem>();
foreach (var file in InputAssemblyNames) foreach (var file in InputAssemblyNames)
@ -135,7 +136,7 @@ Examples:
projects.Add(new ProjectItem(projectFileName, projectId.PlatformName, projectId.Guid, projectId.TypeGuid)); projects.Add(new ProjectItem(projectFileName, projectId.PlatformName, projectId.Guid, projectId.TypeGuid));
} }
SolutionCreator.WriteSolutionFile(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(outputDirectory) + ".sln"), projects); SolutionCreator.WriteSolutionFile(Path.Combine(outputDirectory, Path.GetFileNameWithoutExtension(outputDirectory) + ".sln"), projects);
return 0; return Task.FromResult(0);
} }
else else
{ {
@ -143,15 +144,15 @@ Examples:
{ {
int result = PerformPerFileAction(file); int result = PerformPerFileAction(file);
if (result != 0) if (result != 0)
return result; return Task.FromResult(result);
} }
return 0; return Task.FromResult(0);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
app.Error.WriteLine(ex.ToString()); app.Error.WriteLine(ex.ToString());
return ProgramExitCodes.EX_SOFTWARE; return Task.FromResult(ProgramExitCodes.EX_SOFTWARE);
} }
finally finally
{ {

Loading…
Cancel
Save