summaryrefslogtreecommitdiffstats
path: root/src/main.lib/Configuration/BaseArgumentsProvider.cs
diff options
context:
space:
mode:
authorWouter Tinus <wouter.tinus@gmail.com>2020-05-14 20:26:28 +0200
committerWouter Tinus <wouter.tinus@gmail.com>2020-05-14 20:26:28 +0200
commit66ca970cbf63b871848f95b43e9066b7d934d148 (patch)
tree562b08a33da2548b4cb3cd3c543a0ca313e1174b /src/main.lib/Configuration/BaseArgumentsProvider.cs
parentdadac67bcc6fd786e34018a12eb361040528155d (diff)
downloadletsencrypt-win-simple-66ca970cbf63b871848f95b43e9066b7d934d148.zip
letsencrypt-win-simple-66ca970cbf63b871848f95b43e9066b7d934d148.tar.gz
letsencrypt-win-simple-66ca970cbf63b871848f95b43e9066b7d934d148.tar.bz2
improve logging for invalid command lines
Diffstat (limited to 'src/main.lib/Configuration/BaseArgumentsProvider.cs')
-rw-r--r--src/main.lib/Configuration/BaseArgumentsProvider.cs18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/main.lib/Configuration/BaseArgumentsProvider.cs b/src/main.lib/Configuration/BaseArgumentsProvider.cs
index e365084..df42949 100644
--- a/src/main.lib/Configuration/BaseArgumentsProvider.cs
+++ b/src/main.lib/Configuration/BaseArgumentsProvider.cs
@@ -8,6 +8,7 @@ namespace PKISharp.WACS.Configuration
public abstract class BaseArgumentsProvider<T> : IArgumentsProvider<T> where T : class, new()
{
private readonly FluentCommandLineParser<T> _parser;
+ public ILogService? Log { get; set; }
public BaseArgumentsProvider()
{
@@ -67,31 +68,36 @@ namespace PKISharp.WACS.Configuration
return false;
}
- public virtual bool Validate(ILogService log, T current, MainArguments main)
+ public virtual bool Validate(T current, MainArguments main)
{
if (main.Renew)
{
if (IsActive(current))
{
- log.Error($"Renewal {(string.IsNullOrEmpty(Group)?"":$"{Group} ")}parameters cannot be changed during a renewal. Recreate/overwrite the renewal or edit the .json file if you want to make changes.");
+ Log?.Error($"Renewal {(string.IsNullOrEmpty(Group)?"":$"{Group} ")}parameters cannot be changed during a renewal. Recreate/overwrite the renewal or edit the .json file if you want to make changes.");
return false;
}
}
return true;
}
- bool IArgumentsProvider.Validate(ILogService log, object current, MainArguments main) => Validate(log, (T)current, main);
+ bool IArgumentsProvider.Validate(object current, MainArguments main) => Validate((T)current, main);
public IEnumerable<ICommandLineOption> Configuration => _parser.Options;
public ICommandLineParserResult GetParseResult(string[] args) => _parser.Parse(args);
- public T GetResult(string[] args)
+ public T? GetResult(string[] args)
{
- _parser.Parse(args);
+ var result = _parser.Parse(args);
+ if (result.HasErrors)
+ {
+ Log?.Error(result.ErrorText);
+ return null;
+ }
return _parser.Object;
}
- object IArgumentsProvider.GetResult(string[] args) => GetResult(args);
+ object? IArgumentsProvider.GetResult(string[] args) => GetResult(args);
}
} \ No newline at end of file