Skip to content

Commit 4645835

Browse files
committed
update README.md
1 parent a854e8d commit 4645835

1 file changed

Lines changed: 53 additions & 53 deletions

File tree

README.md

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ Yes, there are a lot of arg parsers. But hear us out.
1919

2020
## Usage
2121

22-
### Importing
22+
## Importing
2323

2424
```typescript
2525
import massarg from "massarg" // import init function (returns massarg instance)
2626
import { Massarg } from "massarg" // import class
2727
```
2828
29-
### Initializing
29+
## Initializing
3030
3131
Call the default export function `massarg`, or create a new instance manually using `new Massarg()`,
3232
and then you can start chaining commands. Use `.parse()` to do the final parsing and run the
@@ -41,13 +41,13 @@ massarg()
4141
.parse()
4242
```
4343

44-
### Main command
44+
## Main command
4545

4646
The main command is the one that runs when you supply no other commands.
4747

48-
#### Example
48+
### Example
4949

50-
##### JS/TS
50+
#### JS/TS
5151

5252
```typescript
5353
massarg().main((options) => {
@@ -56,7 +56,7 @@ massarg().main((options) => {
5656
})
5757
```
5858

59-
##### Shell
59+
#### Shell
6060

6161
```shell
6262
$ ./mybin
@@ -66,14 +66,23 @@ $ ./mybin --my-string "Some string"
6666
# Main command runs with option { myString: "Some string" }
6767
```
6868

69-
### Commands
69+
## Commands
7070

7171
Commands are activated when their keyword is included in the args. The first command that matches
7272
will be executed, skipping the rest. Options will still be parsed.
7373

74-
#### Example
74+
#### Options
7575

76-
##### JS/TS
76+
| Name | Type | Required | Example | Description |
77+
| ----------- | --------------------------- | -------- | ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
78+
| name | `string` || `"my-command"` | The name of the command, which will be used in the CLI to trigger it |
79+
| aliases | `string[]` || `["m", "mc"]` | Alternate names for the command, available for use in addition to `name` |
80+
| description | `string` || `"Description of the command"` | Description for the command, only displayed with `--help` or `printHelp()` |
81+
| run | `function(options) => void` || `(options) => console.log("my-command", options)` | Main function that runs this command. The supplied argument is the options passed via the CLI and parsed by massarg. |
82+
83+
### Example
84+
85+
#### JS/TS
7786

7887
```typescript
7988
massarg().command({
@@ -87,16 +96,7 @@ massarg().command({
8796
})
8897
```
8998

90-
###### Options
91-
92-
| Name | Type | Required | Example | Description |
93-
| ----------- | --------------------------- | -------- | ------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
94-
| name | `string` || `"my-command"` | The name of the command, which will be used in the CLI to trigger it |
95-
| aliases | `string[]` || `["m", "mc"]` | Alternate names for the command, available for use in addition to `name` |
96-
| description | `string` || `"Description of the command"` | Description for the command, only displayed with `--help` or `printHelp()` |
97-
| run | `function(options) => void` || `(options) => console.log("my-command", options)` | Main function that runs this command. The supplied argument is the options passed via the CLI and parsed by massarg. |
98-
99-
##### Shell
99+
#### Shell
100100

101101
```shell
102102
$ ./mybin my-command
@@ -106,14 +106,23 @@ $ ./mybin my-command --my-string "Some string"
106106
# Specified "my-command" runs with option { myString: "Some string" }
107107
```
108108

109-
### Options
109+
## Options
110110

111111
Options are variables you can accept via CLI and parse to use in your commands, e.g. `--my-bool`,
112112
`--my-string string`, `--my-number 1`
113113

114-
#### Example
114+
#### Options
115115

116-
##### JS/TS
116+
| Name | Type | Required | Default | Example | Description |
117+
| ----------- | --------------------------------- | -------- | -------- | ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
118+
| name | `string` || | `"my-number"` | The name of the option, which will be used in the CLI to apply it |
119+
| aliases | `string[]` || | `["n"]` | Alternate names for the option, available for use in addition to `name` |
120+
| description | `string` || | `"Description of the command"` | Description for the command, only displayed with `--help` or `printHelp()` |
121+
| parse | `function(value, options) => any` || `String` | `(value, options) => parseInt(value)` | Function that parses this option. The supplied arguments are the string value from the arg, and other options passed via the CLI and parsed by massarg before this one. Not all options will be available. |
122+
123+
### Example
124+
125+
#### JS/TS
117126

118127
```typescript
119128
massarg()
@@ -135,16 +144,7 @@ massarg()
135144
})
136145
```
137146

138-
###### Options
139-
140-
| Name | Type | Required | Default | Example | Description |
141-
| ----------- | --------------------------------- | -------- | -------- | ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
142-
| name | `string` || | `"my-number"` | The name of the option, which will be used in the CLI to apply it |
143-
| aliases | `string[]` || | `["n"]` | Alternate names for the option, available for use in addition to `name` |
144-
| description | `string` || | `"Description of the command"` | Description for the command, only displayed with `--help` or `printHelp()` |
145-
| parse | `function(value, options) => any` || `String` | `(value, options) => parseInt(value)` | Function that parses this option. The supplied arguments are the string value from the arg, and other options passed via the CLI and parsed by massarg before this one. Not all options will be available. |
146-
147-
##### Shell
147+
#### Shell
148148

149149
```shell
150150
$ ./mybin my-command
@@ -154,14 +154,31 @@ $ ./mybin my-command --my-string "Some string" --my-number 1 --my-bool
154154
# Specified "my-command" runs with option { myString: "Some string", myNumber: 1, myBool: true }
155155
```
156156

157-
### Help/Usage Command
157+
## Help/Usage Command
158158

159159
You can modify some of the styles and behavior of the help text. None of the options are required,
160160
you may override their defaults to modify the behavior.
161161

162-
#### Example
162+
#### Options
163163

164-
##### JS/TS
164+
| Name | Type | Default | Description |
165+
| ---------------------- | -------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------- |
166+
| `binName` | `string` | running script name | The name of the binary, to be used when outputting usage information. |
167+
| `printWidth` | `number` | `80` | The amount of characters to allow per line. Use `0` to disable wrapping. |
168+
| `normalColors` | `string \| string[]` | `"dim"` | Colors to use on normal text (descriptions, usage example, etc.) |
169+
| `highlightColors` | `string \| string[]` | `"yellow"` | Colors to use on highlighted text (command names, option names, binary name, etc) |
170+
| `titleColors` | `string \| string[]` | `"white"` | Colors to use on title text ("Options", "Usage", etc) |
171+
| `subtitleColors` | `string \| string[]` | `["bold", "dim"]` | Colors to use on subtitle text (e.g. command titles for non-gloal options) |
172+
| `header` | `string` | `"Header text"` | Additional content to display below the usage line, and above the rest. |
173+
| `footer` | `string` | `"Footer text"` | Additional content to display below the commands and options, at the very bottom. |
174+
| `commandNameSeparator` | `string` | `" \| "` | Separator for command name & its aliases. |
175+
| `optionNameSeparator` | `string` | `"\|"` | Separator for option name & its aliases. |
176+
| `useGlobalColumns` | `boolean` | `false` | Decides whether to align the columns of the option/command names and their descriptions globally or per table |
177+
| `usageExample` | `string` | `"[command] [option]"` | Default text to use as suffix for the `binName`, which will be used in the "Usage" line of the help text |
178+
179+
### Example
180+
181+
#### JS/TS
165182

166183
```typescript
167184
massarg().help({
@@ -180,24 +197,7 @@ massarg().help({
180197
})
181198
```
182199

183-
###### Options
184-
185-
| Name | Type | Default | Description |
186-
| ---------------------- | -------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------- |
187-
| `binName` | `string` | running script name | The name of the binary, to be used when outputting usage information. |
188-
| `printWidth` | `number` | `80` | The amount of characters to allow per line. Use `0` to disable wrapping. |
189-
| `normalColors` | `string \| string[]` | `"dim"` | Colors to use on normal text (descriptions, usage example, etc.) |
190-
| `highlightColors` | `string \| string[]` | `"yellow"` | Colors to use on highlighted text (command names, option names, binary name, etc) |
191-
| `titleColors` | `string \| string[]` | `"white"` | Colors to use on title text ("Options", "Usage", etc) |
192-
| `subtitleColors` | `string \| string[]` | `["bold", "dim"]` | Colors to use on subtitle text (e.g. command titles for non-gloal options) |
193-
| `header` | `string` | `"Header text"` | Additional content to display below the usage line, and above the rest. |
194-
| `footer` | `string` | `"Footer text"` | Additional content to display below the commands and options, at the very bottom. |
195-
| `commandNameSeparator` | `string` | `" \| "` | Separator for command name & its aliases. |
196-
| `optionNameSeparator` | `string` | `"\|"` | Separator for option name & its aliases. |
197-
| `useGlobalColumns` | `boolean` | `false` | Decides whether to align the columns of the option/command names and their descriptions globally or per table |
198-
| `usageExample` | `string` | `"[command] [option]"` | Default text to use as suffix for the `binName`, which will be used in the "Usage" line of the help text |
199-
200-
##### Shell
200+
#### Shell
201201

202202
```shell
203203
$ ./mybin --help

0 commit comments

Comments
 (0)