-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCALCLI.py
More file actions
executable file
·53 lines (39 loc) · 1.22 KB
/
CALCLI.py
File metadata and controls
executable file
·53 lines (39 loc) · 1.22 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
#!/usr/bin/env python3
from mylib.calc import add, sub, mul, div, power
import click
@click.group()
def cli():
"""A calculator module"""
@cli.command("add")
@click.argument("a", type=float)
@click.argument("b", type=float)
def add_cmd(a, b):
"""Add two numbers"""
# use colored output in f string
click.echo(click.style(f"{a} + {b} = {add(a, b)}", fg="green"))
@cli.command("sub")
@click.argument("a", type=float)
@click.argument("b", type=float)
def sub_cmd(a, b):
"""Subtract two numbers"""
click.echo(click.style(f"{a} - {b} = {sub(a, b)}", fg="red"))
@cli.command("mul")
@click.argument("a", type=float)
@click.argument("b", type=float)
def mul_cmd(a, b):
"""Multiply two numbers"""
click.echo(click.style(f"{a} * {b} = {mul(a, b)}", fg="yellow"))
@cli.command("div")
@click.argument("a", type=float)
@click.argument("b", type=float)
def div_cmd(a, b):
"""Divide two numbers"""
click.echo(click.style(f"{a} / {b} = {div(a, b)}", fg="blue"))
@cli.command("power")
@click.argument("a", type=float)
@click.argument("b", type=float)
def power_cmd(a, b):
"""Raise a to the power of b"""
click.echo(click.style(f"{a} ** {b} = {power(a, b)}", fg="magenta"))
if __name__ == "__main__":
cli()