Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
thatstoasty committed Apr 20, 2024
1 parent 56e3596 commit e54e766
Showing 1 changed file with 45 additions and 31 deletions.
76 changes: 45 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,68 @@ from prism import Flag, Command, CommandArc
from python import Python, PythonObject
fn base(command: CommandArc, args: List[String]) raises -> None:
fn base(command: CommandArc, args: List[String]) -> Error:
print("This is the base command!")
return Error()
fn print_information(command: CommandArc, args: List[String]) raises -> None:
fn print_information(command: CommandArc, args: List[String]) -> Error:
print("Pass cat or dog as a subcommand, and see what you get!")
return Error()
fn get_cat_fact(command: CommandArc, args: List[String]) raises -> None:
fn get_cat_fact(command: CommandArc, args: List[String]) -> Error:
var flags = command[].get_all_flags()[]
var lover = flags.get_as_bool("lover")
if lover and lover.value():
print("Hello fellow cat lover!")
var requests = Python.import_module("requests")
# URL you want to send a GET request to
var url = "https://cat-fact.herokuapp.com/facts/"
try:
var requests = Python.import_module("requests")
# Send the GET request
var response = requests.get(url)
# URL you want to send a GET request to
var url = "https://cat-fact.herokuapp.com/facts/"
# Check if the request was successful (status code 200)
if response.status_code == 200:
var count = flags.get_as_int("count")
if not count:
raise Error("Count flag was not found.")
var body = response.json()
for i in range(count.value()):
print(body[i]["text"])
else:
raise Error("Request failed!")
# Send the GET request
var response = requests.get(url)
# Check if the request was successful (status code 200)
if response.status_code == 200:
var count = flags.get_as_int("count")
if not count:
return Error("Count flag was not found.")
var body = response.json()
for i in range(count.value()):
print(body[i]["text"])
else:
return Error("Request failed!")
except e:
return e
fn get_dog_breeds(command: CommandArc, args: List[String]) raises -> None:
var requests = Python.import_module("requests")
# URL you want to send a GET request to
var url = "https://dog.ceo/api/breeds/list/all"
return Error()
# Send the GET request
var response = requests.get(url)
# Check if the request was successful (status code 200)
if response.status_code == 200:
print(response.json()["message"])
else:
raise Error("Request failed!")
fn get_dog_breeds(command: CommandArc, args: List[String]) -> Error:
try:
var requests = Python.import_module("requests")
# URL you want to send a GET request to
var url = "https://dog.ceo/api/breeds/list/all"
# Send the GET request
var response = requests.get(url)
fn init() raises -> None:
# Check if the request was successful (status code 200)
if response.status_code == 200:
print(response.json()["message"])
else:
return Error("Request failed!")
except e:
return e
return Error()
fn init() -> None:
var root_command = Command(name="nested", description="Base command.", run=base)
var get_command = Command(
Expand Down Expand Up @@ -96,8 +109,9 @@ fn init() raises -> None:
root_command.execute()
fn main() raises -> None:
fn main() -> None:
init()
```

Start by navigating to the `nested` example directory.
Expand Down

0 comments on commit e54e766

Please sign in to comment.