-
Notifications
You must be signed in to change notification settings - Fork 909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start exposing lists and package results via the API #132 #137
Changes from all commits
8702e01
8364b0e
cec6145
80a84e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ namespace chocolatey.infrastructure.app.commands | |
|
||
[CommandFor(CommandNameType.sources)] | ||
[CommandFor(CommandNameType.source)] | ||
public sealed class ChocolateySourceCommand : ICommand | ||
public sealed class ChocolateySourceCommand : IListCommand<ChocolateySource> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What benefit does this change have? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean if you implemented a separate command, what are you gaining here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This extends ICommand by adding a list function without forcing every command to implement list. I cannot make it an additional interface instead of an inherited one, because you need to be able to search for commands based on classes that implement the interface. This seemed natural to me. Is there some objection? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I am starting to understand it, I'm just trying to understand it here. |
||
{ | ||
private readonly IChocolateyConfigSettingsService _configSettingsService; | ||
|
||
|
@@ -139,5 +139,10 @@ public void run(ChocolateyConfiguration configuration) | |
break; | ||
} | ||
} | ||
|
||
public IEnumerable<ChocolateySource> list(ChocolateyConfiguration configuration) | ||
{ | ||
return _configSettingsService.source_list(configuration); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright © 2015 - 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.configuration | ||
{ | ||
public class ChocolateySource | ||
{ | ||
public string Id { get; set; } | ||
public string Value { get; set; } | ||
public bool Disabled { get; set; } | ||
public bool Authenticated { get; set; } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,12 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
|
||
namespace chocolatey.infrastructure.app.runners | ||
{ | ||
using System; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using SimpleInjector; | ||
using adapters; | ||
using attributes; | ||
|
@@ -28,7 +30,7 @@ namespace chocolatey.infrastructure.app.runners | |
|
||
public sealed class GenericRunner | ||
{ | ||
public void run(ChocolateyConfiguration config, Container container, bool isConsole, Action<ICommand> parseArgs) | ||
private ICommand find_command(ChocolateyConfiguration config, Container container, bool isConsole, Action<ICommand> parseArgs) | ||
{ | ||
var commands = container.GetAllInstances<ICommand>(); | ||
var command = commands.Where((c) => | ||
|
@@ -83,7 +85,7 @@ Chocolatey is not an official build (bypassed with --allow-unofficial). | |
If you are seeing this message and it is not expected, your system may | ||
now be in a bad state. Only official builds are to be trusted. | ||
" | ||
); | ||
); | ||
|
||
} | ||
} | ||
|
@@ -96,14 +98,38 @@ now be in a bad state. Only official builds are to be trusted. | |
} | ||
|
||
command.noop(config); | ||
return null; | ||
} | ||
else | ||
} | ||
return command; | ||
} | ||
|
||
public void run(ChocolateyConfiguration config, Container container, bool isConsole, Action<ICommand> parseArgs) | ||
{ | ||
var command = find_command(config, container, isConsole, parseArgs); | ||
if(command != null) | ||
{ | ||
this.Log().Debug("_ {0}:{1} - Normal Run Mode _".format_with(ApplicationParameters.Name, command.GetType().Name)); | ||
command.run(config); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need a space below this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check. |
||
|
||
public IEnumerable<T> list<T>(ChocolateyConfiguration config, Container container, bool isConsole, Action<ICommand> parseArgs) | ||
{ | ||
var command = find_command(config, container, isConsole, parseArgs) as IListCommand<T>; | ||
if (command == null) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(config.CommandName)) | ||
{ | ||
this.Log().Debug("_ {0}:{1} - Normal Run Mode _".format_with(ApplicationParameters.Name, command.GetType().Name)); | ||
command.run(config); | ||
throw new Exception("The implementation of '{0}' does not support listing '{1}'".format_with(config.CommandName, typeof(T).Name)); | ||
} | ||
return new List<T>(); | ||
} | ||
else | ||
{ | ||
this.Log().Debug("_ {0}:{1} - Normal List Mode _".format_with(ApplicationParameters.Name, command.GetType().Name)); | ||
return command.list(config); | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
namespace chocolatey.infrastructure.app.services | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using configuration; | ||
using infrastructure.services; | ||
|
@@ -43,12 +44,22 @@ public void noop(ChocolateyConfiguration configuration) | |
this.Log().Info("Would have made a change to the configuration."); | ||
} | ||
|
||
public void source_list(ChocolateyConfiguration configuration) | ||
public IEnumerable<ChocolateySource> source_list(ChocolateyConfiguration configuration) | ||
{ | ||
var list = new List<ChocolateySource>(); | ||
foreach (var source in configFileSettings.Sources) | ||
{ | ||
this.Log().Info(() => "{0}{1} - {2}".format_with(source.Id, source.Disabled ? " [Disabled]" : string.Empty, source.Value)); | ||
} | ||
if (configuration.RegularOuptut) { | ||
this.Log().Info(() => "{0}{1} - {2}".format_with(source.Id, source.Disabled ? " [Disabled]" : string.Empty, source.Value)); | ||
} | ||
list.Add(new ChocolateySource { | ||
Id = source.Id, | ||
Value = source.Value, | ||
Disabled = source.Disabled, | ||
Authenticated = string.IsNullOrWhiteSpace(source.Password) | ||
}); | ||
} | ||
return list; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
public void source_add(ChocolateyConfiguration configuration) | ||
|
@@ -232,4 +243,4 @@ public void set_api_key(ChocolateyConfiguration configuration) | |
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,13 @@ | |
namespace chocolatey.infrastructure.app.services | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using configuration; | ||
|
||
public interface IChocolateyConfigSettingsService | ||
{ | ||
void noop(ChocolateyConfiguration configuration); | ||
void source_list(ChocolateyConfiguration configuration); | ||
IEnumerable<ChocolateySource> source_list(ChocolateyConfiguration configuration); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
void source_add(ChocolateyConfiguration configuration); | ||
void source_remove(ChocolateyConfiguration configuration); | ||
void source_disable(ChocolateyConfiguration configuration); | ||
|
@@ -32,4 +33,4 @@ public interface IChocolateyConfigSettingsService | |
string get_api_key(ChocolateyConfiguration configuration, Action<ConfigFileApiKeySetting> keyAction); | ||
void set_api_key(ChocolateyConfiguration configuration); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright © 2015 - 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.commands | ||
{ | ||
using System.Collections.Generic; | ||
using app.configuration; | ||
|
||
public interface IListCommand<out T> : ICommand | ||
{ | ||
IEnumerable<T> list(ChocolateyConfiguration config); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to push return statements to have an empty line before. This looks good though.