htcw_CliUtility 1.0.1

Additional Details

This package has a bug with not adding optional named switches

There is a newer version of this package available.
See the version list below for details.
dotnet add package htcw_CliUtility --version 1.0.1                
NuGet\Install-Package htcw_CliUtility -Version 1.0.1                
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="htcw_CliUtility" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add htcw_CliUtility --version 1.0.1                
#r "nuget: htcw_CliUtility, 1.0.1"                
#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 htcw_CliUtility as a Cake Addin
#addin nuget:?package=htcw_CliUtility&version=1.0.1

// Install htcw_CliUtility as a Cake Tool
#tool nuget:?package=htcw_CliUtility&version=1.0.1                

CliUtility

Provides command line argument parsing, usage screen generation, word wrapping and stale file checking useful for CLI apps

Command Line Parsing

There are two ways to do command line argument definitions. One way is to build a list of CmdSwitch instances. The other way is to use the [CmdArg(...)] attribute to mark up static fields or properties on a type (typically your main Program class). Those fields can then be automatically filled in by this library.

the function ParseArguments() can be used to retrieve the parsed information or ParseAndSet() if using the [CmdArg()] method which handles reflecting, parsing, and setting the fields.

Simple example

A simple word wrapping application that takes a series of input files and an optional switch "wrap" that specifies the columns to wrap to:

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

using Cli;

[assembly: AssemblyDescription("An example of command line argument processing")]

internal class Program
{
	[CmdArg(Ordinal = 0)]
	static TextReader[] inputs = { Console.In };
	[CmdArg(Optional = true, Description = "The width to wrap to in characters")]
	static int wrap = Console.WindowWidth;
	static void Main()
	{
		try
		{

			using (var result = CliUtility.ParseAndSet(typeof(Program)))
			{
				foreach (var input in inputs)
				{
					Console.WriteLine();
					Console.WriteLine(CliUtility.WordWrap(input.ReadToEnd(), wrap));

				}
			}
		}
		catch (Exception ex)
		{
			Console.Error.WriteLine(ex.Message);
		}
	}
}

The following using screen is produced:

Example v1.0.0.0

An example of command line argument processing

Usage: Example { <inputfile1>,  <inputfile2>, ... } [ /wrap <item> ]

    <inputfile> The input file. Defaults to <stdin>
    <item>      The width to wrap to in characters. Defaults to 120
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.
  • net7.0

    • No dependencies.

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.4.0 65 11/19/2024
1.3.1 63 11/18/2024
1.3.0 64 11/18/2024
1.1.3 60 11/18/2024
1.1.2 70 11/18/2024 1.1.2 is deprecated.
1.1.1 61 11/17/2024
1.1.0 68 11/17/2024 1.1.0 is deprecated.
1.0.2 76 11/16/2024 1.0.2 is deprecated.
1.0.1 79 11/16/2024 1.0.1 is deprecated.
1.0.0 79 11/16/2024 1.0.0 is deprecated.