-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds the outdated command, similar to `brew outdated`.
- Loading branch information
1 parent
6f711ad
commit 6b04611
Showing
10 changed files
with
324 additions
and
14 deletions.
There are no files selected for viewing
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
142 changes: 142 additions & 0 deletions
142
src/chocolatey.tests/infrastructure.app/commands/ChocolateyOutdatedCommandSpecs.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 |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Copyright © 2011 - Present RealDimensions Software, LLC | ||
// | ||
// 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. | ||
|
||
namespace chocolatey.tests.infrastructure.app.commands | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Moq; | ||
using Should; | ||
using chocolatey.infrastructure.app.attributes; | ||
using chocolatey.infrastructure.app.commands; | ||
using chocolatey.infrastructure.app.configuration; | ||
using chocolatey.infrastructure.app.domain; | ||
using chocolatey.infrastructure.app.services; | ||
using chocolatey.infrastructure.commandline; | ||
|
||
public class ChocolateyOutdatedCommandSpecs | ||
{ | ||
public abstract class ChocolateyOutdatedCommandSpecsBase : TinySpec | ||
{ | ||
protected ChocolateyOutdatedCommand command; | ||
protected Mock<IChocolateyPackageService> packageService = new Mock<IChocolateyPackageService>(); | ||
protected ChocolateyConfiguration configuration = new ChocolateyConfiguration(); | ||
|
||
public override void Context() | ||
{ | ||
configuration.Sources = "bob"; | ||
command = new ChocolateyOutdatedCommand(packageService.Object); | ||
} | ||
} | ||
|
||
public class when_implementing_command_for : ChocolateyOutdatedCommandSpecsBase | ||
{ | ||
private List<string> results; | ||
|
||
public override void Because() | ||
{ | ||
results = command.GetType().GetCustomAttributes(typeof (CommandForAttribute), false).Cast<CommandForAttribute>().Select(a => a.CommandName).ToList(); | ||
} | ||
|
||
[Fact] | ||
public void should_implement_outdated() | ||
{ | ||
results.ShouldContain(CommandNameType.outdated.to_string()); | ||
} | ||
} | ||
|
||
public class when_configurating_the_argument_parser : ChocolateyOutdatedCommandSpecsBase | ||
{ | ||
private OptionSet optionSet; | ||
|
||
public override void Context() | ||
{ | ||
base.Context(); | ||
optionSet = new OptionSet(); | ||
} | ||
|
||
public override void Because() | ||
{ | ||
command.configure_argument_parser(optionSet, configuration); | ||
} | ||
|
||
[Fact] | ||
public void should_add_source_to_the_option_set() | ||
{ | ||
optionSet.Contains("source").ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void should_add_short_version_of_source_to_the_option_set() | ||
{ | ||
optionSet.Contains("s").ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void should_add_user_to_the_option_set() | ||
{ | ||
optionSet.Contains("user").ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void should_add_short_version_of_user_to_the_option_set() | ||
{ | ||
optionSet.Contains("u").ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void should_add_password_to_the_option_set() | ||
{ | ||
optionSet.Contains("password").ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void should_add_short_version_of_password_to_the_option_set() | ||
{ | ||
optionSet.Contains("p").ShouldBeTrue(); | ||
} | ||
|
||
} | ||
|
||
public class when_noop_is_called : ChocolateyOutdatedCommandSpecsBase | ||
{ | ||
public override void Because() | ||
{ | ||
command.noop(configuration); | ||
} | ||
|
||
[Fact] | ||
public void should_call_service_outdated_noop() | ||
{ | ||
packageService.Verify(c => c.outdated_noop(configuration), Times.Once); | ||
} | ||
} | ||
|
||
public class when_run_is_called : ChocolateyOutdatedCommandSpecsBase | ||
{ | ||
public override void Because() | ||
{ | ||
command.run(configuration); | ||
} | ||
|
||
[Fact] | ||
public void should_call_service_oudated_run() | ||
{ | ||
packageService.Verify(c => c.outdated_run(configuration), Times.Once); | ||
} | ||
} | ||
} | ||
} |
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
102 changes: 102 additions & 0 deletions
102
src/chocolatey/infrastructure.app/commands/ChocolateyOutdatedCommand.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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright © 2011 - Present RealDimensions Software, LLC | ||
// | ||
// 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. | ||
|
||
namespace chocolatey.infrastructure.app.commands | ||
{ | ||
using System.Collections.Generic; | ||
using attributes; | ||
using commandline; | ||
using configuration; | ||
using domain; | ||
using infrastructure.commands; | ||
using logging; | ||
using services; | ||
|
||
[CommandFor(CommandNameType.outdated)] | ||
public sealed class ChocolateyOutdatedCommand : ICommand | ||
{ | ||
private readonly IChocolateyPackageService _packageService; | ||
|
||
public ChocolateyOutdatedCommand(IChocolateyPackageService packageService) | ||
{ | ||
_packageService = packageService; | ||
} | ||
|
||
public void configure_argument_parser(OptionSet optionSet, ChocolateyConfiguration configuration) | ||
{ | ||
optionSet | ||
.Add("s=|source=", | ||
"Source - The source to find the package(s) to install. Special sources include: ruby, webpi, cygwin, windowsfeatures, and python. Defaults to default feeds.", | ||
option => configuration.Sources = option.remove_surrounding_quotes()) | ||
.Add("u=|user=", | ||
"User - used with authenticated feeds. Defaults to empty.", | ||
option => configuration.SourceCommand.Username = option.remove_surrounding_quotes()) | ||
.Add("p=|password=", | ||
"Password - the user's password to the source. Defaults to empty.", | ||
option => configuration.SourceCommand.Password = option.remove_surrounding_quotes()) | ||
; | ||
} | ||
|
||
public void handle_additional_argument_parsing(IList<string> unparsedArguments, ChocolateyConfiguration configuration) | ||
{ | ||
configuration.Input = string.Join(" ", unparsedArguments); | ||
configuration.PackageNames = string.Join(ApplicationParameters.PackageNamesSeparator.to_string(), unparsedArguments); | ||
} | ||
|
||
public void handle_validation(ChocolateyConfiguration configuration) | ||
{ | ||
} | ||
|
||
public void help_message(ChocolateyConfiguration configuration) | ||
{ | ||
this.Log().Info(ChocolateyLoggers.Important, "Outdated Command"); | ||
this.Log().Info(@" | ||
Returns a list of outdated packages | ||
"); | ||
|
||
"chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage"); | ||
"chocolatey".Log().Info(@" | ||
choco outdated [<options/switches>] | ||
"); | ||
|
||
"chocolatey".Log().Info(ChocolateyLoggers.Important, "Examples"); | ||
"chocolatey".Log().Info(@" | ||
choco outdated | ||
choco outdated -s ""https://somewhere/out/there"" | ||
choco outdated -s ""https://somewhere/protected"" -u user -p pass | ||
If you use `--source=https://somewhere/out/there`, it is | ||
going to look for outdated packages only based on that source. | ||
"); | ||
|
||
"chocolatey".Log().Info(ChocolateyLoggers.Important, "Options and Switches"); | ||
} | ||
|
||
public void noop(ChocolateyConfiguration configuration) | ||
{ | ||
_packageService.outdated_noop(configuration); | ||
} | ||
|
||
public void run(ChocolateyConfiguration configuration) | ||
{ | ||
_packageService.outdated_run(configuration); | ||
} | ||
|
||
public bool may_require_admin_access() | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.