Improve Linux terminal input and interactive path prompts
This commit is contained in:
1 parent
eb5937a629
commit
ad2b15994f
5 files changed
+190
-22
No files matched your search
Regular → Executable
+13
-6
@@ -13,9 +13,9 @@ from __future__ import annotations
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from tools.console import pause_if_interactive
|
||||
from tools.console import launch_terminal_if_needed, pause_if_interactive
|
||||
from tools.exiftool import require_exiftool, run_exiftool_command
|
||||
from tools.filesystem import first_file_from_path
|
||||
from tools.filesystem import first_file_from_path, input_paths
|
||||
|
||||
|
||||
def choose_file(args: list[str]) -> Path | None:
|
||||
@@ -27,9 +27,14 @@ def choose_file(args: list[str]) -> Path | None:
|
||||
|
||||
|
||||
def run(argv: list[str]) -> int:
|
||||
if len(argv) < 2:
|
||||
print("Usage: python3 view_metadata.py path/to/file/or/directory [...]")
|
||||
return 2
|
||||
try:
|
||||
args = input_paths(argv)
|
||||
except RuntimeError as exc:
|
||||
print(exc)
|
||||
return 1
|
||||
if not args:
|
||||
print("No inputs selected.")
|
||||
return 0
|
||||
|
||||
try:
|
||||
exiftool = require_exiftool()
|
||||
@@ -37,7 +42,7 @@ def run(argv: list[str]) -> int:
|
||||
print(exc)
|
||||
return 1
|
||||
|
||||
file_path = choose_file(argv[1:])
|
||||
file_path = choose_file(args)
|
||||
if file_path is None:
|
||||
print("No file found.")
|
||||
return 1
|
||||
@@ -55,6 +60,8 @@ def run(argv: list[str]) -> int:
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
if launch_terminal_if_needed(argv):
|
||||
return 0
|
||||
try:
|
||||
return run(argv)
|
||||
finally:
|
||||
|
||||
Reference in new issue
Block a user