Debian Codegraph @

docs/basic_documentation.rst

raw
1 Crazy-Complete Documentation
2 ============================
3
4 .. contents::
5 :local:
6 :depth: 2
7
8 This documentation provides an overview of how to define shell completions for commands using **crazy-complete**.
9
10 Command Definition
11 ------------------
12
13 To define a completion for a command, use the following structure:
14
15 .. code-block:: yaml
16
17 prog: "<PROGRAM NAME>"
18 help: "<PROGRAM DESCRIPTION>"
19 options:
20 <OPTION ...>
21 positionals:
22 <POSITIONAL ...>
23
24 :prog:
25 The name of the program for which you want to create completion.
26 :help:
27 *(optional)* A short description of the program.
28 :options:
29 *(optional)* A list of options the program accepts.
30 :positionals:
31 *(optional)* A list of positional arguments the program uses.
32
33 Example:
34
35 .. code-block:: yaml
36
37 prog: "git"
38 help: "Distributed version control system"
39
40 Option Definition
41 -----------------
42
43 Options are defined as follows:
44
45 .. code-block:: yaml
46
47 options:
48 - option_strings: ["<OPTION STRING>", ...]
49 metavar: "<METAVAR>"
50 help: "<OPTION DESCRIPTION>"
51 optional_arg: <BOOL>
52 complete: <COMPLETE ACTION>
53 repeatable: <BOOL>
54 final: <BOOL>
55 hidden: <BOOL>
56 groups: ["<GROUP>", ...]
57 when: "<CONDITION>"
58
59 :option_strings:
60 A list of option strings (e.g., ``["-h", "--help"]``).
61 :metavar:
62 *(optional)* The placeholder used for the argument (e.g., ``FILE``).
63 :help:
64 *(optional)* A description of the option.
65 :optional_arg:
66 *(optional)* Indicates if the option's argument is optional (default: ``false``).
67 :complete:
68 *(optional)* Defines the completion method.
69 If not set, the option does not take an argument.
70 Use ``["none"]`` if the option accepts an argument but no specific completion method applies.
71 :repeatable:
72 *(optional)* Whether an option can be used multiple times (default: ``false``).
73 :final:
74 *(optional)* If true, no further options are suggested after this one.
75 Commonly used for ``--help`` or ``--version`` (default: ``false``).
76 :hidden:
77 *(optional)* Excludes this option from completion suggestions, but it remains valid when typed manually.
78 :groups:
79 *(optional)* Assigns this option to one or more groups.
80 Multiple options from the same group cannot be suggested at once, useful for mutually exclusive flags.
81 :when:
82 *(optional)* Enables this option only if the condition evaluates to true.
83
84 Example:
85
86 .. code-block:: yaml
87
88 options:
89 - option_strings: ["--directory", "-C"]
90 metavar: "PATH"
91 help: "Run as if git was started in PATH"
92 complete: ["directory"]
93
94 Positional Arguments
95 --------------------
96
97 Positional arguments are defined as follows:
98
99 .. code-block:: yaml
100
101 positionals:
102 - number: <NUMBER>
103 metavar: "<METAVAR>"
104 help: "<POSITIONAL DESCRIPTION>"
105 repeatable: <BOOL>
106 complete: <COMPLETE ACTION>
107 when: "<CONDITION>"
108
109 :number:
110 The order of the positional argument (e.g., ``1`` for the first argument).
111 :metavar:
112 *(optional)* Placeholder for the positional argument in the help text.
113 :help:
114 *(optional)* A description of the positional argument.
115 :repeatable:
116 *(optional)* Whether this argument can be repeated (default: ``false``).
117 :complete:
118 *(optional)* Completion method to generate possible values (default: ``["none"]``).
119 :when:
120 *(optional)* Enables this positional only if the condition evaluates to true.
121
122 Example:
123
124 .. code-block:: yaml
125
126 positionals:
127 - number: 1
128 metavar: "FILE"
129 help: "File to process"
130 complete: ["file"]
131
132 Subcommands
133 -----------
134
135 Subcommands are defined by appending them to the program name:
136
137 .. code-block:: yaml
138
139 prog: "<PROGRAM NAME> <SUBCOMMAND> ..."
140 aliases: ["<ALIAS>", ...]
141 help: "<SUBCOMMAND DESCRIPTION>"
142
143 :prog:
144 The name of the program, followed by the subcommand(s).
145 :aliases:
146 *(optional)* A list of alternative names for the subcommand.
147 Aliases must not include the program name.
148 :help:
149 *(optional)* A description of the subcommand.
150
151 Example:
152
153 .. code-block:: yaml
154
155 prog: "kubectl get"
156 help: "Display one or many resources"
157 options:
158 - option_strings: ["--output"]
159 complete: ["choices", ["json", "yaml", "wide"]]
160
161 Best Practices
162 --------------
163
164 * Use ``["none"]`` only when a value is required but no completion applies.
165 * Use ``repeatable: true`` for options like ``--tag`` or ``--define``.
166 * Set ``final: true`` for options like ``--help`` or ``--version`` so no further suggestions appear afterward.
167 * Use groups for mutually exclusive flags to improve user experience.
168