Rakis.Args 0.2.2

dotnet add package Rakis.Args --version 0.2.2
                    
NuGet\Install-Package Rakis.Args -Version 0.2.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="Rakis.Args" Version="0.2.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rakis.Args" Version="0.2.2" />
                    
Directory.Packages.props
<PackageReference Include="Rakis.Args" />
                    
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 Rakis.Args --version 0.2.2
                    
#r "nuget: Rakis.Args, 0.2.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 Rakis.Args@0.2.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=Rakis.Args&version=0.2.2
                    
Install as a Cake Addin
#tool nuget:?package=Rakis.Args&version=0.2.2
                    
Install as a Cake Tool

Rakis.Args - Parse Commandline arguments

Blame me for having a Unix background, but I simply got used to the way most GNU commandline software deals with arguments:

  • A command is given as a list of strings separated by spaces. This usually causes some confusion with Windows' insistence at using spaces in directory and filenames, combined with the lack of an "escape character" such as the back-slash. So, "Program Files" can be typed as "Program\ Files" in practically any shell on Linux, but not on Windows' CMD. There you need to put quotes around the complete argument, so ""C:\Program Files"" will work, but "C:\"Program Files"" will not.

    Anyway, using Git Bash or WSL2 will save your day here, but then you're in Linux-land.

  • A single dash ("-") starts one or more single-character options. If the option has an argument, it is the next argument in the line. If you happen to add multiple option-characters with an argument, you can get into trouble, but it is best to just continue with a fresh dash and a new set. So, if "-a and "-c" require arguments, don't try "some-command -abcd arg1 arg2" but instead use "some-command -a arg1 -bc arg2 -d".

  • A double-dash ("--") starts an option with a spelled-out name. These names tend to use "kebab-case" rather than "camelCase" to show where individual words are ending, although I see a number of "single-dash-camel-case" options in e.g. the "nuget" and "dotnet" CLI tools. For arguments to long option-names, the GNU standard is to use an equals sign and a value, without spaces around it. This is helped by the fact that Unix shells allow you to put quotes anywhere, so you can do "--data="This is a long argument with a lot of text"". On Windows you'll have to put the first quote before the first dash. Double-dash arguments cannot be combined, so each will need to become a separate argument.

    Generally all arguments are available as a double-dash variant with an easily recognizable name that explains its purpose. The most common ones then get a single-character version.

Some options are common enough to have become standard:

  • "-h" (sometimes "-?", but not often) and "--help" ask for the program to print out a list of all possible options and their meaning. The program is not expected to do anything beyond that.
  • "--version" asks for the program to print out version information and, again, not to do anything beyond that.
  • "-o <path>" usually specifies an output filename.
  • "-f <path>" usually specifies an input filename or "the" file.
  • "-v" asks for the program to be (more) verbose, providing feedback on what it is doing.
  • "-d" is sometimes used to request very verbose output, to debug a potential issue.
  • If arguments (without an option specifier) are used for one or more input files, a single dash instead is taken to mean "read from standard input".
  • An alternative use of a single dash is to tell the argument parser the explicit end of the list, allowing you to put arguments beyond that point that will start with a dash.

Release notes

Version 0.2.2

  • Made library multi-platform.

Usage

Create an ArgParser object and pass it the array of arguments, then use this to add Options. When done, call Parse() to obtain an Args object that can be queried.

  String[] args = { "--verbose", "-f", "file.txt" };

  var args = new ArgParser(args)
      .WithOption('v', "verbose")
      .WithOption("help")
      .WithOption("f", true)
      .Parse();

  if (args.Has("help")) {
    Console.WriteLine("Ask and you will be given...");
    return;
  }
  if (args.Has('v')) { // Both 'v' and "verbose" will work.
    Console.WriteLine("Starting program...");
  }
  using StreamReader f = new(args['f']);
  ... read file ...
...
}
Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed.  net8.0-windows7.0 is compatible.  net9.0-windows 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.2.2 244 8/8/2024
0.2.1 251 2/11/2024
0.2.0 465 12/28/2022
0.1.5 441 12/26/2022