main
cs 84 lines 3.15 KB
Raw
1 // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3 namespace WixToolset.Core.Burn.CommandLine
4 {
5 using System;
6 using System.Threading;
7 using System.Threading.Tasks;
8 using WixToolset.Data;
9 using WixToolset.Extensibility;
10 using WixToolset.Extensibility.Data;
11 using WixToolset.Extensibility.Services;
12
13 /// <summary>
14 /// Burn specialized command.
15 /// </summary>
16 internal class BurnCommand : BaseCommandLineCommand
17 {
18 public BurnCommand(IServiceProvider serviceProvider)
19 {
20 this.ServiceProvider = serviceProvider;
21 this.Messaging = this.ServiceProvider.GetService<IMessaging>();
22 }
23
24 private IServiceProvider ServiceProvider { get; }
25
26 private IMessaging Messaging { get; }
27
28 private BurnSubcommandBase Subcommand { get; set; }
29
30 public override CommandLineHelp GetCommandLineHelp()
31 {
32 return this.Subcommand?.GetCommandLineHelp() ?? new CommandLineHelp("Specialized operations for manipulating Burn-based bundles.", "burn detach|extract|reattach|remotepayload")
33 {
34 Commands = new[]
35 {
36 new CommandLineHelpCommand("detach", "Detach the Burn engine from a bundle so it can be signed."),
37 new CommandLineHelpCommand("extract", "Extract the internals of a bundle to a folder."),
38 new CommandLineHelpCommand("reattach", "Reattach a signed Burn engine to a bundle."),
39 new CommandLineHelpCommand("remotepayload", "Generate source code for a remote payload."),
40 }
41 };
42 }
43
44 public override Task<int> ExecuteAsync(CancellationToken cancellationToken)
45 {
46 if (this.Subcommand is null)
47 {
48 this.Messaging.Write(ErrorMessages.CommandLineCommandRequired("burn"));
49 return Task.FromResult(this.Messaging.LastErrorNumber);
50 }
51
52 return this.Subcommand.ExecuteAsync(cancellationToken);
53 }
54
55 public override bool TryParseArgument(ICommandLineParser parser, string argument)
56 {
57 if (this.Subcommand is null)
58 {
59 switch (argument.ToLowerInvariant())
60 {
61 case "detach":
62 this.Subcommand = new DetachSubcommand(this.ServiceProvider);
63 return true;
64
65 case "extract":
66 this.Subcommand = new ExtractSubcommand(this.ServiceProvider);
67 return true;
68
69 case "reattach":
70 this.Subcommand = new ReattachSubcommand(this.ServiceProvider);
71 return true;
72
73 case "remotepayload":
74 this.Subcommand = new RemotePayloadSubcommand(this.ServiceProvider);
75 return true;
76 }
77
78 return false;
79 }
80
81 return this.Subcommand.TryParseArgument(parser, argument);
82 }
83 }
84 }