Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Jan 12, 2024
1 parent a1da0fd commit dc7be5b
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# CLI
20 changes: 20 additions & 0 deletions docs/spec/reference/arg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# `arg`

```sh
arg "<file>" # positional arg, completed as a filename
arg "<dir>" # positional arg, completed as a directory
arg "[file]" # optional positional arg
arg "<file>" default="file.txt" # default value for arg
arg "<file>" parse="mycli parse-file {}" # parse arg value with external command

arg "[file]" var=true # multiple args can be passed (e.g. mycli file1 file2 file3) (0 or more)
arg "<file>" var=true # multiple args can be passed (e.g. mycli file1 file2 file3) (1 or more)
arg "<file>" var=true var_min=3 # at least 3 args must be passed
arg "<file>" var=true var_max=3 # up to 3 args can be passed

arg "<shell>" {
choices "bash" "zsh" "fish" # <shell> must be one of the choices
}

arg "<file>" long_help="longer help for --help (as oppoosed to -h)"
```
38 changes: 38 additions & 0 deletions docs/spec/reference/cmd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# `cmd`

```sh
# aliases
cmd "config" help="Manage the CLI config" {
alias "cfg" "cf" "cg" # aliases for the command
alias "conf" hide=true # hide alias from docs and completions
}

cmd "config" hide=true # hide command from docs and completions
cmd "config" subcommand_required=true # subcommand is not optional

# these are shown under -h
cmd "config" before_help="shown before the command"
cmd "config" help="short description"
cmd "config" after_help="shown after the command"

# these are shown under --help
cmd "config" before_long_help="shown before the command"
cmd "config" long_help="longer description"
cmd "config" after_long_help="shown after the command"

cmd "list" {
example "Basic usage" r#"
$ mycli list
FRUIT COLOR
apple red
banana yellow
"#
example "JSON output" r#"
$ mycli list --json
[
{"FRUIT": "apple", "COLOR": "red"},
{"FRUIT": "banana", "COLOR": "yellow"}
]
"#
}
```
6 changes: 6 additions & 0 deletions docs/spec/reference/complete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# `complete`

```sh
# use a custom completion command for args named "PLUGIN"
complete "<plugin>" run="mycli plugins list"
```
34 changes: 34 additions & 0 deletions docs/spec/reference/flag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# `flag`

```sh
flag "-u,--user <user>" # one way to define a flag
flag "--user" { # another way to define the same flag
alias "-u"
arg "<user>"
}
flag "--user" { alias "-u" hide=true } # hide alias from docs and completions

flag "-f,--force" global=true # global can be set on any subcommand
flag "--file <file>" default="file.txt" # default value for flag
flag "-v,--verbose" count=true # instead of true/false $usage_verbose is # of times
# flag was used (e.g. -vvv = 3)

flag "--color" negate="--no-color" default=true # $usage_color=true by default
# --no-color will set $usage_color=false

flag "--color" env="MYCLI_COLOR" # flag can be backed by an env var
flag "--color" config="ui.color" # flag can be backed by a config file

flag "--file <file>" # args named "<file>" will be completed as files
flag "--dir <dir>" # args named "<dir>" will be completed as directories

flag "--file <file>" required_if="--dir" # if --dir is set, --file must also be set
flag "--file <file>" required_unless="--dir" # either --file or --dir must be present
flag "--file <file>" overrides="--stdin" # if --file is set, previous --stdin will be ignored

flag "--file <file>" long_help="longer help for --help (as oppoosed to -h)"

flag "--shell <shell>" {
choices "bash" "zsh" "fish" # <shell> must be one of the choices
}
```
24 changes: 24 additions & 0 deletions docs/spec/reference/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Top-level metadata

::: warning
This spec is still a work in progress and is subject to change until 1.0
:::

```sh
name "My CLI" # a friendly name for the CLI
bin "mycli" # the name of the binary
version "1.0.0" # the version of the CLI
author "nobody" # the author of the CLI
license "MIT" # SPDX license the CLI is released under

# help for -h
before_help "before about"
about "some help"
after_help "after about"

# help for --help
before_long_help "before about"
long_about "longer help"
after_long_help "after about"
example "mycli --help"
```

0 comments on commit dc7be5b

Please sign in to comment.