From 9027f28065f9af907ee46e9ea871e090de96618f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Fri, 1 Mar 2024 22:39:02 +0100 Subject: [PATCH] Add -h --help aliases for help --- src/Alma.Abstraction/Command/ICommand.cs | 5 +++-- src/Alma.App/Application.cs | 1 - src/Alma.App/Command/Configure/ConfigureCommand.cs | 2 +- src/Alma.App/Command/Diag/DiagCommand.cs | 2 ++ src/Alma.App/Command/Help/HelpCommand.cs | 2 ++ src/Alma.App/Command/Info/InfoCommand.cs | 1 + src/Alma.App/Command/Install/InstallCommand.cs | 3 +-- src/Alma.App/Command/Link/LinkCommand.cs | 2 +- src/Alma.App/Command/List/ListCommand.cs | 1 + src/Alma.App/Command/RepositoryModuleCommandBase.cs | 2 ++ src/Alma.App/Command/Unlink/UnlinkCommand.cs | 1 + src/Alma.App/Services/ConfigurationFileReader.cs | 9 ++++++++- src/Alma.App/Services/JsonConfigurationFileReader.cs | 8 +++++++- src/Alma/Alma.csproj | 2 +- src/Alma/Program.cs | 4 +--- 15 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/Alma.Abstraction/Command/ICommand.cs b/src/Alma.Abstraction/Command/ICommand.cs index 3d0d2e4..2c2f917 100644 --- a/src/Alma.Abstraction/Command/ICommand.cs +++ b/src/Alma.Abstraction/Command/ICommand.cs @@ -2,6 +2,7 @@ namespace Alma.Command; public interface ICommand { - public string CommandString { get; } - public Task Run(List parameters); + string CommandString { get; } + string[] CommandAliases { get; } + Task Run(List parameters); } \ No newline at end of file diff --git a/src/Alma.App/Application.cs b/src/Alma.App/Application.cs index 58c54c5..db06e0a 100644 --- a/src/Alma.App/Application.cs +++ b/src/Alma.App/Application.cs @@ -1,5 +1,4 @@ using Alma.Command; -using Alma.Command.Help; using Alma.Logging; namespace Alma; diff --git a/src/Alma.App/Command/Configure/ConfigureCommand.cs b/src/Alma.App/Command/Configure/ConfigureCommand.cs index 3e2df8f..9ce2110 100644 --- a/src/Alma.App/Command/Configure/ConfigureCommand.cs +++ b/src/Alma.App/Command/Configure/ConfigureCommand.cs @@ -1,6 +1,5 @@ using Alma.Command.Install; using Alma.Configuration.Repository; -using Alma.Data; using Alma.Logging; using Alma.Services; @@ -11,6 +10,7 @@ public class ConfigureCommand : RepositoryModuleCommandBase private readonly ILogger _logger; private readonly IShellService _shellService; public override string CommandString => "configure"; + public override string[] CommandAliases => Array.Empty(); public ConfigureCommand( ILogger logger, diff --git a/src/Alma.App/Command/Diag/DiagCommand.cs b/src/Alma.App/Command/Diag/DiagCommand.cs index 452f3a9..a727c11 100644 --- a/src/Alma.App/Command/Diag/DiagCommand.cs +++ b/src/Alma.App/Command/Diag/DiagCommand.cs @@ -7,6 +7,8 @@ public class DiagCommand : ICommand { private readonly ILogger _logger; public string CommandString => "diag"; + public string[] CommandAliases => Array.Empty(); + private readonly Lazy> _diagnosticHelpersLazy; public DiagCommand(ILogger logger) diff --git a/src/Alma.App/Command/Help/HelpCommand.cs b/src/Alma.App/Command/Help/HelpCommand.cs index fd87431..e979dd7 100644 --- a/src/Alma.App/Command/Help/HelpCommand.cs +++ b/src/Alma.App/Command/Help/HelpCommand.cs @@ -9,6 +9,8 @@ public class HelpCommand : ICommand public string CommandString => "help"; + public string[] CommandAliases { get; } = ["--help", "-h"]; + public HelpCommand( IServiceProvider serviceProvider, ILogger logger diff --git a/src/Alma.App/Command/Info/InfoCommand.cs b/src/Alma.App/Command/Info/InfoCommand.cs index d0948a8..3bf0dbd 100644 --- a/src/Alma.App/Command/Info/InfoCommand.cs +++ b/src/Alma.App/Command/Info/InfoCommand.cs @@ -9,6 +9,7 @@ namespace Alma.Command.Info; public class InfoCommand : RepositoryModuleCommandBase { public override string CommandString => "info"; + public override string[] CommandAliases => Array.Empty(); private readonly IFolderService _folderService; private readonly IRepositoryConfiguration _repositoryConfiguration; diff --git a/src/Alma.App/Command/Install/InstallCommand.cs b/src/Alma.App/Command/Install/InstallCommand.cs index 45ca05e..07709e7 100644 --- a/src/Alma.App/Command/Install/InstallCommand.cs +++ b/src/Alma.App/Command/Install/InstallCommand.cs @@ -1,6 +1,4 @@ -using System.Diagnostics; using Alma.Configuration.Repository; -using Alma.Data; using Alma.Logging; using Alma.Services; @@ -11,6 +9,7 @@ public class InstallCommand : RepositoryModuleCommandBase private readonly ILogger _logger; private readonly IShellService _shellService; public override string CommandString => "install"; + public override string[] CommandAliases => Array.Empty(); public InstallCommand( ILogger logger, diff --git a/src/Alma.App/Command/Link/LinkCommand.cs b/src/Alma.App/Command/Link/LinkCommand.cs index 3d6d063..b67462f 100644 --- a/src/Alma.App/Command/Link/LinkCommand.cs +++ b/src/Alma.App/Command/Link/LinkCommand.cs @@ -2,7 +2,6 @@ using System.Runtime.InteropServices; using Alma.Configuration.Module; using Alma.Configuration.Repository; using Alma.Data; -using Alma.Helper; using Alma.Logging; using Alma.Services; @@ -17,6 +16,7 @@ public class LinkCommand : RepositoryModuleCommandBase private readonly ILogger _logger; public override string CommandString => "link"; + public override string[] CommandAliases => Array.Empty(); public LinkCommand( IRepositoryConfiguration repositoryConfiguration, diff --git a/src/Alma.App/Command/List/ListCommand.cs b/src/Alma.App/Command/List/ListCommand.cs index 0e980ea..9bc56ea 100644 --- a/src/Alma.App/Command/List/ListCommand.cs +++ b/src/Alma.App/Command/List/ListCommand.cs @@ -12,6 +12,7 @@ public class ListCommand : ICommand private readonly ILogger _logger; public string CommandString => "ls"; + public string[] CommandAliases => Array.Empty(); public ListCommand( IRepositoryConfiguration repositoryConfiguration, diff --git a/src/Alma.App/Command/RepositoryModuleCommandBase.cs b/src/Alma.App/Command/RepositoryModuleCommandBase.cs index efb5511..cc00ea4 100644 --- a/src/Alma.App/Command/RepositoryModuleCommandBase.cs +++ b/src/Alma.App/Command/RepositoryModuleCommandBase.cs @@ -10,6 +10,8 @@ public abstract class RepositoryModuleCommandBase : ICommand private readonly IModuleConfigurationResolver _moduleConfigurationResolver; private readonly IPathHelperService _pathHelperService; public abstract string CommandString { get; } + public abstract string[] CommandAliases { get; } + public abstract Task Run(List parameters); protected RepositoryModuleCommandBase( diff --git a/src/Alma.App/Command/Unlink/UnlinkCommand.cs b/src/Alma.App/Command/Unlink/UnlinkCommand.cs index 48e97ef..11228e7 100644 --- a/src/Alma.App/Command/Unlink/UnlinkCommand.cs +++ b/src/Alma.App/Command/Unlink/UnlinkCommand.cs @@ -3,6 +3,7 @@ namespace Alma.Command.Unlink; public class UnlinkCommand : ICommand { public string CommandString => "unlink"; + public string[] CommandAliases => Array.Empty(); public Task Run(List parameters) { throw new NotImplementedException(); diff --git a/src/Alma.App/Services/ConfigurationFileReader.cs b/src/Alma.App/Services/ConfigurationFileReader.cs index 08e23bf..1073b08 100644 --- a/src/Alma.App/Services/ConfigurationFileReader.cs +++ b/src/Alma.App/Services/ConfigurationFileReader.cs @@ -19,7 +19,14 @@ public class ConfigurationFileReader { foreach (var configurationFileReader in _configurationFileReaders) { - if (await configurationFileReader.DeserializeAsync(fileNameWithoutExtension, contextGenerator, extension) is { Result: { } } result) return result; + if (await configurationFileReader.DeserializeAsync( + fileNameWithoutExtension, + contextGenerator, + extension) is { Result: { } } result + ) + { + return result; + } } return (null, null); diff --git a/src/Alma.App/Services/JsonConfigurationFileReader.cs b/src/Alma.App/Services/JsonConfigurationFileReader.cs index eb25d12..12bed0f 100644 --- a/src/Alma.App/Services/JsonConfigurationFileReader.cs +++ b/src/Alma.App/Services/JsonConfigurationFileReader.cs @@ -17,6 +17,12 @@ public class JsonConfigurationFileReader : IConfigurationFileReader if (!File.Exists(fileName)) return (null, null); await using FileStream openStream = File.OpenRead(fileName); - return ((T?)await JsonSerializer.DeserializeAsync(openStream, typeof(T), contextGenerator(new JsonSerializerOptions(DefaultOptions))), fileName); + var result = + (T?)await JsonSerializer.DeserializeAsync( + openStream, + typeof(T), + contextGenerator(new JsonSerializerOptions(DefaultOptions)) + ); + return (result, fileName); } } \ No newline at end of file diff --git a/src/Alma/Alma.csproj b/src/Alma/Alma.csproj index d9c8f01..304af61 100644 --- a/src/Alma/Alma.csproj +++ b/src/Alma/Alma.csproj @@ -14,7 +14,7 @@ net8.0 enable enable - 0.0.0 + 0.0.4 development diff --git a/src/Alma/Program.cs b/src/Alma/Program.cs index 8546f1d..9381555 100644 --- a/src/Alma/Program.cs +++ b/src/Alma/Program.cs @@ -1,6 +1,4 @@ -using System.IO; -using System; -using Alma.Command; +using Alma.Command; using Alma.Command.Configure; using Alma.Command.Diag; using Alma.Command.Help;