Redpoint.CommandLine 2024.1165.792

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Redpoint.CommandLine --version 2024.1165.792                
NuGet\Install-Package Redpoint.CommandLine -Version 2024.1165.792                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Redpoint.CommandLine" Version="2024.1165.792" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Redpoint.CommandLine --version 2024.1165.792                
#r "nuget: Redpoint.CommandLine, 2024.1165.792"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Redpoint.CommandLine as a Cake Addin
#addin nuget:?package=Redpoint.CommandLine&version=2024.1165.792

// Install Redpoint.CommandLine as a Cake Tool
#tool nuget:?package=Redpoint.CommandLine&version=2024.1165.792                

Redpoint.CommandLine

This library provides APIs for building dependency injected console applications, with both commands and option declarations being dependency injected.

To use this library, first define your command:

internal class SomeAction
{
	public class Options
	{
		public Option<string> SomeOpt = new Option<string>("--opt", "My option description.");

		// Add more fields or properties that use Option<> or Argument<> and they'll be automatically
		// registered to the command line parser.
	}

	public static Command CreateCommand(ICommandBuilder builder)
	{
		return new Command("some-action", "The description of your some-action command.");
	}

	public class CommandInstance : ICommandInstance
	{
        private readonly ILogger<CommandInstance> _logger;
        private readonly Options _options;

        public CommandInstance(
            ILogger<CommandInstance> logger,
            Options options)
        {
            _logger = logger;
            _options = options;
        }

        public Task<int> ExecuteAsync(ICommandInvocationContext context)
        {
            // Example on how to access an option's value.
            var value = context.ParseResult.GetValueForOption(_options.SomeOpt);

            // ... implement your command here ...
            _logger.LogInformation("Hello world!");

            // Return the exit code for the application.
            return Task.FromResult(0);
        }
	}
}

To register and execute commands, in your Program.Main:

// Use the command line builder APIs to build the root command.
var rootCommand = CommandLineBuilder.NewBuilder()
    .AddGlobalRuntimeServices((builder, services) =>
    {
        // Register global runtime services here, such as services.AddLogging(...)
    })
    .SetGlobalExecutionHandler(async (sp, executeCommand) =>
    {
        // Can be used to wrap execution of all commands, such as capturing
        // exceptions and logging them:

        var logger = sp.GetRequiredService<ILogger<Program>>();
        try
        {
            return await executeCommand().ConfigureAwait(true);
        }
        catch (Exception ex)
        {
            logger.LogError(ex, $"Uncaught exception during command execution: {ex}");
            return 1;
        }
    })
    // Add each of your commands like this:
    .AddCommand<SomeAction.CommandInstance, SomeAction.Options>(SomeAction.CreateCommand)
    // Then build the root command to use below.
    .Build("My console application description.");

// Parse and execute the command.
var exitCode = await rootCommand.InvokeAsync(args).ConfigureAwait(false);
await Console.Out.FlushAsync().ConfigureAwait(false);
await Console.Error.FlushAsync().ConfigureAwait(false);
Environment.Exit(exitCode);
throw new BadImageFormatException();
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2024.1242.282 80 8/29/2024
2024.1242.261 71 8/29/2024
2024.1242.233 72 8/29/2024
2024.1238.829 92 8/25/2024
2024.1238.327 90 8/25/2024
2024.1225.297 84 8/12/2024
2024.1205.140 63 7/23/2024
2024.1204.110 82 7/22/2024
2024.1204.62 64 7/22/2024
2024.1190.491 86 7/8/2024
2024.1177.305 85 6/25/2024
2024.1168.700 82 6/16/2024
2024.1168.649 82 6/16/2024
2024.1168.535 84 6/16/2024
2024.1167.643 79 6/15/2024
2024.1166.989 84 6/14/2024
2024.1166.818 76 6/14/2024
2024.1166.535 79 6/14/2024
2024.1166.422 78 6/14/2024
2024.1166.362 81 6/14/2024
2024.1166.360 81 6/14/2024
2024.1165.1212 76 6/13/2024
2024.1165.1160 75 6/13/2024
2024.1165.1019 74 6/13/2024
2024.1165.978 78 6/13/2024
2024.1165.920 73 6/13/2024
2024.1165.908 76 6/13/2024
2024.1165.873 75 6/13/2024
2024.1165.830 77 6/13/2024
2024.1165.806 75 6/13/2024
2024.1165.794 74 6/13/2024
2024.1165.792 76 6/13/2024
2024.1165.761 77 6/13/2024
2024.1165.743 73 6/13/2024
2024.1165.735 75 6/13/2024
2024.1165.713 82 6/13/2024
2024.1165.640 78 6/13/2024
2024.1165.574 81 6/13/2024
2024.1165.466 74 6/13/2024
2024.1165.417 77 6/13/2024
2024.1165.392 76 6/13/2024
2024.1164.341 67 6/12/2024
2024.1155.941 87 6/3/2024
2024.1140.783 88 5/19/2024
2024.1140.692 80 5/19/2024
2024.1140.673 81 5/19/2024
2024.1129.506 89 5/8/2024
2024.1128.831 92 5/7/2024
2024.1124.465 59 5/3/2024
2024.1123.1162 56 5/2/2024
2024.1123.1117 51 5/2/2024
2024.1123.1050 48 5/2/2024
2024.1122.352 86 5/1/2024
2024.1122.233 82 5/1/2024
2024.1115.1101 100 4/24/2024
2024.1115.1048 72 4/24/2024
2024.1115.932 95 4/24/2024
2024.1115.858 79 4/24/2024
2024.1115.665 94 4/24/2024
2024.1115.648 84 4/24/2024
2024.1115.591 83 4/24/2024
2024.1101.390 92 4/10/2024
2024.1100.741 95 4/9/2024
2024.1099.526 87 4/8/2024
2024.1099.466 81 4/8/2024
2024.1098.573 93 4/7/2024
2024.1095.977 90 4/4/2024
2024.1095.847 85 4/4/2024
2024.1095.604 94 4/4/2024
2024.1095.485 90 4/4/2024
2024.1094.930 87 4/3/2024
2024.1094.910 91 4/3/2024
2024.1094.387 90 4/3/2024
2024.1094.313 93 4/3/2024
2024.1093.520 104 4/2/2024
2024.1092.240 98 4/1/2024
2024.1089.1425 88 3/29/2024
2024.1089.983 92 3/29/2024
2024.1089.942 79 3/29/2024
2024.1089.2 92 3/29/2024
2024.1088.1343 96 3/28/2024
2024.1088.1139 93 3/28/2024
2024.1088.875 93 3/28/2024
2024.1088.700 102 3/28/2024
2024.1088.603 94 3/28/2024
2024.1088.590 84 3/28/2024
2024.1088.575 97 3/28/2024
2024.1088.561 92 3/28/2024
2024.1088.506 90 3/28/2024
2024.1088.18 93 3/28/2024
2024.1087.1181 103 3/27/2024
2024.1087.1173 87 3/27/2024
2024.1087.1143 98 3/27/2024
2024.1087.1108 100 3/27/2024
2024.1087.950 111 3/27/2024
2024.1087.939 105 3/27/2024
2024.1087.252 92 3/27/2024
2024.1070.736 103 3/10/2024
2024.1049.1437 108 2/19/2024
2024.1036.571 109 2/5/2024
2024.1036.508 86 2/5/2024
2024.1032.1204 98 2/1/2024
2024.1032.1133 89 2/1/2024
2024.1032.1122 86 2/1/2024
2024.1032.1071 83 2/1/2024
2024.1032.940 91 2/1/2024
2024.1031.912 86 1/31/2024
2024.1031.893 83 1/31/2024
2024.1031.851 80 1/31/2024
2024.1031.829 81 1/31/2024
2024.1031.386 84 1/31/2024
2024.1031.318 84 1/31/2024
2024.1017.460 113 1/17/2024
2024.1017.420 90 1/17/2024
2024.1017.163 94 1/17/2024
2024.1016.414 264 1/16/2024
2024.1012.167 100 1/12/2024
2024.1011.406 107 1/11/2024
2024.1010.315 99 1/10/2024
2023.1358.326 127 12/24/2023
2023.1351.473 117 12/17/2023
2023.1351.445 87 12/17/2023
2023.1351.432 93 12/17/2023
2023.1350.478 97 12/16/2023
2023.1344.600 106 12/10/2023
2023.1344.529 94 12/10/2023
2023.1339.582 118 12/5/2023
2023.1338.1072 98 12/4/2023
2023.1336.844 117 12/2/2023
2023.1335.378 107 12/1/2023
2023.1335.236 111 12/1/2023
2023.1335.203 101 12/1/2023
2023.1334.814 119 11/30/2023
2023.1332.652 109 11/28/2023
2023.1332.622 107 11/28/2023
2023.1332.524 122 11/28/2023
2023.1331.1073 85 11/27/2023
2023.1331.423 108 11/27/2023
2023.1328.513 108 11/24/2023
2023.1327.985 115 11/23/2023
2023.1325.593 103 11/21/2023
2023.1325.551 125 11/21/2023
2023.1325.529 119 11/21/2023