-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
34 lines (25 loc) · 851 Bytes
/
utils.py
File metadata and controls
34 lines (25 loc) · 851 Bytes
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
from typing import Tuple
def read_file(file):
"""Reads a file and returns its contents."""
try:
with open(file, "r") as f:
content = f.read()
return content
except FileNotFoundError:
print(f"File {file} not found.")
exit(1)
__RUN_COMMAND_USAGE = "Usage: python3 myrpal.py [-ast, -st] <file_name>\nRequired: <file_name>\nOptional: -as"
def init_args(args)->Tuple[str, str]:
"""Takes command line arguments as input and returns the file name and switch"""
switch:str = None
file_name = ""
if len(args) < 2:
print(__RUN_COMMAND_USAGE)
exit(1)
if len(args) > 2:
file_name = args[2]
if str.startswith(args[1], "-"):
switch = args[1]
else:
file_name = args[1]
return file_name, switch