# OptionParser

<a id="optionparser"></a>

# OptionParser

```cpp
#include <icy/application.h>

struct OptionParser
```

[Defined in src/base/include/icy/application.h:103](https://github.com/auscaster/icey/blob/main/src/base/include/icy/application.h#L103)

Command-line option parser.

## Public Attributes

| Return | Name | Description |
|--------|------|-------------|
| `std::string` | [`exepath`](#exepath)  |  |
| [`OptionMap`](https://auscaster.com/icey/docs/api-reference/base.md#optionmap) | [`args`](#args)  |  |

---

<a id="exepath"></a>

### exepath

```cpp
std::string exepath
```

[Defined in src/base/include/icy/application.h:105](https://github.com/auscaster/icey/blob/main/src/base/include/icy/application.h#L105)

---

<a id="args"></a>

### args

```cpp
OptionMap args
```

Type: [`OptionMap`](https://auscaster.com/icey/docs/api-reference/base.md#optionmap)

[Defined in src/base/include/icy/application.h:106](https://github.com/auscaster/icey/blob/main/src/base/include/icy/application.h#L106)

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`OptionParser`](#optionparser-1)  | Parses command-line arguments from `argc`/`argv`. |
| `bool` | [`has`](#has-3) `inline` | Returns true if the given option key was present on the command line. |
| `std::string` | [`get`](#get-9) `inline` | Returns the string value associated with the given option key. Returns an empty string if the key was not found. |
| `NumericType` | [`get`](#get-10) `inline` | Returns the value associated with the given option key, converted to a numeric type. |

---

<a id="optionparser-1"></a>

### OptionParser

```cpp
OptionParser(int argc, char * argv, const char * delim)
```

[Defined in src/base/include/icy/application.h:112](https://github.com/auscaster/icey/blob/main/src/base/include/icy/application.h#L112)

Parses command-line arguments from `argc`/`argv`.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `argc` | `int` | Argument count from `main()`. |
| `argv` | `char *` | Argument vector from `main()`. |
| `delim` | `const char *` | Prefix string that identifies an option key (e.g. "--"). |

---

<a id="has-3"></a>

### has

`inline`

```cpp
inline bool has(const char * key)
```

[Defined in src/base/include/icy/application.h:117](https://github.com/auscaster/icey/blob/main/src/base/include/icy/application.h#L117)

Returns true if the given option key was present on the command line. 
#### Returns
True if the key exists in the parsed argument map.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const char *` | Option key to look up (without delimiter prefix). |

---

<a id="get-9"></a>

### get

`inline`

```cpp
inline std::string get(const char * key)
```

[Defined in src/base/include/icy/application.h:123](https://github.com/auscaster/icey/blob/main/src/base/include/icy/application.h#L123)

Returns the string value associated with the given option key. Returns an empty string if the key was not found. 
#### Returns
Value string, or empty string if not present.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const char *` | Option key to look up. |

---

<a id="get-10"></a>

### get

`inline`

```cpp
template<typename NumericType> inline NumericType get(const char * key)
```

[Defined in src/base/include/icy/application.h:136](https://github.com/auscaster/icey/blob/main/src/base/include/icy/application.h#L136)

Returns the value associated with the given option key, converted to a numeric type. 
#### Returns
Converted numeric value.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `key` | `const char *` | Option key to look up. |
