write basic cli for init and import
This commit is contained in:
parent
4538969c10
commit
daab486f7b
4 changed files with 73 additions and 1 deletions
60
corrlib/cli.py
Normal file
60
corrlib/cli.py
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
from typing import Optional
|
||||
import typer
|
||||
from corrlib import __app_name__, __version__
|
||||
from .initialization import create
|
||||
from .toml import import_toml
|
||||
app = typer.Typer()
|
||||
|
||||
|
||||
def _version_callback(value: bool) -> None:
|
||||
if value:
|
||||
typer.echo(f"{__app_name__} v{__version__}")
|
||||
raise typer.Exit()
|
||||
|
||||
|
||||
@app.command()
|
||||
def importer(
|
||||
path: str = typer.Option(
|
||||
str('./corrlib'),
|
||||
"--dataset",
|
||||
"-d",
|
||||
prompt="Which corrlib instance?"
|
||||
),
|
||||
file: str = typer.Argument(
|
||||
),
|
||||
copy_file: bool = typer.Option(
|
||||
bool(True),
|
||||
"--save",
|
||||
"-s",
|
||||
prompt="Copy config file?",
|
||||
),
|
||||
) -> None:
|
||||
import_toml(path, file, copy_file)
|
||||
return
|
||||
|
||||
|
||||
@app.command()
|
||||
def init(
|
||||
path: str = typer.Option(
|
||||
str('./corrlib'),
|
||||
"--dataset",
|
||||
"-d",
|
||||
prompt="Dataset location?",
|
||||
),
|
||||
) -> None:
|
||||
create(path)
|
||||
return
|
||||
|
||||
|
||||
@app.callback()
|
||||
def main(
|
||||
version: Optional[bool] = typer.Option(
|
||||
None,
|
||||
"--version",
|
||||
"-v",
|
||||
help="Show the application's version and exit.",
|
||||
callback=_version_callback,
|
||||
is_eager=True,
|
||||
)
|
||||
) -> None:
|
||||
return
|
||||
Loading…
Add table
Add a link
Reference in a new issue