diff options
author | Wouter Tinus <win.acme.simple@gmail.com> | 2019-12-15 22:35:30 +0100 |
---|---|---|
committer | Wouter Tinus <win.acme.simple@gmail.com> | 2019-12-15 22:35:30 +0100 |
commit | 37409eec4ae574cc3e263a864d356e60094d8710 (patch) | |
tree | b0be4cf8b892cd26f2285e47d3ab5e6d0c01c559 /src/main.lib/Services/InputService.cs | |
parent | d0aa1b73e74365db83317ddd3c7fb0b72d073479 (diff) | |
download | letsencrypt-win-simple-37409eec4ae574cc3e263a864d356e60094d8710.zip letsencrypt-win-simple-37409eec4ae574cc3e263a864d356e60094d8710.tar.gz letsencrypt-win-simple-37409eec4ae574cc3e263a864d356e60094d8710.tar.bz2 |
fix last nullability annotations
Diffstat (limited to 'src/main.lib/Services/InputService.cs')
-rw-r--r-- | src/main.lib/Services/InputService.cs | 64 |
1 files changed, 33 insertions, 31 deletions
diff --git a/src/main.lib/Services/InputService.cs b/src/main.lib/Services/InputService.cs index ee01772..5781500 100644 --- a/src/main.lib/Services/InputService.cs +++ b/src/main.lib/Services/InputService.cs @@ -286,6 +286,28 @@ namespace PKISharp.WACS.Services } } + public async Task<TResult?> ChooseFromList<TSource, TResult>( + string what, IEnumerable<TSource> options, + Func<TSource, Choice<TResult?>> creator, + string nullLabel) where TResult : class + { + var baseChoices = options.Select(creator).ToList(); + if (!baseChoices.Any(x => !x.Disabled)) + { + _log.Warning("No options available"); + return default; + } + var defaults = baseChoices.Where(x => x.Default); + var cancel = Choice.Create(default(TResult), nullLabel, _cancelCommand); + if (defaults.Count() == 0) + { + cancel.Command = "<Enter>"; + cancel.Default = true; + } + baseChoices.Add(cancel); + return await ChooseFromList(what, baseChoices); + } + /// <summary> /// Print a (paged) list of targets for the user to choose from /// </summary> @@ -293,41 +315,12 @@ namespace PKISharp.WACS.Services public async Task<T> ChooseFromList<S, T>( string what, IEnumerable<S> options, - Func<S, Choice<T>> creator, - string? nullLabel = null) + Func<S, Choice<T>> creator) { var baseChoices = options.Select(creator).ToList(); - var allowNull = !string.IsNullOrEmpty(nullLabel); if (!baseChoices.Any(x => !x.Disabled)) { - if (allowNull) - { - _log.Warning("No options available"); - return default; - } - else - { - throw new Exception("No options available for required choice"); - } - } - var defaults = baseChoices.Where(x => x.Default); - if (defaults.Count() > 1) - { - throw new Exception("Multiple defaults provided"); - } - else if (defaults.Count() == 1 && defaults.First().Disabled) - { - throw new Exception("Default option is disabled"); - } - if (allowNull) - { - var cancel = Choice.Create(default(T), nullLabel, _cancelCommand); - if (defaults.Count() == 0) - { - cancel.Command = "<Enter>"; - cancel.Default = true; - } - baseChoices.Add(cancel); + throw new Exception("No options available for required choice"); } return await ChooseFromList(what, baseChoices); } @@ -342,6 +335,15 @@ namespace PKISharp.WACS.Services { throw new Exception("No options available"); } + var defaults = choices.Where(x => x.Default); + if (defaults.Count() > 1) + { + throw new Exception("Multiple defaults provided"); + } + else if (defaults.Count() == 1 && defaults.First().Disabled) + { + throw new Exception("Default option is disabled"); + } await WritePagedList(choices); |