From 8a8b16c655778e19687cb648f729ffc8886ffc95 Mon Sep 17 00:00:00 2001 From: Matthias Langhard Date: Thu, 4 Nov 2021 21:13:40 +0100 Subject: [PATCH] feat: implements better commandline args parsing with '--version' and '--help' outputs --- src/Cli/Cli.csproj | 4 +++- src/Cli/Models/CliParams.cs | 10 ++++++++++ src/Cli/Program.cs | 10 ++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/Cli/Models/CliParams.cs diff --git a/src/Cli/Cli.csproj b/src/Cli/Cli.csproj index 2c9a5ac..830fdaa 100644 --- a/src/Cli/Cli.csproj +++ b/src/Cli/Cli.csproj @@ -6,10 +6,11 @@ Cli true update-tag + update-tag Novaloop.UpdateTag Updates the tag of a repo to the next chosen version according the semver symantic. semver;update-tag;tag;git - 0.4.0 + 0.5.0 Matthias Langhard Novaloop AG https://gitlab.com/novaloop-oss/novaloop.update-tag @@ -18,6 +19,7 @@ + diff --git a/src/Cli/Models/CliParams.cs b/src/Cli/Models/CliParams.cs new file mode 100644 index 0000000..9a77b8c --- /dev/null +++ b/src/Cli/Models/CliParams.cs @@ -0,0 +1,10 @@ +using CommandLine; + +namespace Cli.Models +{ + public class CliParams + { + [Option('r', "repository-path", Required = false, HelpText = "Run update-tag on a git repository other than the current directory.")] + public string RepositoryPath { get; set; } + } +} \ No newline at end of file diff --git a/src/Cli/Program.cs b/src/Cli/Program.cs index 869d98b..77722c9 100644 --- a/src/Cli/Program.cs +++ b/src/Cli/Program.cs @@ -1,7 +1,8 @@ using System; -using System.Linq; using System.Threading.Tasks; using Application; +using Cli.Models; +using CommandLine; using Infrastructure; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; @@ -21,9 +22,14 @@ namespace Cli .ServiceProvider .GetRequiredService(); - await appRunner.Run(args.FirstOrDefault() ?? Environment.CurrentDirectory); + await Parser.Default + .ParseArguments(args) + .WithParsedAsync( + async options => { await appRunner.Run(options.RepositoryPath ?? Environment.CurrentDirectory); } + ); } + private static IHostBuilder CreateHostBuilder() { return Host.CreateDefaultBuilder()