61 lines
1.2 KiB
Python
Executable file
61 lines
1.2 KiB
Python
Executable file
import os
|
|
import typer
|
|
|
|
from pathlib import Path
|
|
from database import Shelf
|
|
from utils import die
|
|
|
|
|
|
|
|
app = typer.Typer()
|
|
project_subcommand = typer.Typer()
|
|
app.add_typer(project_subcommand, name='project')
|
|
|
|
entries: dict = {
|
|
'dirs': [],
|
|
'projects': [],
|
|
'config': {}
|
|
}
|
|
|
|
|
|
|
|
@project_subcommand.command('add')
|
|
def project_add(path: Path, name: str = None, runner: str = None, editor: str = 'code', multi: bool = False):
|
|
|
|
global entries
|
|
|
|
if multi:
|
|
die('Cannot specify name for a dir', 2) if name else None
|
|
|
|
for dir in os.listdir(path):
|
|
entries['dirs'].append(create_entry(path/dir, name, runner, editor))
|
|
|
|
else:
|
|
entries['projects'].append(create_entry(path, name, runner, editor))
|
|
|
|
with Shelf('spyglass') as shelf:
|
|
shelf.update(entries)
|
|
|
|
|
|
|
|
def create_entry(path: Path, name: str, runner: str, editor: str):
|
|
if not name:
|
|
name = os.path.dirname(path)
|
|
|
|
if not runner:
|
|
runner = None
|
|
|
|
if not editor:
|
|
editor = None
|
|
|
|
return {name: {'path': str(path.resolve()), 'runner': str(path/runner) if runner else None, 'editor': editor}}
|
|
|
|
|
|
|
|
def main():
|
|
app()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|