-
Notifications
You must be signed in to change notification settings - Fork 2
/
Example.py
51 lines (36 loc) · 1.41 KB
/
Example.py
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
# import hypercli
from hypercli import Hypercli
# create an instance of hypercli
cli = Hypercli()
# configure the instance
cli.config["banner_text"] = "HYPERCLI"
cli.config["intro_title"] = "Intro"
cli.config["intro_content"] = "Generate enhanced menu-driven CLI programs with ease!"
cli.config["show_menu_table_header"] = True
# add navigation options to the menu
cli.link("Main Menu", "Mathematics Menu")
cli.link("Main Menu", "String Menu")
@cli.entry(menu="Main Menu", option="Greeter")
def greet():
name = input("Enter your name: ")
print(f"Hello, {name}!")
@cli.entry(menu="Mathematics Menu", option="Add two numbers")
def add(num1=1, num2=1):
a = int(input(f"Enter first number (default {num1}): ") or num1)
b = int(input(f"Enter second number (default {num2}): ") or num2)
print(f"{a} + {b} = {a + b}")
@cli.entry(menu="Mathematics Menu", option="Subtract two numbers")
def sub(num1=1, num2=1):
a = int(input(f"Enter first number (default {num1}): ") or num1)
b = int(input(f"Enter second number (default {num2}): ") or num2)
print(f"{a} - {b} = {a - b}")
@cli.entry(menu="String Menu", option="Reverse a string")
def reverse():
string = input("Enter a string: ")
print(string[::-1])
@cli.entry(menu="String Menu", option="Show length of a string")
def str_length():
string = input("Enter a string: ")
print(f"Length of string is {len(string)}")
# run the cli
cli.run()