Altinn.Authorization.CommandLine.Azure.KeyVault
1.0.0
dotnet add package Altinn.Authorization.CommandLine.Azure.KeyVault --version 1.0.0
NuGet\Install-Package Altinn.Authorization.CommandLine.Azure.KeyVault -Version 1.0.0
<PackageReference Include="Altinn.Authorization.CommandLine.Azure.KeyVault" Version="1.0.0" />
<PackageVersion Include="Altinn.Authorization.CommandLine.Azure.KeyVault" Version="1.0.0" />
<PackageReference Include="Altinn.Authorization.CommandLine.Azure.KeyVault" />
paket add Altinn.Authorization.CommandLine.Azure.KeyVault --version 1.0.0
#r "nuget: Altinn.Authorization.CommandLine.Azure.KeyVault, 1.0.0"
#:package Altinn.Authorization.CommandLine.Azure.KeyVault@1.0.0
#addin nuget:?package=Altinn.Authorization.CommandLine.Azure.KeyVault&version=1.0.0
#tool nuget:?package=Altinn.Authorization.CommandLine.Azure.KeyVault&version=1.0.0
Altinn.Authorization.CommandLine
Altinn.Authorization.CommandLine is a small framework for building hosted command line applications. It combines
System.CommandLine, Microsoft.Extensions.Hosting, dependency injection, and Spectre.Console-backed output behind a
simple application builder.
Installation
Install the package with the .NET CLI:
dotnet add package Altinn.Authorization.CommandLine
Or with the NuGet Package Manager Console:
Install-Package Altinn.Authorization.CommandLine
Usage
Create a builder, register any application services, build the CliApplication, add commands, and run the application
with the process arguments.
using Altinn.Authorization.CommandLine;
using Microsoft.Extensions.Logging;
var builder = CliApplication.CreateBuilder("Example command line application");
var cli = builder.Build();
cli.AddCommand("hello", "Writes a greeting", (
[Argument] string name,
ILogger<Program> logger) =>
{
logger.LogInformation("Hello, {name}!", name);
});
return await cli.RunAsync(args);
Commands can also be implemented as handler types. The handler is constructed from the application service provider for each invocation and disposed after it runs.
using Altinn.Authorization.CommandLine;
using Altinn.Authorization.CommandLine.Results;
using Microsoft.Extensions.Logging;
using Spectre.Console;
var builder = CliApplication.CreateBuilder("Example command line application");
var cli = builder.Build();
cli.AddCommand<GreetCommand>("hello", "Writes a greeting");
return await cli.RunAsync(args);
internal sealed class GreetCommand(ILogger<GreetCommand> logger)
{
public GreetingResult Invoke(
[Option("--times", "-t")] int times = 5,
[Argument] string message = "Hello, world!")
{
for (var i = 0; i < times; i++)
{
logger.LogInformation("Greeting: {message}", message);
}
return new GreetingResult(message);
}
}
internal sealed class GreetingResult(string message)
: ICommandResult
{
public Task Execute(CommandInvocationContext context, CancellationToken cancellationToken = default)
{
context.Console.WriteLine(message);
return Task.CompletedTask;
}
}
Parameter Binding
Handler parameters are bound by the command handler factory:
[Argument]binds a parameter from a command line argument.[Option]binds a parameter from a command line option. The default option name is--{parameterName}.CommandInvocationContext,CancellationToken,IConsole,ParseResult, andIServiceProviderare injected from the current invocation.- Service parameters are resolved from dependency injection when the service provider reports that the parameter type is registered.
- Custom parameter attributes can implement
IFromArgumentMetadata,IFromOptionMetadata, orIFromServiceMetadatafor specialized binding.
Parameters with default values are treated as optional. Nullable parameters are also optional according to the parameter nullability metadata.
Return Values
Handlers can return:
void,Task, orValueTask.T,Task<T>, orValueTask<T>when anICommandResultHandlerResolvercan resolve a handler forT.ICommandResult, which is executed directly.
An int result handler is registered by default and maps the returned value to the command return code.
Middleware
Commands expose a middleware pipeline through ICommandBuilder.Middleware.
cli.Middleware.Add(async (context, next, cancellationToken) =>
{
var started = DateTimeOffset.UtcNow;
await next(context, cancellationToken);
var elapsed = DateTimeOffset.UtcNow - started;
context.Console.MarkupLineInterpolated($"Completed in {elapsed.TotalMilliseconds:N0} ms");
});
Contributing
Contributions to Altinn.Authorization.CommandLine are welcome. Open an issue for bugs or feature requests, or submit a
pull request with the proposed changes.
License
Altinn.Authorization.CommandLine is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Altinn.Authorization.CommandLine (>= 1.0.0)
- Altinn.Authorization.CommandLine.Azure (>= 1.0.0)
- Azure.Identity (>= 1.21.0)
- Azure.Security.KeyVault.Secrets (>= 4.11.0)
- CommunityToolkit.Diagnostics (>= 8.4.2)
- Microsoft.Extensions.AsyncState (>= 10.9.0)
- Microsoft.Extensions.Hosting (>= 10.0.11)
- Microsoft.Extensions.Options (>= 10.0.11)
- Nerdbank.Streams (>= 2.13.31)
- Spectre.Console (>= 0.57.2)
- System.CommandLine (>= 2.0.11)
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 |
|---|---|---|
| 1.0.0 | 44 | 8/25/2026 |
# Changelog
## 1.0.0 (2026-08-21)
### Features
* add argument preprocessor support ([#659](https://github.com/Altinn/altinn-authorization-utils/issues/659)) ([61e0466](https://github.com/Altinn/altinn-authorization-utils/commit/61e0466dff0f745adf1d5349e29df5548dd42b8c))
* add command execution helper ([#654](https://github.com/Altinn/altinn-authorization-utils/issues/654)) ([ccee390](https://github.com/Altinn/altinn-authorization-utils/commit/ccee39086a94f152b062a11de9c942c4ff6b78b0))
* add formatting handling to the cli ([#642](https://github.com/Altinn/altinn-authorization-utils/issues/642)) ([6b26269](https://github.com/Altinn/altinn-authorization-utils/commit/6b26269de06aa2c4b7447d3ac6ca743bd156563a))
* add invocation extensions ([#647](https://github.com/Altinn/altinn-authorization-utils/issues/647)) ([8126203](https://github.com/Altinn/altinn-authorization-utils/commit/81262036272b3e029299fde10782af6eac9d3a08))
* add json pretty printing ([#641](https://github.com/Altinn/altinn-authorization-utils/issues/641)) ([487ec3a](https://github.com/Altinn/altinn-authorization-utils/commit/487ec3ac3c585495c10683b19046d31fe8783af8))
* add simple console pretty-printer ([#640](https://github.com/Altinn/altinn-authorization-utils/issues/640)) ([30c9728](https://github.com/Altinn/altinn-authorization-utils/commit/30c97280112d1783c7251d2a4de4a971726a33a0))
* allow command-factory more binding patters ([#643](https://github.com/Altinn/altinn-authorization-utils/issues/643)) ([0153c3f](https://github.com/Altinn/altinn-authorization-utils/commit/0153c3fdcd192b89f73b89ed3b8a29d07d40c777))
* async state ([#661](https://github.com/Altinn/altinn-authorization-utils/issues/661)) ([b78928d](https://github.com/Altinn/altinn-authorization-utils/commit/b78928d0654d798cb2857628756cf6529e2b8a5e))
* command metadata ([#635](https://github.com/Altinn/altinn-authorization-utils/issues/635)) ([d88702e](https://github.com/Altinn/altinn-authorization-utils/commit/d88702e315cbac055fc7552287f117705c96c886))
* create CommandLine library ([#627](https://github.com/Altinn/altinn-authorization-utils/issues/627)) ([dff0d56](https://github.com/Altinn/altinn-authorization-utils/commit/dff0d56a7469f3f8c8225973a394e406956f4031))
* customize enum argument handling ([#664](https://github.com/Altinn/altinn-authorization-utils/issues/664)) ([467c90f](https://github.com/Altinn/altinn-authorization-utils/commit/467c90f2bd0ca749fee309c58ebe8f423d82e35e))
* execute-command result ([#662](https://github.com/Altinn/altinn-authorization-utils/issues/662)) ([06b62f0](https://github.com/Altinn/altinn-authorization-utils/commit/06b62f0249e6fc8abb5ce9a7508a02f480c16ce8))
* github actions utils ([#663](https://github.com/Altinn/altinn-authorization-utils/issues/663)) ([a732a70](https://github.com/Altinn/altinn-authorization-utils/commit/a732a706394cde3b8aca04495c0256b2eb9951e8))
### Bug Fixes
* ensure timeprovider is registered ([#670](https://github.com/Altinn/altinn-authorization-utils/issues/670)) ([8616fd9](https://github.com/Altinn/altinn-authorization-utils/commit/8616fd9d2413c33a5439e04ede1d5e5c0eb2299c))