-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathexample.py
More file actions
54 lines (44 loc) · 1.25 KB
/
Copy pathexample.py
File metadata and controls
54 lines (44 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from typer import Context
import devcli.framework as cmd
cli = cmd.new("Examples on how create cli commands with *devcli*")
@cli.command()
def hello(name: str, rainbow: bool = False):
"""
Simplest example of a command, it just outputs "Hello, NAME!"
If --rainbow is passed it will make it colorful
"""
if rainbow:
colors = ["red", "orange1", "yellow1", "green", "blue", "purple"]
name = "".join(
f"[{colors[i % len(colors)]}]{char}[/{colors[i % len(colors)]}]"
for i, char in enumerate(name)
)
cmd.echo(f"Hello, {name}!")
@cli.command()
def ping():
"""
Replies with a PONG!
"""
cmd.echo("PONG!")
@cli.command()
def text():
"""
Demo types of text output you can use
out of the box as shortcuts.
"""
cmd.echo("This is a cmd.echo(msg)")
cmd.info("This is a cmd.info(msg)")
cmd.warn("This is a cmd.warn(msg)")
cmd.error("This is a cmd.error(msg)")
# Simple table
table = [
["This is", "a simple table"],
["With one value", "and another"],
]
cmd.table(table)
@cli.command()
def config(ctx: Context):
"""
Example of access to global configurations
"""
cmd.echo(f"Default devcli config: {ctx.obj['devcli']}")