forked from chocolatey/choco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chocolatey#2788) Handle limited output for removed options
When emitting a warning for options that are no longer supported, if the user requested limited output we should not emit a warning.
- Loading branch information
Showing
4 changed files
with
59 additions
and
50 deletions.
There are no files selected for viewing
103 changes: 56 additions & 47 deletions
103
src/chocolatey/infrastructure.app/commands/ChocolateyCommandBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,56 @@ | ||
// Copyright © 2023 Chocolatey Software, Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace chocolatey.infrastructure.app.commands | ||
{ | ||
/// <summary> | ||
/// A base class for any Chocolatey commands which need to utilise shared logic. | ||
/// </summary> | ||
public abstract class ChocolateyCommandBase | ||
{ | ||
/// <summary> | ||
/// Emit a warning to the use if any of the options which are known to be deprecated are found in the <paramref name="unparsedOptions"/>. | ||
/// </summary> | ||
/// <param name="unparsedOptions">The list of unrecognised and unparsed options.</param> | ||
/// <param name="removedOptions">The list of options which are known to be removed and should be warned for.</param> | ||
protected virtual void warn_for_removed_options(IEnumerable<string> unparsedOptions, IEnumerable<string> removedOptions) | ||
{ | ||
if (!unparsedOptions.or_empty_list_if_null().Any() || !removedOptions.or_empty_list_if_null().Any()) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var removed in removedOptions) | ||
{ | ||
if (unparsedOptions.Contains(removed)) | ||
{ | ||
this.Log().Warn("The {0} option is no longer supported.", removed); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// Copyright © 2023 Chocolatey Software, Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace chocolatey.infrastructure.app.commands | ||
{ | ||
/// <summary> | ||
/// A base class for any Chocolatey commands which need to utilise shared logic. | ||
/// </summary> | ||
public abstract class ChocolateyCommandBase | ||
{ | ||
/// <summary> | ||
/// Emit a warning to the use if any of the options which are known to be deprecated are found in the <paramref name="unparsedOptions"/>. | ||
/// </summary> | ||
/// <param name="unparsedOptions">The list of unrecognised and unparsed options.</param> | ||
/// <param name="removedOptions">The list of options which are known to be removed and should be warned for.</param> | ||
protected virtual void warn_for_removed_options(IEnumerable<string> unparsedOptions, IEnumerable<string> removedOptions, bool RegularOutput) | ||
{ | ||
if (!unparsedOptions.or_empty_list_if_null().Any() || !removedOptions.or_empty_list_if_null().Any()) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (var removed in removedOptions) | ||
{ | ||
if (unparsedOptions.Contains(removed)) | ||
{ | ||
var message = "The {0} option is no longer supported.".format_with(removed); | ||
|
||
if (RegularOutput) | ||
{ | ||
this.Log().Warn(message); | ||
} | ||
else | ||
{ | ||
this.Log().Debug(message); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters