# CommandSpec
<span class="source-link">[[Source]](src/cli/command_spec.md#L9)</span>

CommandSpec describes the specification of a parent or leaf command. Each
command has the following attributes:

- a name: a simple string token that identifies the command.
- a description: used in the syntax message.
- a map of options: the valid options for this command.
- an optional help option+command name for help parsing
- one of:
   - a Map of child commands.
   - an Array of arguments.


```pony
class ref CommandSpec
```

## Constructors

### parent
<span class="source-link">[[Source]](src/cli/command_spec.md#L33)</span>


Creates a command spec that can accept options and child commands, but not
arguments.


```pony
new ref parent(
  name': String val,
  descr': String val = seq,
  options': Array[OptionSpec val] box = seq,
  commands': Array[CommandSpec ref] box = seq)
: CommandSpec ref^ ?
```
#### Parameters

*   name': [String](builtin-String) val
*   descr': [String](builtin-String) val = seq
*   options': [Array](builtin-Array)\[[OptionSpec](cli-OptionSpec) val\] box = seq
*   commands': [Array](builtin-Array)\[[CommandSpec](cli-CommandSpec) ref\] box = seq

#### Returns

* [CommandSpec](cli-CommandSpec) ref^ ?

---

### leaf
<span class="source-link">[[Source]](src/cli/command_spec.md#L53)</span>


Creates a command spec that can accept options and arguments, but not child
commands.


```pony
new ref leaf(
  name': String val,
  descr': String val = seq,
  options': Array[OptionSpec val] box = seq,
  args': Array[ArgSpec val] box = seq)
: CommandSpec ref^ ?
```
#### Parameters

*   name': [String](builtin-String) val
*   descr': [String](builtin-String) val = seq
*   options': [Array](builtin-Array)\[[OptionSpec](cli-OptionSpec) val\] box = seq
*   args': [Array](builtin-Array)\[[ArgSpec](cli-ArgSpec) val\] box = seq

#### Returns

* [CommandSpec](cli-CommandSpec) ref^ ?

---

## Public Functions

### add_command
<span class="source-link">[[Source]](src/cli/command_spec.md#L84)</span>


Adds an additional child command to this parent command.


```pony
fun ref add_command(
  cmd: CommandSpec box)
: None val ?
```
#### Parameters

*   cmd: [CommandSpec](cli-CommandSpec) box

#### Returns

* [None](builtin-None) val ?

---

### add_help
<span class="source-link">[[Source]](src/cli/command_spec.md#L91)</span>


Adds a standard help option and, optionally command, to a root command.


```pony
fun ref add_help(
  hname: String val = seq,
  descr': String val = seq)
: None val ?
```
#### Parameters

*   hname: [String](builtin-String) val = seq
*   descr': [String](builtin-String) val = seq

#### Returns

* [None](builtin-None) val ?

---

### name
<span class="source-link">[[Source]](src/cli/command_spec.md#L106)</span>


Returns the name of this command.


```pony
fun box name()
: String val
```

#### Returns

* [String](builtin-String) val

---

### descr
<span class="source-link">[[Source]](src/cli/command_spec.md#L112)</span>


Returns the description for this command.


```pony
fun box descr()
: String val
```

#### Returns

* [String](builtin-String) val

---

### options
<span class="source-link">[[Source]](src/cli/command_spec.md#L118)</span>


Returns a map by name of the named options of this command.


```pony
fun box options()
: HashMap[String val, OptionSpec val, HashEq[String val] val] box
```

#### Returns

* [HashMap](collections-HashMap)\[[String](builtin-String) val, [OptionSpec](cli-OptionSpec) val, [HashEq](collections-HashEq)\[[String](builtin-String) val\] val\] box

---

### commands
<span class="source-link">[[Source]](src/cli/command_spec.md#L124)</span>


Returns a map by name of the child commands of this command.


```pony
fun box commands()
: HashMap[String val, CommandSpec box, HashEq[String val] val] box
```

#### Returns

* [HashMap](collections-HashMap)\[[String](builtin-String) val, [CommandSpec](cli-CommandSpec) box, [HashEq](collections-HashEq)\[[String](builtin-String) val\] val\] box

---

### args
<span class="source-link">[[Source]](src/cli/command_spec.md#L130)</span>


Returns an array of the positional arguments of this command.


```pony
fun box args()
: Array[ArgSpec val] box
```

#### Returns

* [Array](builtin-Array)\[[ArgSpec](cli-ArgSpec) val\] box

---

### is_leaf
<span class="source-link">[[Source]](src/cli/command_spec.md#L136)</span>


```pony
fun box is_leaf()
: Bool val
```

#### Returns

* [Bool](builtin-Bool) val

---

### is_parent
<span class="source-link">[[Source]](src/cli/command_spec.md#L138)</span>


```pony
fun box is_parent()
: Bool val
```

#### Returns

* [Bool](builtin-Bool) val

---

### help_name
<span class="source-link">[[Source]](src/cli/command_spec.md#L140)</span>


Returns the name of the help command, which defaults to "help".


```pony
fun box help_name()
: String val
```

#### Returns

* [String](builtin-String) val

---

### help_string
<span class="source-link">[[Source]](src/cli/command_spec.md#L146)</span>


Returns a formated help string for this command and all of its arguments.


```pony
fun box help_string()
: String val
```

#### Returns

* [String](builtin-String) val

---

## Private Functions

### _assertName
<span class="source-link">[[Source]](src/cli/command_spec.md#L73)</span>


```pony
fun tag _assertName(
  nm: String val)
: String val ?
```
#### Parameters

*   nm: [String](builtin-String) val

#### Returns

* [String](builtin-String) val ?

---

