|
1 | 1 | import cowsay |
2 | 2 | import argparse |
3 | 3 |
|
4 | | -# Get dynamic list of animals from the cowsay library |
5 | | -animals = cowsay.char_names |
| 4 | +def main(): |
| 5 | + # Get dynamic list of animals from the cowsay library |
| 6 | + animals = cowsay.char_names |
6 | 7 |
|
7 | | -parser = argparse.ArgumentParser( |
8 | | - prog="cowsay", |
9 | | - description="Make animals say things" |
10 | | -) |
| 8 | + parser = argparse.ArgumentParser( |
| 9 | + prog="cowsay", |
| 10 | + description="Make animals say things" |
| 11 | + ) |
11 | 12 |
|
12 | | -parser.add_argument("--animal", choices=animals, help="The animal to be saying things.") |
13 | | -parser.add_argument("message", nargs="+", help="The message to say.") |
| 13 | + parser.add_argument("--animal", choices=animals, help="The animal to be saying things.") |
| 14 | + parser.add_argument("message", nargs="+", help="The message to say.") |
14 | 15 |
|
15 | | -args = parser.parse_args() |
| 16 | + args = parser.parse_args() |
16 | 17 |
|
17 | | -# Join all message words into a single string |
18 | | -message = " ".join(args.message) |
| 18 | + # Join all message words into a single string |
| 19 | + message = " ".join(args.message) |
19 | 20 |
|
| 21 | + if args.animal: |
| 22 | + cowsay.char_funcs[args.animal](message) |
| 23 | + else: |
| 24 | + cowsay.cow(message) |
20 | 25 |
|
21 | | -if args.animal: |
22 | | - cowsay.char_funcs[args.animal](message) |
23 | | -else: |
24 | | - # if no animal is provided, use default |
25 | | - cowsay.cow(message) |
26 | | - |
| 26 | +if __name__ == "__main__": |
| 27 | + main() |
0 commit comments