Compare commits
2 Commits
eee9327e15
...
713cd6e9a1
| Author | SHA1 | Date | |
|---|---|---|---|
| 713cd6e9a1 | |||
| 9e72c62481 |
2
Pipfile
2
Pipfile
@@ -16,5 +16,5 @@ python_version = "3"
|
||||
[scripts]
|
||||
web = "python web.py"
|
||||
cli = "python cli.py"
|
||||
build = "pyinstaller --clean led-cli.spec"
|
||||
build = "pyinstaller --clean --onefile --name led-cli --paths lib cli.py"
|
||||
install = "pipenv install"
|
||||
|
||||
37
cli.py
37
cli.py
@@ -154,7 +154,7 @@ _FLAGS_WITH_VALUE = frozenset({
|
||||
def _get_ordered_actions(argv: List[str]) -> List[tuple]:
|
||||
"""
|
||||
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 = []
|
||||
i = 1
|
||||
@@ -205,13 +205,18 @@ def _get_ordered_actions(argv: List[str]) -> List[tuple]:
|
||||
actions.append(('upload', [local_dir, ""]))
|
||||
continue
|
||||
if arg == '--lib':
|
||||
# Upload local DIR to /lib on device
|
||||
if i + 1 < len(argv):
|
||||
# Upload local DIR (default: ./lib) to /lib on device
|
||||
local_dir = "lib"
|
||||
if i + 1 < len(argv) and not argv[i + 1].startswith('-'):
|
||||
local_dir = argv[i + 1]
|
||||
actions.append(('upload', [local_dir, "lib"]))
|
||||
i += 2
|
||||
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
|
||||
if arg == '-e':
|
||||
actions.append(('erase_all', None))
|
||||
@@ -434,8 +439,16 @@ Examples:
|
||||
|
||||
parser.add_argument(
|
||||
"--lib",
|
||||
nargs="?",
|
||||
const="lib",
|
||||
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(
|
||||
@@ -527,6 +540,18 @@ Examples:
|
||||
print(f"Error uploading directory: {e}", file=sys.stderr)
|
||||
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':
|
||||
try:
|
||||
print(f"Erasing all code on device {port}...", file=sys.stderr)
|
||||
|
||||
@@ -10,7 +10,7 @@ pipenv install "$@"
|
||||
if [ ! -f "dist/led-cli" ] || [ "cli.py" -nt "dist/led-cli" ] || [ "device.py" -nt "dist/led-cli" ]; then
|
||||
echo ""
|
||||
echo "Building binary..."
|
||||
pipenv run pyinstaller --clean led-cli.spec
|
||||
pipenv run pyinstaller --clean --onefile --name led-cli --paths lib cli.py
|
||||
fi
|
||||
|
||||
# Ensure ~/.local/bin exists
|
||||
|
||||
Reference in New Issue
Block a user