Skip to content

Commit

Permalink
docs(command): add documentation and example's for hidden command's a…
Browse files Browse the repository at this point in the history
…nd option's
  • Loading branch information
c4spar committed May 21, 2020
1 parent 5cd8287 commit 0c2f400
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
8 changes: 8 additions & 0 deletions examples/command/hidden-commands.ts
@@ -0,0 +1,8 @@
#!/usr/bin/env -S deno run

import { Command } from '../../packages/command/lib/command.ts';

await new Command()
.command( 'top-secret', 'Nobody knows about me!' )
.hidden()
.parse( Deno.args );
7 changes: 7 additions & 0 deletions examples/command/hidden-options.ts
@@ -0,0 +1,7 @@
#!/usr/bin/env -S deno run

import { Command } from '../../packages/command/lib/command.ts';

await new Command()
.option( '-H, --hidden [hidden:boolean]', 'Nobody knows about me!', { hidden: true } )
.parse( Deno.args );
37 changes: 36 additions & 1 deletion packages/command/README.md
Expand Up @@ -59,11 +59,13 @@
- [Options which conflicts with other options](#options-which-conflicts-with-other-options)
- [Custom option processing](#custom-option-processing)
- [Standalone options](#standalone-options)
- [Hidden options](#hidden-options)
- [Specify an action for an option](#specify-an-action-for-an-option)
- [Commands](#commands)
- [Action handler](#action-handler)
- [Sub-commands](#sub-commands)
- [Specify the argument syntax](#specify-the-argument-syntax)
- [Hidden commands](#hidden-commands)
- [Git-style executable sub-commands](#git-style-executable-sub-commands)
- [Override exit handling](#override-exit-handling)
- [Specify environment variables](#specify-the-argument-syntax)
Expand Down Expand Up @@ -578,6 +580,22 @@ $ ./examples/command/standalone-option.ts --standalone --other
Error: Option --standalone cannot be combined with other options.
```

### Hidden options

To exclude option's from the help and completion command's you can use the `hidden` option.

```typescript
#!/usr/bin/env -S deno run

import { Command } from 'https://deno.land/x/cliffy/command.ts';

await new Command()
.option( '-H, --hidden [hidden:boolean]', 'Nobody knows about me!', { hidden: true } )
.parse( Deno.args );
```

**Example:** `deno run https://deno.land/x/cliffy/examples/command/hidden-options.ts -h`

### Specify an action for an option

```typescript
Expand Down Expand Up @@ -712,6 +730,23 @@ await new Command()
.parse( Deno.args );
```

### Hidden commands

To exclude commands's from the help and completion command's you can use the `.hidden()` method.

```typescript
#!/usr/bin/env -S deno run

import { Command } from 'https://deno.land/x/cliffy/command.ts';

await new Command()
.command( 'top-secret', 'Nobody knows about me!' )
.hidden()
.parse( Deno.args );
```

**Example:** `deno run https://deno.land/x/cliffy/examples/command/hidden-commands.ts -h`

### Git-style executable sub-commands

When `.command()` is invoked with a description argument, this tells cliffy that you're going to use separate executables for sub-commands, much like `git(1)` and other popular tools. Cliffy will search the executables in the directory of the entry script (like `./examples/pm`) with the name program-sub-command, like `pm-install`, `pm-search`. You can specify a custom name with the `executable` configuration option.
Expand Down Expand Up @@ -867,7 +902,7 @@ const input: string = result.args[ 0 ];
const output: string | undefined = result.args[ 1 ];
```

**Example**: `deno run https://deno.land/x/cliffy/examples/command/generic.ts`
**Example:** `deno run https://deno.land/x/cliffy/examples/command/generic.ts`

## Default options & commands

Expand Down

0 comments on commit 0c2f400

Please sign in to comment.