Suwbackkit.Cli 0.5.2

dotnet add package Suwbackkit.Cli --version 0.5.2
                    
NuGet\Install-Package Suwbackkit.Cli -Version 0.5.2
                    
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="Suwbackkit.Cli" Version="0.5.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Suwbackkit.Cli" Version="0.5.2" />
                    
Directory.Packages.props
<PackageReference Include="Suwbackkit.Cli" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Suwbackkit.Cli --version 0.5.2
                    
#r "nuget: Suwbackkit.Cli, 0.5.2"
                    
#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.
#:package Suwbackkit.Cli@0.5.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Suwbackkit.Cli&version=0.5.2
                    
Install as a Cake Addin
#tool nuget:?package=Suwbackkit.Cli&version=0.5.2
                    
Install as a Cake Tool

Suwbackkit.Cli

The skeleton the .NET command lines of Manomenu's apps share: a CLI that talks to a server built on Suwbackkit.Server. It holds only what every such CLI needs and knows nothing of any app; the commands, their output, exit codes and configuration files stay in the app. It depends on System.CommandLine and not on ASP.NET Core, so a CLI packed as a .NET tool needs no web framework.

  • ServerAddress.Choose(sources, fallback) picks the server's address from named sources, in order: the first AddressSource(name, value) whose value is not blank wins, and the later ones are not read (a value is a function, so a file is read only when it is needed); with none it is the fallback. The address must be http or https, else the AddressChoice holds no address and a Problem that names the source and gives the fallback as an example. An address ends in one /, so paths resolve under it; ServerAddress.Api(site) is the address of the API one folder api below the site, ServerAddress.Display(address) the address without its last /.
  • ServerRefusal.Read(body) reads the server's refusal, the format Suwbackkit.Server's Refusals.Refuse(...) writes: its Code, Title, Detail and every ServerMistake with its Code, Message, Fix, At, and its whole Json for what an app adds to a mistake. A field that is missing or not text is null; an answer that is no JSON object is no refusal (null). How it is printed is the app's.
  • WebPage.ShowAsync(page, output, error, openBrowser) prints the page's address and opens it in the default browser; with no browser the address stays printed and the error says to open it (WebPage.NoBrowser). Tests pass openBrowser.
  • CommandTree walks a System.CommandLine tree: Find(root, "facts show") finds a command by its words, All(root) gives every command below the root (each before its own subcommands), WordsOf(command) the words that run it. A test that checks every command (its help, its plugin docs, its route) walks the tree instead of copying a list.

Usage

using Suwbackkit.Cli;

var choice = ServerAddress.Choose(
    [
        new AddressSource("--server", () => option),
        new AddressSource("MYAPP_URL", () => Environment.GetEnvironmentVariable("MYAPP_URL")),
        new AddressSource("myappUrl in myapp/config.yaml", () => config?.MyappUrl),
    ],
    "http://localhost:3000"
);
if (choice.Address is not { } site)
{
    await error.WriteLineAsync(choice.Problem);
    return 2;
}
using var http = new HttpClient { BaseAddress = ServerAddress.Api(site) };
using var response = await http.GetAsync(new Uri("things", UriKind.Relative));
if (!response.IsSuccessStatusCode && ServerRefusal.Read(await response.Content.ReadAsStringAsync()) is { } refusal)
{
    foreach (var mistake in refusal.Mistakes)
    {
        await error.WriteLineAsync($"{mistake.At}: {mistake.Message} {mistake.Fix}");
    }
}

A test that every route the server maps has a command, with MappedRoutes from Suwbackkit.Testing:

var missing = MappedRoutes.Of(app.Services).Where(route => !Routes.ContainsKey(route));
var unknownCommands = Routes.Values.Where(words => CommandTree.Find(CliApp.Create(), words) is null);

Source, license and changes: https://github.com/Manomenu/suwbackkit

Product 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. 
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
0.5.2 52 11/22/2026
0.5.1 58 11/22/2026
0.5.0 72 11/21/2026