Skip to content

Commit

Permalink
Add ArgsReader docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejball committed Feb 18, 2024
1 parent 6b2bf8c commit 451f9ea
Show file tree
Hide file tree
Showing 18 changed files with 331 additions and 10 deletions.
10 changes: 10 additions & 0 deletions ArgsReading.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# ArgsReading assembly

## ArgsReading namespace

| public type | description |
| --- | --- |
| class [ArgsReader](./ArgsReading/ArgsReader.md) | Helps process command-line arguments. |
| class [ArgsReaderException](./ArgsReading/ArgsReaderException.md) | Thrown when an error occurs while processing command-line arguments. |

<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
33 changes: 33 additions & 0 deletions ArgsReading/ArgsReader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ArgsReader class

Helps process command-line arguments.

```csharp
public sealed class ArgsReader
```

## Public Members

| name | description |
| --- | --- |
| [ArgsReader](ArgsReader/ArgsReader.md)(…) | Creates a reader for the specified command-line arguments. |
| [LongOptionIgnoreCase](ArgsReader/LongOptionIgnoreCase.md) { get; set; } | True if long options (e.g. `--help`) should ignore case. (Default false.) |
| [LongOptionIgnoreKebabCase](ArgsReader/LongOptionIgnoreKebabCase.md) { getset; } | True if long options (e.g. `--dry-run`) should ignore "kebab case", i.e. allow `--dryrun`. (Default false.) |
| [NoOptionsAfterDoubleDash](ArgsReader/NoOptionsAfterDoubleDash.md) { getset; } | True if `--` is ignored and all following arguments are not read as options. (Default false.) |
| [ShortOptionIgnoreCase](ArgsReader/ShortOptionIgnoreCase.md) { getset; } | True if short options (e.g. `-h`) should ignore case. (Default false.) |
| [ReadArgument](ArgsReader/ReadArgument.md)() | Reads the next non-option argument. |
| [ReadArguments](ArgsReader/ReadArguments.md)() | Reads any remaining non-option arguments. |
| [ReadFlag](ArgsReader/ReadFlag.md)(…) | Reads the specified flag, returning true if it is found. |
| [ReadOption](ArgsReader/ReadOption.md)(…) | Reads the value of the specified option, if any. |
| [VerifyComplete](ArgsReader/VerifyComplete.md)() | Confirms that all arguments were processed. |

## Remarks

To use this class, construct an `ArgsReader` with the command-line arguments from `Main`, read the supported options one at a time with [`ReadFlag`](./ArgsReader/ReadFlag.md) and [`ReadOption`](./ArgsReader/ReadOption.md), read any normal arguments with [`ReadArgument`](./ArgsReader/ReadArgument.md), and finally call [`VerifyComplete`](./ArgsReader/VerifyComplete.md), which throws an [`ArgsReaderException`](./ArgsReaderException.md) if any unsupported options or arguments haven't been read.

## See Also

* namespace [ArgsReading](../ArgsReading.md)
* [ArgsReader.cs](https://github.com/ejball/ArgsReading/tree/master/src/ArgsReading/ArgsReader.cs)
<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
24 changes: 24 additions & 0 deletions ArgsReading/ArgsReader/ArgsReader.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ArgsReader constructor

Creates a reader for the specified command-line arguments.

```csharp
public ArgsReader(IEnumerable<string> args)
```

| parameter | description |
| --- | --- |
| args | The command-line arguments from `Main`. |

## Exceptions

| exception | condition |
| --- | --- |
| ArgumentNullException | `args` is `null`. |

## See Also

* class [ArgsReader](../ArgsReader.md)
* namespace [ArgsReading](../../ArgsReading.md)

<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
14 changes: 14 additions & 0 deletions ArgsReading/ArgsReader/LongOptionIgnoreCase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ArgsReader.LongOptionIgnoreCase property

True if long options (e.g. `--help`) should ignore case. (Default false.)

```csharp
public bool LongOptionIgnoreCase { get; set; }
```

## See Also

* class [ArgsReader](../ArgsReader.md)
* namespace [ArgsReading](../../ArgsReading.md)

<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
14 changes: 14 additions & 0 deletions ArgsReading/ArgsReader/LongOptionIgnoreKebabCase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ArgsReader.LongOptionIgnoreKebabCase property

True if long options (e.g. `--dry-run`) should ignore "kebab case", i.e. allow `--dryrun`. (Default false.)

```csharp
public bool LongOptionIgnoreKebabCase { get; set; }
```

## See Also

* class [ArgsReader](../ArgsReader.md)
* namespace [ArgsReading](../../ArgsReading.md)

<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
14 changes: 14 additions & 0 deletions ArgsReading/ArgsReader/NoOptionsAfterDoubleDash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ArgsReader.NoOptionsAfterDoubleDash property

True if `--` is ignored and all following arguments are not read as options. (Default false.)

```csharp
public bool NoOptionsAfterDoubleDash { get; set; }
```

## See Also

* class [ArgsReader](../ArgsReader.md)
* namespace [ArgsReading](../../ArgsReading.md)

<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
28 changes: 28 additions & 0 deletions ArgsReading/ArgsReader/ReadArgument.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ArgsReader.ReadArgument method

Reads the next non-option argument.

```csharp
public string? ReadArgument()
```

## Return Value

The next non-option argument, or null if none remain.

## Exceptions

| exception | condition |
| --- | --- |
| [ArgsReaderException](../ArgsReaderException.md) | The next argument is an option. |

## Remarks

If the next argument is an option, this method throws an exception. If options can appear before normal arguments, be sure to read all options before reading any normal arguments.

## See Also

* class [ArgsReader](../ArgsReader.md)
* namespace [ArgsReading](../../ArgsReading.md)

<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
28 changes: 28 additions & 0 deletions ArgsReading/ArgsReader/ReadArguments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ArgsReader.ReadArguments method

Reads any remaining non-option arguments.

```csharp
public IReadOnlyList<string> ReadArguments()
```

## Return Value

The remaining non-option arguments, if any.

## Exceptions

| exception | condition |
| --- | --- |
| [ArgsReaderException](../ArgsReaderException.md) | A remaining argument is an option. |

## Remarks

If any remaining arguments are options, this method throws an exception. If options can appear before normal arguments, be sure to read all options before reading any normal arguments.

## See Also

* class [ArgsReader](../ArgsReader.md)
* namespace [ArgsReading](../../ArgsReading.md)

<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
37 changes: 37 additions & 0 deletions ArgsReading/ArgsReader/ReadFlag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# ArgsReader.ReadFlag method

Reads the specified flag, returning true if it is found.

```csharp
public bool ReadFlag(string name)
```

| parameter | description |
| --- | --- |
| name | The name of the specified flag. |

## Return Value

True if the specified flag was found on the command line.

## Exceptions

| exception | condition |
| --- | --- |
| ArgumentNullException | `name` is `null`. |
| ArgumentException | One of the names is empty. |

## Remarks

If the flag is found, the method returns `true` and the flag is removed. If `ReadFlag` is called again with the same name, it will return `false`, unless the same flag appears twice on the command line.

To support multiple names for the same flag, use a `|` to separate them, e.g. use `help|h|?` to support three different names for a help flag.

Single-character names use a single hyphen, e.g. `-h`. Longer names use a double hyphen, e.g. `--help`.

## See Also

* class [ArgsReader](../ArgsReader.md)
* namespace [ArgsReading](../../ArgsReading.md)

<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
38 changes: 38 additions & 0 deletions ArgsReading/ArgsReader/ReadOption.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# ArgsReader.ReadOption method

Reads the value of the specified option, if any.

```csharp
public string? ReadOption(string name)
```

| parameter | description |
| --- | --- |
| name | The name of the specified option. |

## Return Value

The specified option if it was found on the command line; `null` otherwise.

## Exceptions

| exception | condition |
| --- | --- |
| ArgumentNullException | `name` is `null`. |
| ArgumentException | One of the names is empty. |
| [ArgsReaderException](../ArgsReaderException.md) | The argument that must follow the option is missing. |

## Remarks

If the option is found, the method returns the command-line argument after the option and both arguments are removed. If `ReadOption` is called again with the same name, it will return `null`, unless the same option appears twice on the command line.

To support multiple names for the same option, use a vertical bar (`|`) to separate them, e.g. use `n|name` to support two different names for a module option.

Single-character names use a single hyphen, e.g. `-n example`. Longer names use a double hyphen, e.g. `--name example`.

## See Also

* class [ArgsReader](../ArgsReader.md)
* namespace [ArgsReading](../../ArgsReading.md)

<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
14 changes: 14 additions & 0 deletions ArgsReading/ArgsReader/ShortOptionIgnoreCase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ArgsReader.ShortOptionIgnoreCase property

True if short options (e.g. `-h`) should ignore case. (Default false.)

```csharp
public bool ShortOptionIgnoreCase { get; set; }
```

## See Also

* class [ArgsReader](../ArgsReader.md)
* namespace [ArgsReading](../../ArgsReading.md)

<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
20 changes: 20 additions & 0 deletions ArgsReading/ArgsReader/VerifyComplete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ArgsReader.VerifyComplete method

Confirms that all arguments were processed.

```csharp
public void VerifyComplete()
```

## Exceptions

| exception | condition |
| --- | --- |
| [ArgsReaderException](../ArgsReaderException.md) | A command-line argument was not read. |

## See Also

* class [ArgsReader](../ArgsReader.md)
* namespace [ArgsReading](../../ArgsReading.md)

<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
20 changes: 20 additions & 0 deletions ArgsReading/ArgsReaderException.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ArgsReaderException class

Thrown when an error occurs while processing command-line arguments.

```csharp
public sealed class ArgsReaderException : Exception
```

## Public Members

| name | description |
| --- | --- |
| [ArgsReaderException](ArgsReaderException/ArgsReaderException.md)(…) | Creates an exception. |

## See Also

* namespace [ArgsReading](../ArgsReading.md)
* [ArgsReaderException.cs](https://github.com/ejball/ArgsReading/tree/master/src/ArgsReading/ArgsReaderException.cs)

<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
19 changes: 19 additions & 0 deletions ArgsReading/ArgsReaderException/ArgsReaderException.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ArgsReaderException constructor

Creates an exception.

```csharp
public ArgsReaderException(string message, Exception? innerException = null)
```

| parameter | description |
| --- | --- |
| message | The exception message. |
| innerException | The inner exception. |

## See Also

* class [ArgsReaderException](../ArgsReaderException.md)
* namespace [ArgsReading](../../ArgsReading.md)

<!-- DO NOT EDIT: generated by xmldocmd for ArgsReading.dll -->
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
### https://ejball.com/RepoName/
### https://ejball.com/ArgsReading/
10 changes: 5 additions & 5 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{{ "/" | relative_url }}">ProjectName</a>
<a class="navbar-brand" href="{{ "/" | relative_url }}">ArgsReading</a>
</div>
<div class="navbar-collapse collapse" id="navbar-main">
<ul class="nav navbar-nav">
<li><a href="{{ "/ProjectName" | relative_url }}">Reference</a></li>
<li><a href="{{ "/ArgsReading" | relative_url }}">Reference</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="/"><img src="{{ "/assets/home.png" | relative_url }}" class="navbar-logo"></a></li>
Expand All @@ -32,9 +32,9 @@
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><img src="{{ "/assets/github.png" | relative_url }}" class="navbar-logo"> <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="https://github.com/ejball/RepoName">View Source Code</a></li>
<li><a href="https://github.com/ejball/RepoName/blob/master/LICENSE">View License</a></li>
<li><a href="https://github.com/ejball/RepoName/blob/master/docs/{{ page.path }}">Edit This Page</a></li>
<li><a href="https://github.com/ejball/ArgsReading">View Source Code</a></li>
<li><a href="https://github.com/ejball/ArgsReading/blob/master/LICENSE">View License</a></li>
<li><a href="https://github.com/ejball/ArgsReading/blob/master/docs/{{ page.path }}">Edit This Page</a></li>
</ul>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3'
services:
jekyll:
image: jekyll/jekyll:pages
container_name: reponame
container_name: argsreading
command: jekyll serve --force_polling --livereload
ports:
- 4000:4000
Expand Down
14 changes: 11 additions & 3 deletions index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# ProjectName
# ArgsReading

[![NuGet](https://img.shields.io/nuget/v/ProjectName.svg)](https://www.nuget.org/packages/ProjectName)
**ArgsReading** is a .NET library for reading command-line arguments.

[![NuGet](https://img.shields.io/nuget/v/ArgsReading.svg)](https://www.nuget.org/packages/ArgsReading)

## Usage

See the [reference documentation](ProjectName.md).
**ArgsReading** is considerably simpler (and less powerful) than most command-line argument libraries.

It does not support registering a list of options, data type conversion, binding options to the properties of a class, documenting options, or displaying usage. If you want those features, use a competing library such as [CommandLineParser](https://www.nuget.org/packages/CommandLineParser) or [McMaster.Extensions.CommandLineUtils](https://www.nuget.org/packages/McMaster.Extensions.CommandLineUtils/).

To use this library, construct an [ArgsReader](ArgsReading/ArgsReader/ArgsReader.md) with the command-line arguments, read the supported options one at a time with [ReadFlag](ArgsReading/ArgsReader/ReadFlag.md) and [ReadOption](ArgsReading/ArgsReader/ReadOption.md), read any normal arguments with [ReadArgument](ArgsReading/ArgsReader/ReadArgument.md), and finally call [VerifyComplete](ArgsReading/ArgsReader/VerifyComplete.md), which throws an [ArgsReaderException](ArgsReading/ArgsReaderException.md) if any unsupported options or arguments haven't been read.

For more information, consult the [reference documentation](ArgsReading.md).

0 comments on commit 451f9ea

Please sign in to comment.