| 1 |
from enum import Enum |
| 2 |
from pathlib import Path |
| 3 |
from typing import Annotated, Literal |
| 4 |
|
| 5 |
from cyclopts import App, Parameter |
| 6 |
from cyclopts.types import ExistingFile |
| 7 |
|
| 8 |
app_basic = App(name="basic") |
| 9 |
|
| 10 |
|
| 11 |
@app_basic.default |
| 12 |
def main( |
| 13 |
verbose: Annotated[bool, Parameter(help="Enable verbose output")] = False, |
| 14 |
count: Annotated[int, Parameter(help="Number of items")] = 1, |
| 15 |
): |
| 16 |
"""Basic app for testing.""" |
| 17 |
pass |
| 18 |
|
| 19 |
|
| 20 |
@app_basic.command |
| 21 |
def deploy( |
| 22 |
env: Annotated[Literal["dev", "staging", "prod"], Parameter(help="Environment")], |
| 23 |
force: bool = False, |
| 24 |
): |
| 25 |
"""Deploy to environment.""" |
| 26 |
pass |
| 27 |
|
| 28 |
|
| 29 |
class Speed(Enum): |
| 30 |
FAST = "fast" |
| 31 |
SLOW = "slow" |
| 32 |
|
| 33 |
|
| 34 |
app_enum = App(name="enumapp") |
| 35 |
|
| 36 |
|
| 37 |
@app_enum.default |
| 38 |
def enum_main(speed: Speed = Speed.FAST): |
| 39 |
"""App with enum parameter.""" |
| 40 |
pass |
| 41 |
|
| 42 |
|
| 43 |
app_nested = App(name="nested") |
| 44 |
config_app = App(name="config") |
| 45 |
|
| 46 |
|
| 47 |
@config_app.command |
| 48 |
def get(key: str): |
| 49 |
"""Get config value.""" |
| 50 |
pass |
| 51 |
|
| 52 |
|
| 53 |
@config_app.command |
| 54 |
def set(key: str, value: str): |
| 55 |
"""Set config value.""" |
| 56 |
pass |
| 57 |
|
| 58 |
|
| 59 |
app_nested.command(config_app) |
| 60 |
|
| 61 |
|
| 62 |
app_path = App(name="pathapp") |
| 63 |
|
| 64 |
|
| 65 |
@app_path.default |
| 66 |
def path_main( |
| 67 |
input_file: Annotated[Path, Parameter(help="Input file")], |
| 68 |
output: Annotated[Path | None, Parameter(help="Output file")] = None, |
| 69 |
): |
| 70 |
"""App with path parameters.""" |
| 71 |
pass |
| 72 |
|
| 73 |
|
| 74 |
app_negative = App(name="negapp") |
| 75 |
|
| 76 |
|
| 77 |
@app_negative.default |
| 78 |
def negative_main( |
| 79 |
verbose: Annotated[bool, Parameter(help="Enable verbose")] = False, |
| 80 |
colors: Annotated[bool, Parameter(negative="no-colors")] = True, |
| 81 |
): |
| 82 |
"""App with negative flags.""" |
| 83 |
pass |
| 84 |
|
| 85 |
|
| 86 |
app_markup = App(name="markupapp") |
| 87 |
|
| 88 |
|
| 89 |
@app_markup.default |
| 90 |
def markup_main( |
| 91 |
verbose: Annotated[bool, Parameter(help="Enable **verbose** output with `extra` details")] = False, |
| 92 |
mode: Annotated[ |
| 93 |
Literal["fast", "slow"], |
| 94 |
Parameter(help="Choose *execution* mode: **fast** or **slow**"), |
| 95 |
] = "fast", |
| 96 |
): |
| 97 |
"""App with **markdown** markup in help text. |
| 98 |
|
| 99 |
This tests that markup is properly stripped in completions. |
| 100 |
""" |
| 101 |
pass |
| 102 |
|
| 103 |
|
| 104 |
@app_markup.command |
| 105 |
def deploy_markup( |
| 106 |
env: Annotated[str, Parameter(help="Target `environment` like **dev** or **prod**")], |
| 107 |
): |
| 108 |
"""Deploy to `environment`.""" |
| 109 |
pass |
| 110 |
|
| 111 |
|
| 112 |
app_rst = App(name="rstapp", help_format="rst") |
| 113 |
|
| 114 |
|
| 115 |
@app_rst.default |
| 116 |
def rst_main( |
| 117 |
verbose: Annotated[bool, Parameter(help="Enable **verbose** output with ``code`` samples")] = False, |
| 118 |
mode: Annotated[ |
| 119 |
Literal["fast", "slow"], |
| 120 |
Parameter(help="Choose *execution* mode: **fast** or **slow**"), |
| 121 |
] = "fast", |
| 122 |
): |
| 123 |
"""App with **RST** markup in help text. |
| 124 |
|
| 125 |
This tests that RST markup is properly stripped in completions. |
| 126 |
""" |
| 127 |
pass |
| 128 |
|
| 129 |
|
| 130 |
app_positional_literal = App(name="poslit") |
| 131 |
|
| 132 |
|
| 133 |
@app_positional_literal.command |
| 134 |
def command(param: Literal["foo", "bar", "baz"], /): |
| 135 |
"""Simple command with positional literal. |
| 136 |
|
| 137 |
Parameters |
| 138 |
---------- |
| 139 |
param : Literal["foo", "bar", "baz"] |
| 140 |
Literal param. |
| 141 |
""" |
| 142 |
pass |
| 143 |
|
| 144 |
|
| 145 |
app_multiple_positionals = App(name="multipos") |
| 146 |
|
| 147 |
|
| 148 |
@app_multiple_positionals.command |
| 149 |
def command_multi( |
| 150 |
first: Literal["red", "blue"], |
| 151 |
second: Literal["cat", "dog"], |
| 152 |
/, |
| 153 |
): |
| 154 |
"""Command with multiple positionals with distinct choices. |
| 155 |
|
| 156 |
Parameters |
| 157 |
---------- |
| 158 |
first : Literal["red", "blue"] |
| 159 |
Color choice. |
| 160 |
second : Literal["cat", "dog"] |
| 161 |
Animal choice. |
| 162 |
""" |
| 163 |
pass |
| 164 |
|
| 165 |
|
| 166 |
app_deploy = App(name="deploy") |
| 167 |
|
| 168 |
|
| 169 |
@app_deploy.command |
| 170 |
def deploy_project( |
| 171 |
project: Literal["web", "api", "worker"], |
| 172 |
/, |
| 173 |
*, |
| 174 |
environment: Literal["dev", "staging", "prod"], |
| 175 |
branch: str = "main", |
| 176 |
): |
| 177 |
"""Deploy a project to an environment. |
| 178 |
|
| 179 |
Parameters |
| 180 |
---------- |
| 181 |
project : Literal["web", "api", "worker"] |
| 182 |
Project to deploy. |
| 183 |
environment : Literal["dev", "staging", "prod"] |
| 184 |
Target environment. |
| 185 |
branch : str |
| 186 |
Git branch. |
| 187 |
""" |
| 188 |
pass |
| 189 |
|
| 190 |
|
| 191 |
app_positional_path = App(name="pathpos") |
| 192 |
|
| 193 |
|
| 194 |
@app_positional_path.command |
| 195 |
def process( |
| 196 |
input_file: Path, |
| 197 |
/, |
| 198 |
): |
| 199 |
"""Process a file. |
| 200 |
|
| 201 |
Parameters |
| 202 |
---------- |
| 203 |
input_file : Path |
| 204 |
Input file to process. |
| 205 |
""" |
| 206 |
pass |
| 207 |
|
| 208 |
|
| 209 |
app_list_path = App(name="listpath") |
| 210 |
|
| 211 |
|
| 212 |
@app_list_path.default |
| 213 |
def list_path_main( |
| 214 |
files: Annotated[list[Path], Parameter(help="List of files")], |
| 215 |
): |
| 216 |
"""App with list[Path] parameter.""" |
| 217 |
pass |
| 218 |
|
| 219 |
|
| 220 |
app_list_annotated_path = App(name="listannotatedpath") |
| 221 |
|
| 222 |
|
| 223 |
@app_list_annotated_path.default |
| 224 |
def list_annotated_path_main( |
| 225 |
files: list[ExistingFile], |
| 226 |
): |
| 227 |
"""App with list[ExistingFile] parameter.""" |
| 228 |
pass |
| 229 |
|
| 230 |
|
| 231 |
app_disabled_negative = App(name="disabledneg", default_parameter=Parameter(negative="")) |
| 232 |
|
| 233 |
|
| 234 |
@app_disabled_negative.command |
| 235 |
def build(param: list[Literal["apple", "banana", "cherry"]]): |
| 236 |
"""Build command with list parameter.""" |
| 237 |
pass |
| 238 |
|
| 239 |
|
| 240 |
app_three_positionals = App(name="multipos3") |
| 241 |
|
| 242 |
|
| 243 |
@app_three_positionals.command |
| 244 |
def command_multi3( |
| 245 |
first: Literal["red", "blue"], |
| 246 |
second: Literal["cat", "dog"], |
| 247 |
third: Literal["small", "large"], |
| 248 |
/, |
| 249 |
): |
| 250 |
"""Command with three positional literals. |
| 251 |
|
| 252 |
Parameters |
| 253 |
---------- |
| 254 |
first : Literal["red", "blue"] |
| 255 |
Color choice. |
| 256 |
second : Literal["cat", "dog"] |
| 257 |
Animal choice. |
| 258 |
third : Literal["small", "large"] |
| 259 |
Size choice. |
| 260 |
""" |
| 261 |
pass |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
app_two_iterables = App(name="twoiter") |
| 269 |
|
| 270 |
|
| 271 |
@app_two_iterables.command |
| 272 |
def collect( |
| 273 |
paths: list[Path], |
| 274 |
tags: list[str], |
| 275 |
): |
| 276 |
"""Collect paths and tags. |
| 277 |
|
| 278 |
Parameters |
| 279 |
---------- |
| 280 |
paths : list[Path] |
| 281 |
Paths to collect. |
| 282 |
tags : list[str] |
| 283 |
Optional tags. |
| 284 |
""" |
| 285 |
pass |