Compare commits
1 Commits
9e72c62481
...
713cd6e9a1
| Author | SHA1 | Date | |
|---|---|---|---|
| 713cd6e9a1 |
37
cli.py
37
cli.py
@@ -154,7 +154,7 @@ _FLAGS_WITH_VALUE = frozenset({
|
|||||||
def _get_ordered_actions(argv: List[str]) -> List[tuple]:
|
def _get_ordered_actions(argv: List[str]) -> List[tuple]:
|
||||||
"""
|
"""
|
||||||
Scan argv and return list of (action_name, value) in order of appearance.
|
Scan argv and return list of (action_name, value) in order of appearance.
|
||||||
Actions: flash, pause, reset, upload, erase_all, rm, follow.
|
Actions: flash, pause, reset, upload, ls, erase_all, rm, follow.
|
||||||
"""
|
"""
|
||||||
actions = []
|
actions = []
|
||||||
i = 1
|
i = 1
|
||||||
@@ -205,13 +205,18 @@ def _get_ordered_actions(argv: List[str]) -> List[tuple]:
|
|||||||
actions.append(('upload', [local_dir, ""]))
|
actions.append(('upload', [local_dir, ""]))
|
||||||
continue
|
continue
|
||||||
if arg == '--lib':
|
if arg == '--lib':
|
||||||
# Upload local DIR to /lib on device
|
# Upload local DIR (default: ./lib) to /lib on device
|
||||||
if i + 1 < len(argv):
|
local_dir = "lib"
|
||||||
|
if i + 1 < len(argv) and not argv[i + 1].startswith('-'):
|
||||||
local_dir = argv[i + 1]
|
local_dir = argv[i + 1]
|
||||||
actions.append(('upload', [local_dir, "lib"]))
|
|
||||||
i += 2
|
i += 2
|
||||||
else:
|
else:
|
||||||
raise ValueError("--lib requires a directory argument")
|
i += 1
|
||||||
|
actions.append(('upload', [local_dir, "lib"]))
|
||||||
|
continue
|
||||||
|
if arg == '--ls':
|
||||||
|
actions.append(('ls', None))
|
||||||
|
i += 1
|
||||||
continue
|
continue
|
||||||
if arg == '-e':
|
if arg == '-e':
|
||||||
actions.append(('erase_all', None))
|
actions.append(('erase_all', None))
|
||||||
@@ -434,8 +439,16 @@ Examples:
|
|||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--lib",
|
"--lib",
|
||||||
|
nargs="?",
|
||||||
|
const="lib",
|
||||||
metavar="DIR",
|
metavar="DIR",
|
||||||
help="Upload DIR recursively to /lib on device"
|
help="Upload DIR recursively to /lib on device. If DIR is omitted, uses local ./lib."
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--ls",
|
||||||
|
action="store_true",
|
||||||
|
help="List files on the device root (:/)"
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -527,6 +540,18 @@ Examples:
|
|||||||
print(f"Error uploading directory: {e}", file=sys.stderr)
|
print(f"Error uploading directory: {e}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
elif action_name == 'ls':
|
||||||
|
try:
|
||||||
|
print(f"Listing files on device {port}...", file=sys.stderr)
|
||||||
|
conn = DeviceConnection(port)
|
||||||
|
items = conn.list_files('')
|
||||||
|
for name, is_dir, size in items:
|
||||||
|
marker = "d" if is_dir else "-"
|
||||||
|
print(f"{marker} {size:>8} {name}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error listing files: {e}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
elif action_name == 'erase_all':
|
elif action_name == 'erase_all':
|
||||||
try:
|
try:
|
||||||
print(f"Erasing all code on device {port}...", file=sys.stderr)
|
print(f"Erasing all code on device {port}...", file=sys.stderr)
|
||||||
|
|||||||
Reference in New Issue
Block a user