forked from dotnet/sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackCommandDefinition.cs
More file actions
134 lines (110 loc) · 6.04 KB
/
Copy pathPackCommandDefinition.cs
File metadata and controls
134 lines (110 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.CommandLine;
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Commands.Build;
using Microsoft.DotNet.Cli.Commands.Restore;
using NuGet.Versioning;
namespace Microsoft.DotNet.Cli.Commands.Pack;
internal sealed class PackCommandDefinition : Command
{
private const string Link = "https://aka.ms/dotnet-pack";
public readonly Argument<string[]> SlnOrProjectOrFileArgument = new(CommandDefinitionStrings.SolutionOrProjectOrFileArgumentName)
{
Description = CommandDefinitionStrings.SolutionOrProjectOrFileArgumentDescription,
Arity = ArgumentArity.ZeroOrMore
};
public readonly ImplicitRestoreOptions ImplicitRestoreOptions = new(showHelp: false, useShortOptions: false);
public readonly Option<string> OutputOption = new Option<string>("--output", "-o")
{
Description = CommandDefinitionStrings.PackCmdOutputDirDescription,
HelpName = CommandDefinitionStrings.PackCmdOutputDir
}.ForwardAsSingle(o => $"-property:PackageOutputPath={CommandDirectoryContext.GetFullPath(o)}");
public readonly Option<bool> NoBuildOption = new Option<bool>("--no-build")
{
Description = CommandDefinitionStrings.CmdNoBuildOptionDescription,
Arity = ArgumentArity.Zero
}.ForwardAs("-property:NoBuild=true");
public readonly Option<bool> IncludeSymbolsOption = new Option<bool>("--include-symbols")
{
Description = CommandDefinitionStrings.CmdIncludeSymbolsDescription,
Arity = ArgumentArity.Zero
}.ForwardAs("-property:IncludeSymbols=true");
public readonly Option<bool> IncludeSourceOption = new Option<bool>("--include-source")
{
Description = CommandDefinitionStrings.CmdIncludeSourceDescription,
Arity = ArgumentArity.Zero
}.ForwardAs("-property:IncludeSource=true");
public readonly Option<bool> ServiceableOption = new Option<bool>("--serviceable", "-s")
{
Description = CommandDefinitionStrings.CmdServiceableDescription,
Arity = ArgumentArity.Zero
}.ForwardAs("-property:Serviceable=true");
public readonly Option<bool> OutputFileNamesWithoutVersionOption = new Option<bool>("--OutputFileNamesWithoutVersion")
{
Description = CommandDefinitionStrings.PackCmdOutputFileNamesWithoutVersionDescription,
Arity = ArgumentArity.Zero
}.ForwardAs("-property:OutputFileNamesWithoutVersion=true");
public readonly Option<bool> NoLogoOption = CommonOptions.CreateNoLogoOption();
public readonly Option<bool> NoRestoreOption = CommonOptions.CreateNoRestoreOption();
public readonly Option<string?> ConfigurationOption = CommonOptions.CreateConfigurationOption(CommandDefinitionStrings.PackConfigurationOptionDescription);
public readonly Option<string[]> TargetOption = CreateTargetOption();
public readonly Option<Utils.VerbosityOptions?> VerbosityOption = CommonOptions.CreateVerbosityOption();
public readonly Option<string> ArtifactsPathOption = CommonOptions.CreateArtifactsPathOption();
public readonly Option<bool> InteractiveOption = CommonOptions.CreateInteractiveMsBuildForwardOption();
public readonly Option<string> VersionSuffixOption = CommonOptions.CreateVersionSuffixOption();
public readonly Option<bool> DisableBuildServersOption = CommonOptions.CreateDisableBuildServersOption();
public readonly Option<string[]?> GetPropertyOption = CommonOptions.CreateGetPropertyOption();
public readonly Option<string[]?> GetItemOption = CommonOptions.CreateGetItemOption();
public readonly Option<string[]?> GetTargetResultOption = CommonOptions.CreateGetTargetResultOption();
public readonly Option<string[]?> GetResultOutputFileOption = CommonOptions.CreateGetResultOutputFileOption();
public readonly Option<bool> NoDependenciesOption = RestoreCommandDefinition.CreateNoDependenciesOption(showHelp: false);
public readonly Option<string> RuntimeOption = TargetPlatformOptions.CreateRuntimeOption(CommandDefinitionStrings.BuildRuntimeOptionDescription);
public readonly Option<NuGetVersion> VersionOption = new Option<NuGetVersion>("--version")
{
Description = CommandDefinitionStrings.PackCmdVersionDescription,
HelpName = CommandDefinitionStrings.PackCmdVersion,
Arity = ArgumentArity.ExactlyOne,
CustomParser = r =>
{
if (r.Tokens.Count == 0)
return null;
var value = r.Tokens[0].Value;
if (NuGetVersion.TryParse(value, out var version))
return version;
r.AddError(string.Format(CommandDefinitionStrings.InvalidVersion, value));
return null;
}
}.ForwardAsSingle(o => $"--property:PackageVersion={o}");
public PackCommandDefinition()
: base("pack", CommandDefinitionStrings.PackAppFullName)
{
this.DocsLink = Link;
Arguments.Add(SlnOrProjectOrFileArgument);
Options.Add(OutputOption);
Options.Add(ArtifactsPathOption);
Options.Add(NoBuildOption);
Options.Add(IncludeSymbolsOption);
Options.Add(IncludeSourceOption);
Options.Add(ServiceableOption);
Options.Add(OutputFileNamesWithoutVersionOption);
Options.Add(NoLogoOption);
Options.Add(InteractiveOption);
Options.Add(NoRestoreOption);
Options.Add(VerbosityOption);
Options.Add(VersionSuffixOption);
Options.Add(VersionOption);
Options.Add(ConfigurationOption);
Options.Add(DisableBuildServersOption);
Options.Add(TargetOption);
Options.Add(GetPropertyOption);
Options.Add(GetItemOption);
Options.Add(GetTargetResultOption);
Options.Add(GetResultOutputFileOption);
ImplicitRestoreOptions.AddTo(Options);
Options.Add(NoDependenciesOption);
Options.Add(RuntimeOption);
}
public static Option<string[]> CreateTargetOption()
=> CommonOptions.CreateRequiredMSBuildTargetOption("Pack", [("_IsPacking", "true")]);
}