Handles a `cd` shell command by calling python's os.chdir.
(command: list[str])
| 13 | |
| 14 | |
| 15 | def handle_cd_command(command: list[str]) -> tuple[bool, str | None]: |
| 16 | """Handles a `cd` shell command by calling python's os.chdir.""" |
| 17 | if not command[0].lower() == 'cd': |
| 18 | return False, 'Not a cd command.' |
| 19 | if len(command) != 2: |
| 20 | return False, 'Exactly one directory name must be provided.' |
| 21 | directory = command[1] |
| 22 | try: |
| 23 | os.chdir(directory) |
| 24 | click.echo(os.getcwd(), err=True) |
| 25 | return True, None |
| 26 | except OSError as e: |
| 27 | return False, e.strerror |
| 28 | |
| 29 | |
| 30 | def format_uptime(uptime_in_seconds: str) -> str: |