Skip to content

Commit c5fc6b8

Browse files
committed
Add vulnerable option to dotnet list package, also corrections to option logic
1 parent 3d11699 commit c5fc6b8

17 files changed

+523
-328
lines changed

src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/ListPackageReferencesCommand.cs

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,64 +39,85 @@ public override int Execute()
3939
return NuGetCommand.Run(TransformArgs());
4040
}
4141

42-
private string[] TransformArgs()
42+
internal static void EnforceOptionRules(AppliedOption appliedCommand)
4343
{
44-
var args = new List<string>
44+
if (appliedCommand.HasOption("include-prerelease"))
4545
{
46-
"package",
47-
"list",
48-
};
49-
50-
args.Add(GetProjectOrSolution());
51-
52-
args.AddRange(_appliedCommand.OptionValuesToBeForwarded());
46+
CheckForOutdatedOption(appliedCommand, "--include-prerelease");
47+
}
5348

54-
if (_appliedCommand.HasOption("include-prerelease"))
49+
if (appliedCommand.HasOption("highest-patch"))
5550
{
56-
CheckForOutdatedOrDeprecated("--include-prerelease");
51+
CheckForOutdatedOption(appliedCommand, "--highest-patch");
5752
}
5853

59-
if (_appliedCommand.HasOption("highest-patch"))
54+
if (appliedCommand.HasOption("highest-minor"))
6055
{
61-
CheckForOutdatedOrDeprecated("--highest-patch");
56+
CheckForOutdatedOption(appliedCommand, "--highest-minor");
6257
}
6358

64-
if (_appliedCommand.HasOption("highest-minor"))
59+
if (appliedCommand.HasOption("config"))
6560
{
66-
CheckForOutdatedOrDeprecated("--highest-minor");
61+
CheckForOnlineOptions(appliedCommand, "--config");
6762
}
6863

69-
if (_appliedCommand.HasOption("config"))
64+
if (appliedCommand.HasOption("source"))
7065
{
71-
CheckForOutdatedOrDeprecated("--config");
66+
CheckForOnlineOptions(appliedCommand, "--source");
7267
}
7368

74-
if (_appliedCommand.HasOption("source"))
69+
var mutexOptionCount = 0;
70+
mutexOptionCount += appliedCommand.HasOption("deprecated") ? 1 : 0;
71+
mutexOptionCount += appliedCommand.HasOption("outdated") ? 1 : 0;
72+
mutexOptionCount += appliedCommand.HasOption("vulnerable") ? 1 : 0;
73+
if (mutexOptionCount > 1)
7574
{
76-
CheckForOutdatedOrDeprecated("--source");
75+
throw new GracefulException(LocalizableStrings.OptionsCannotBeCombined);
7776
}
77+
}
7878

79-
if (_appliedCommand.HasOption("deprecated") && _appliedCommand.HasOption("outdated"))
79+
/// <summary>
80+
/// A check for options requiring online services. If no online options are present,
81+
/// these options must not be used, so error is thrown.
82+
/// </summary>
83+
/// <param name="option"></param>
84+
private static void CheckForOnlineOptions(AppliedOption appliedCommand, string option)
85+
{
86+
if (!appliedCommand.HasOption("deprecated") && !appliedCommand.HasOption("outdated") && !appliedCommand.HasOption("vulnerable"))
8087
{
81-
throw new GracefulException(LocalizableStrings.OutdatedAndDeprecatedOptionsCannotBeCombined);
88+
throw new GracefulException(LocalizableStrings.RequiresOnlineOption, option);
8289
}
83-
84-
return args.ToArray();
8590
}
8691

8792
/// <summary>
88-
/// A check for the outdated and deprecated specific options. If --outdated or --deprecated not present,
89-
/// these options must not be used, so error is thrown.
93+
/// A check for the outdated option. If none of these are present, these options must not be used, so error is thrown.
9094
/// </summary>
9195
/// <param name="option"></param>
92-
private void CheckForOutdatedOrDeprecated(string option)
96+
private static void CheckForOutdatedOption(AppliedOption appliedCommand, string option)
9397
{
94-
if (!_appliedCommand.HasOption("deprecated") && !_appliedCommand.HasOption("outdated"))
98+
if (!appliedCommand.HasOption("outdated"))
9599
{
96-
throw new GracefulException(LocalizableStrings.OutdatedOrDeprecatedOptionOnly, option);
100+
throw new GracefulException(LocalizableStrings.RequiresOutdatedOption, option);
97101
}
98102
}
99103

104+
private string[] TransformArgs()
105+
{
106+
var args = new List<string>
107+
{
108+
"package",
109+
"list",
110+
};
111+
112+
args.Add(GetProjectOrSolution());
113+
114+
args.AddRange(_appliedCommand.OptionValuesToBeForwarded());
115+
116+
EnforceOptionRules(_appliedCommand);
117+
118+
return args.ToArray();
119+
}
120+
100121
/// <summary>
101122
/// Gets a solution file or a project file from a given directory.
102123
/// If the given path is a file, it just returns it after checking

src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/ListPackageReferencesCommandParser.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public static Command ListPackageReferences() => Create.Command(
2222
Create.Option("--deprecated",
2323
LocalizableStrings.CmdDeprecatedDescription,
2424
Accept.NoArguments().ForwardAs("--deprecated")),
25+
Create.Option("--vulnerable",
26+
LocalizableStrings.CmdVulnerableDescription,
27+
Accept.NoArguments().ForwardAs("--vulnerable")),
2528
Create.Option("--framework",
2629
LocalizableStrings.CmdFrameworkDescription,
2730
Accept.OneOrMoreArguments()

src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/LocalizableStrings.resx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,6 @@
126126
<data name="CmdFrameworkDescription" xml:space="preserve">
127127
<value>Chooses a framework to show its packages. Use the option multiple times for multiple frameworks.</value>
128128
</data>
129-
<data name="CmdOutdatedDescription" xml:space="preserve">
130-
<value>Lists packages that have newer versions.</value>
131-
</data>
132129
<data name="CmdTransitiveDescription" xml:space="preserve">
133130
<value>Lists transitive and top-level packages.</value>
134131
</data>
@@ -139,33 +136,42 @@
139136
<value>CONFIG_FILE</value>
140137
</data>
141138
<data name="CmdConfigDescription" xml:space="preserve">
142-
<value>The path to the NuGet config file to use. Requires the '--outdated' or '--deprecated' option.</value>
139+
<value>The path to the NuGet config file to use. Requires the '--outdated', '--deprecated' or '--vulnerable' option.</value>
143140
</data>
144141
<data name="CmdHighestMinorDescription" xml:space="preserve">
145-
<value>Consider only the packages with a matching major version number when searching for newer packages. Requires the '--outdated' or '--deprecated' option.</value>
142+
<value>Consider only the packages with a matching major version number when searching for newer packages. Requires the '--outdated' option.</value>
146143
</data>
147144
<data name="CmdHighestPatchDescription" xml:space="preserve">
148-
<value>Consider only the packages with a matching major and minor version numbers when searching for newer packages. Requires the '--outdated' or '--deprecated' option.</value>
145+
<value>Consider only the packages with a matching major and minor version numbers when searching for newer packages. Requires the '--outdated' option.</value>
149146
</data>
150147
<data name="CmdPrereleaseDescription" xml:space="preserve">
151-
<value>Consider packages with prerelease versions when searching for newer packages. Requires the '--outdated' or '--deprecated' option.</value>
148+
<value>Consider packages with prerelease versions when searching for newer packages. Requires the '--outdated' option.</value>
152149
</data>
153150
<data name="CmdSource" xml:space="preserve">
154151
<value>SOURCE</value>
155152
</data>
156153
<data name="CmdSourceDescription" xml:space="preserve">
157-
<value>The NuGet sources to use when searching for newer packages. Requires the '--outdated' or '--deprecated' option.</value>
154+
<value>The NuGet sources to use when searching for newer packages. Requires the '--outdated', '--deprecated' or '--vulnerable' option.</value>
158155
</data>
159156
<data name="FileNotFound" xml:space="preserve">
160157
<value>Could not find file or directory '{0}'.</value>
161158
</data>
162-
<data name="OutdatedAndDeprecatedOptionsCannotBeCombined" xml:space="preserve">
163-
<value>Option '--outdated' and '--deprecated' cannot be combined.</value>
159+
<data name="OptionsCannotBeCombined" xml:space="preserve">
160+
<value>Options '--outdated', '--deprecated' and '--vulnerable' cannot be combined.</value>
161+
</data>
162+
<data name="CmdOutdatedDescription" xml:space="preserve">
163+
<value>Lists packages that have newer versions. Cannot be combined with '--deprecated' or '--vulnerable' options.</value>
164164
</data>
165165
<data name="CmdDeprecatedDescription" xml:space="preserve">
166-
<value>Lists packages that have been deprecated.</value>
166+
<value>Lists packages that have been deprecated. Cannot be combined with '--vulnerable' or '--outdated' options.</value>
167+
</data>
168+
<data name="CmdVulnerableDescription" xml:space="preserve">
169+
<value>Lists packages that have known vulnerabilities. Cannot be combined with '--deprecated' or '--outdated' options.</value>
170+
</data>
171+
<data name="RequiresOnlineOption" xml:space="preserve">
172+
<value>Option '{0}' requires the '--outdated', '--deprecated' or '--vulnerable' option to be specified.</value>
167173
</data>
168-
<data name="OutdatedOrDeprecatedOptionOnly" xml:space="preserve">
169-
<value>Option '{0}' requires the '--outdated' or '--deprecated' option to be specified.</value>
174+
<data name="RequiresOutdatedOption" xml:space="preserve">
175+
<value>Option '{0}' requires the '--outdated' option to be specified.</value>
170176
</data>
171-
</root>
177+
</root>

src/Cli/dotnet/commands/dotnet-list/dotnet-list-package/xlf/LocalizableStrings.cs.xlf

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<note />
99
</trans-unit>
1010
<trans-unit id="CmdDeprecatedDescription">
11-
<source>Lists packages that have been deprecated.</source>
12-
<target state="translated">Seznam zastaralých balíčků</target>
11+
<source>Lists packages that have been deprecated. Cannot be combined with '--vulnerable' or '--outdated' options.</source>
12+
<target state="needs-review-translation">Seznam zastaralých balíčků</target>
1313
<note />
1414
</trans-unit>
1515
<trans-unit id="CmdFramework">
@@ -23,15 +23,20 @@
2323
<note />
2424
</trans-unit>
2525
<trans-unit id="CmdOutdatedDescription">
26-
<source>Lists packages that have newer versions.</source>
27-
<target state="translated">Zobrazí seznam balíčků, které mají novější verze.</target>
26+
<source>Lists packages that have newer versions. Cannot be combined with '--deprecated' or '--vulnerable' options.</source>
27+
<target state="needs-review-translation">Zobrazí seznam balíčků, které mají novější verze.</target>
2828
<note />
2929
</trans-unit>
3030
<trans-unit id="CmdTransitiveDescription">
3131
<source>Lists transitive and top-level packages.</source>
3232
<target state="translated">Vypíše seznam přenosných balíčků a balíčků nejvyšší úrovně.</target>
3333
<note />
3434
</trans-unit>
35+
<trans-unit id="CmdVulnerableDescription">
36+
<source>Lists packages that have known vulnerabilities. Cannot be combined with '--deprecated' or '--outdated' options.</source>
37+
<target state="new">Lists packages that have known vulnerabilities. Cannot be combined with '--deprecated' or '--outdated' options.</target>
38+
<note />
39+
</trans-unit>
3540
<trans-unit id="NoProjectsOrSolutions">
3641
<source>A project or solution file could not be found in {0}. Specify a project or solution file to use.</source>
3742
<target state="translated">{0} neobsahuje žádný soubor projektu nebo řešení. Zadejte soubor projektu nebo řešení, který chcete použít.</target>
@@ -43,23 +48,23 @@
4348
<note />
4449
</trans-unit>
4550
<trans-unit id="CmdConfigDescription">
46-
<source>The path to the NuGet config file to use. Requires the '--outdated' or '--deprecated' option.</source>
47-
<target state="translated">Cesta ke konfiguračnímu souboru NuGet, který se má použít. Vyžaduje přepínač --outdated nebo --deprecated.</target>
51+
<source>The path to the NuGet config file to use. Requires the '--outdated', '--deprecated' or '--vulnerable' option.</source>
52+
<target state="needs-review-translation">Cesta ke konfiguračnímu souboru NuGet, který se má použít. Vyžaduje přepínač --outdated nebo --deprecated.</target>
4853
<note />
4954
</trans-unit>
5055
<trans-unit id="CmdHighestMinorDescription">
51-
<source>Consider only the packages with a matching major version number when searching for newer packages. Requires the '--outdated' or '--deprecated' option.</source>
52-
<target state="translated">Při hledání novějších balíčků se budou brát v úvahu jen balíčky s odpovídajícím číslem hlavní verze. Vyžaduje přepínač --outdated nebo --deprecated.</target>
56+
<source>Consider only the packages with a matching major version number when searching for newer packages. Requires the '--outdated' option.</source>
57+
<target state="needs-review-translation">Při hledání novějších balíčků se budou brát v úvahu jen balíčky s odpovídajícím číslem hlavní verze. Vyžaduje přepínač --outdated nebo --deprecated.</target>
5358
<note />
5459
</trans-unit>
5560
<trans-unit id="CmdHighestPatchDescription">
56-
<source>Consider only the packages with a matching major and minor version numbers when searching for newer packages. Requires the '--outdated' or '--deprecated' option.</source>
57-
<target state="translated">Při hledání novějších balíčků se budou brát v úvahu jen balíčky s odpovídajícími čísly hlavní verze a podverze. Vyžaduje přepínač --outdated nebo --deprecated.</target>
61+
<source>Consider only the packages with a matching major and minor version numbers when searching for newer packages. Requires the '--outdated' option.</source>
62+
<target state="needs-review-translation">Při hledání novějších balíčků se budou brát v úvahu jen balíčky s odpovídajícími čísly hlavní verze a podverze. Vyžaduje přepínač --outdated nebo --deprecated.</target>
5863
<note />
5964
</trans-unit>
6065
<trans-unit id="CmdPrereleaseDescription">
61-
<source>Consider packages with prerelease versions when searching for newer packages. Requires the '--outdated' or '--deprecated' option.</source>
62-
<target state="translated">Při hledání novějších balíčků se budou brát v úvahu i balíčky v předběžných verzích. Vyžaduje přepínač --outdated nebo --deprecated.</target>
66+
<source>Consider packages with prerelease versions when searching for newer packages. Requires the '--outdated' option.</source>
67+
<target state="needs-review-translation">Při hledání novějších balíčků se budou brát v úvahu i balíčky v předběžných verzích. Vyžaduje přepínač --outdated nebo --deprecated.</target>
6368
<note />
6469
</trans-unit>
6570
<trans-unit id="CmdSource">
@@ -68,23 +73,28 @@
6873
<note />
6974
</trans-unit>
7075
<trans-unit id="CmdSourceDescription">
71-
<source>The NuGet sources to use when searching for newer packages. Requires the '--outdated' or '--deprecated' option.</source>
72-
<target state="translated">Zdroje NuGet, které se mají použít při hledání novějších balíčků. Vyžaduje přepínač --outdated nebo --deprecated.</target>
73-
<note />
74-
</trans-unit>
75-
<trans-unit id="OutdatedAndDeprecatedOptionsCannotBeCombined">
76-
<source>Option '--outdated' and '--deprecated' cannot be combined.</source>
77-
<target state="translated">Možnosti --outdated a --deprecated se nedají kombinovat.</target>
76+
<source>The NuGet sources to use when searching for newer packages. Requires the '--outdated', '--deprecated' or '--vulnerable' option.</source>
77+
<target state="needs-review-translation">Zdroje NuGet, které se mají použít při hledání novějších balíčků. Vyžaduje přepínač --outdated nebo --deprecated.</target>
7878
<note />
7979
</trans-unit>
8080
<trans-unit id="FileNotFound">
8181
<source>Could not find file or directory '{0}'.</source>
8282
<target state="translated">Soubor nebo adresář {0} nešlo najít.</target>
8383
<note />
8484
</trans-unit>
85-
<trans-unit id="OutdatedOrDeprecatedOptionOnly">
86-
<source>Option '{0}' requires the '--outdated' or '--deprecated' option to be specified.</source>
87-
<target state="translated">Přepínač {0} vyžaduje, aby se zadal přepínač --outdated nebo --deprecated.</target>
85+
<trans-unit id="OptionsCannotBeCombined">
86+
<source>Options '--outdated', '--deprecated' and '--vulnerable' cannot be combined.</source>
87+
<target state="new">Options '--outdated', '--deprecated' and '--vulnerable' cannot be combined.</target>
88+
<note />
89+
</trans-unit>
90+
<trans-unit id="RequiresOnlineOption">
91+
<source>Option '{0}' requires the '--outdated', '--deprecated' or '--vulnerable' option to be specified.</source>
92+
<target state="new">Option '{0}' requires the '--outdated', '--deprecated' or '--vulnerable' option to be specified.</target>
93+
<note />
94+
</trans-unit>
95+
<trans-unit id="RequiresOutdatedOption">
96+
<source>Option '{0}' requires the '--outdated' option to be specified.</source>
97+
<target state="new">Option '{0}' requires the '--outdated' option to be specified.</target>
8898
<note />
8999
</trans-unit>
90100
</body>

0 commit comments

Comments
 (0)