-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
61 lines (46 loc) · 1.41 KB
/
cli.py
File metadata and controls
61 lines (46 loc) · 1.41 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
55
56
57
58
59
60
61
import click
import sys
from datetime import datetime
@click.group()
@click.version_option(version="1.0.0")
def cli():
"""
Example CLI tool built with Poetry and python-container-builder.
Demonstrates how to package a CLI application into a distroless container.
"""
pass
@cli.command()
@click.argument("name")
@click.option("--formal", is_flag=True, help="Use formal greeting")
def greet(name, formal):
"""Greet someone by NAME."""
if formal:
greeting = f"Good day, {name}. It is a pleasure to make your acquaintance."
else:
greeting = f"Hello, {name}!"
click.echo(greeting)
@cli.command()
@click.argument("text")
def count(text):
"""Count words and characters in TEXT."""
words = len(text.split())
chars = len(text)
click.echo(f"Text: {text}")
click.echo(f"Words: {words}")
click.echo(f"Characters: {chars}")
@cli.command()
def info():
"""Show system information."""
click.echo("System Information:")
click.echo(f" Python version: {sys.version}")
click.echo(f" Current time: {datetime.now().isoformat()}")
click.echo(f" Platform: {sys.platform}")
@cli.command()
@click.option("--count", default=1, help="Number of times to repeat")
@click.argument("message")
def repeat(count, message):
"""Repeat MESSAGE multiple times."""
for i in range(count):
click.echo(f"{i+1}. {message}")
if __name__ == "__main__":
cli()