Skip to content

Commit

Permalink
removing unusing cose, adding docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
elkanamol committed Sep 5, 2024
1 parent cd3cd20 commit 0e64200
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions sierra_status/src/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,63 @@
DEFAULT_BAUDRATE = 115200

def setup_logging(verbose: bool) -> None:
"""
Sets up the logging configuration based on the provided verbosity level.
Args:
verbose (bool): If True, sets the log level to DEBUG, otherwise sets it to INFO.
Returns:
None
"""
log_level = logging.DEBUG if verbose else logging.INFO
logging.basicConfig(level=log_level)

def validate_port(port: str) -> None:
"""
Validates that the specified USB port exists on the system.
Args:
port (str): The USB port to validate.
Raises:
ValueError: If the specified USB port does not exist.
"""
if not os.path.exists(port):
raise ValueError(f"The specified port '{port}' does not exist.")

# def validate_port(port: str) -> None:
# if sys.platform.startswith('win'):
# # For Windows, we can't easily validate COM ports
# # We could potentially use the winreg module to check available ports
# logging.warning("Windows does not have a built-in way to validate COM ports.")
# pass
# else:
# # For Unix-like systems, check if the device file exists
# if not os.path.exists(port):
# raise ValueError(f"The specified port '{port}' does not exist.")

def main() -> None:
"""
The main entry point for the Sierra Wireless EM9xxx/EM7xxx CLI tool.
This function sets up the command-line argument parser, validates the specified
USB port, and starts the process to query the status of the Sierra Wireless
module.
Args:
None
Raises:
ValueError: If the specified USB port does not exist.
Exception: If any other error occurs during the execution of the tool.
"""
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

parser = argparse.ArgumentParser(
description="CLI tool for Sierra Wireless EM9xxx/EM7xxx modules to query status",
formatter_class=argparse.RawTextHelpFormatter
)

required = parser.add_argument_group('required arguments')
required.add_argument("-p", "--port", help="USB port to use (e.g., 'COM1' for Windows or '/dev/ttyUSB2' for Linux)", required=True)

optional = parser.add_argument_group('optional arguments')
optional.add_argument("--version", help="Show version", action="version", version=f"%(prog)s {__version__}")
optional.add_argument("-m", "--model", help="Model of the device to add to filename (e.g., EM9191 or EM7455)", default="")
optional.add_argument("-v", "--verbose", help="Enable verbose output", action="store_true")
optional.add_argument("-s", "--search", help="Search for network using AT!COPS=?", action="store_true")
optional.add_argument("-b", "--baudrate", help=f"Baudrate to use for serial communication (default: {DEFAULT_BAUDRATE})", default=DEFAULT_BAUDRATE, type=int)

args = parser.parse_args()

setup_logging(args.verbose)
Expand Down

0 comments on commit 0e64200

Please sign in to comment.