feat(cli): extend upload flags for src, patterns, lib, and --all
Support --patterns/--paterns, --all, --erase, and src upload excluding patterns/. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
78
cli.py
78
cli.py
@@ -11,6 +11,7 @@ import argparse
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import shutil
|
||||
from typing import Dict, Any, List, Optional
|
||||
|
||||
import tempfile
|
||||
@@ -147,7 +148,7 @@ _FLAGS_WITH_VALUE = frozenset({
|
||||
'-p', '--port', '-n', '--name', '--pin', '-b', '--brightness',
|
||||
'-l', '--leds', '-d', '-debug', '--debug', '-o', '--order',
|
||||
'--preset', '--pattern', '--default', '--transport', '--ssid',
|
||||
'--wifi-password', '--wifi-channel',
|
||||
'--wifi-password', '--wifi-channel', '--src', '--lib', '--patterns', '--paterns',
|
||||
})
|
||||
|
||||
|
||||
@@ -201,8 +202,24 @@ def _get_ordered_actions(argv: List[str]) -> List[tuple]:
|
||||
i += 2
|
||||
else:
|
||||
i += 1
|
||||
# Use empty string as remote_dir to map to root on device
|
||||
actions.append(('upload', [local_dir, ""]))
|
||||
# Upload source tree excluding patterns/ (handled by --patterns).
|
||||
actions.append(('upload_src_no_patterns', local_dir))
|
||||
continue
|
||||
if arg in ('--patterns', '--paterns'):
|
||||
# Upload local patterns DIR (default: ./src/patterns) to /patterns.
|
||||
local_dir = os.path.join("src", "patterns")
|
||||
if i + 1 < len(argv) and not argv[i + 1].startswith('-'):
|
||||
local_dir = argv[i + 1]
|
||||
i += 2
|
||||
else:
|
||||
i += 1
|
||||
actions.append(('upload', [local_dir, "patterns"]))
|
||||
continue
|
||||
if arg == '--all':
|
||||
actions.append(('upload_src_no_patterns', "src"))
|
||||
actions.append(('upload', [os.path.join("src", "patterns"), "patterns"]))
|
||||
actions.append(('upload', ["lib", "lib"]))
|
||||
i += 1
|
||||
continue
|
||||
if arg == '--lib':
|
||||
# Upload local DIR (default: ./lib) to /lib on device
|
||||
@@ -222,6 +239,10 @@ def _get_ordered_actions(argv: List[str]) -> List[tuple]:
|
||||
actions.append(('erase_all', None))
|
||||
i += 1
|
||||
continue
|
||||
if arg == '--erase':
|
||||
actions.append(('erase_all', None))
|
||||
i += 1
|
||||
continue
|
||||
if arg == '--rm':
|
||||
if i + 1 < len(argv):
|
||||
actions.append(('rm', argv[i + 1]))
|
||||
@@ -434,7 +455,7 @@ Examples:
|
||||
nargs="?",
|
||||
const="src",
|
||||
metavar="DIR",
|
||||
help="Upload DIR recursively to device root (:/, no leading directory). If DIR is omitted, uses local ./src."
|
||||
help="Upload DIR recursively to device root (:/, no leading directory), excluding patterns/. If DIR is omitted, uses local ./src."
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
@@ -445,6 +466,21 @@ Examples:
|
||||
help="Upload DIR recursively to /lib on device. If DIR is omitted, uses local ./lib."
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--all",
|
||||
action="store_true",
|
||||
help="Upload ./src (excluding patterns), ./src/patterns, and ./lib."
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--patterns", "--paterns",
|
||||
dest="patterns_dir",
|
||||
nargs="?",
|
||||
const=os.path.join("src", "patterns"),
|
||||
metavar="DIR",
|
||||
help="Upload DIR recursively to /patterns on device. If DIR is omitted, uses local ./src/patterns."
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--ls",
|
||||
action="store_true",
|
||||
@@ -452,7 +488,7 @@ Examples:
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-e",
|
||||
"-e", "--erase",
|
||||
dest="erase_all",
|
||||
action="store_true",
|
||||
help="Erase all code on the device (delete all files except settings.json)"
|
||||
@@ -539,6 +575,38 @@ Examples:
|
||||
except Exception as e:
|
||||
print(f"Error uploading directory: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
elif action_name == 'upload_src_no_patterns':
|
||||
src_dir = value
|
||||
if not os.path.exists(src_dir):
|
||||
print(f"Error: Directory does not exist: {src_dir}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
if not os.path.isdir(src_dir):
|
||||
print(f"Error: Not a directory: {src_dir}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as temp_src:
|
||||
for entry in sorted(os.listdir(src_dir)):
|
||||
if entry == "patterns":
|
||||
continue
|
||||
src_entry = os.path.join(src_dir, entry)
|
||||
dst_entry = os.path.join(temp_src, entry)
|
||||
if os.path.isdir(src_entry):
|
||||
shutil.copytree(src_entry, dst_entry)
|
||||
else:
|
||||
shutil.copy2(src_entry, dst_entry)
|
||||
print(
|
||||
f"Uploading {src_dir} (excluding patterns/) to device root on {port}...",
|
||||
file=sys.stderr,
|
||||
)
|
||||
conn = DeviceConnection(port)
|
||||
files_copied, dirs_created = conn.upload_directory(temp_src, "")
|
||||
print(
|
||||
f"Upload complete: {files_copied} files, {dirs_created} directories created.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"Error uploading src (excluding patterns): {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
elif action_name == 'ls':
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user