Skip to content

Commit 092ebeb

Browse files
committed
Using rich table for list
1 parent 8969fdb commit 092ebeb

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

ffpm.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
along with this program. If not, see <https://www.gnu.org/licenses/>.
1919
"""
2020

21-
2221
# M""""""""`M dP
2322
# Mmmmmm .M 88
2423
# MMMMP .MMM dP dP 88 .dP .d8888b.
@@ -35,6 +34,8 @@
3534
import subprocess
3635
import sys
3736

37+
from typing_extensions import Annotated
38+
3839
DEPS = ['typer[all]', None, None, 'watchdog'] # None cuz its built-in
3940
DEP_CHECK_NAMES = ['typer', 'zipfile', 'shutil', 'watchdog']
4041

@@ -322,25 +323,37 @@ def watch(profile_name: str = typer.Argument(...), out: str = "watch-log.csv"):
322323

323324

324325
def _ensureBakDir():
325-
import os
326-
os.makedirs(BACKUP_DIR)
326+
import os
327+
os.makedirs(BACKUP_DIR)
328+
327329

328330
@app.command()
329331
def list():
330332
profiles = get_profiles()
333+
from rich.table import Table
334+
from rich.console import Console
335+
table = Table("Name", "Path")
336+
console = Console()
331337
for name, path in profiles.items():
332-
typer.echo(f"{name}: {path}")
338+
table.add_row(name, str(path))
339+
console.print(table)
333340

334341

335342
@app.command()
336-
def export_profile(name: str, output: Path):
343+
def export_profile(name: str, output: Annotated[Path, typer.Argument()] = None):
344+
"""
345+
Export a Firefox profile to a zip file
346+
Args:
347+
name: profile name
348+
output: output path, if omitted. It will be {name}.zip, located in ~/firefox-profile-backups
349+
"""
337350
useDefaultDir = True
338351
if not output:
339352
output = name
340353
if not str(output).endswith(".zip"):
341354
output = Path(output).with_suffix(".zip")
342355
if '/' in str(output) or '\\' in str(output):
343-
useDefaultDir = False
356+
useDefaultDir = False
344357
output = Path(BACKUP_DIR / output if useDefaultDir else output)
345358
_ensureBakDir()
346359
profiles = get_profiles()
@@ -357,7 +370,14 @@ def export_profile(name: str, output: Path):
357370

358371

359372
@app.command()
360-
def import_profile(zip_path, name: str):
373+
def import_profile(zip_path: Annotated[Path, typer.Argument()],
374+
name: Annotated[str, typer.Argument(autocompletion=get_profiles)]):
375+
"""
376+
Import a zip file to a Firefox profile
377+
Args:
378+
zip_path: path to zip file
379+
name: profile name
380+
"""
361381
if not (str(zip_path).index('/') == -1) or not (str(zip_path).index('/1') != -1):
362382
zip_path = get_profile_path(name)
363383
if not zip_path.exists():

0 commit comments

Comments
 (0)