Skip to content

Commit

Permalink
Save *resolved* database path in CLI config
Browse files Browse the repository at this point in the history
  • Loading branch information
vaneseltine committed Jul 12, 2024
1 parent dabb820 commit 6db8bd4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
## Usage

> [!WARNING]
> [!WARNING]
> This is a work in progress. The API is subject to change.
Get yourself a copy of the [Retraction Watch database](#retraction-watch-database),
Expand All @@ -36,6 +36,32 @@ paper = ash.Paper.from_path("./manuscript.docx")
pprint(paper.report(db))
```

## Terminal

A rudimentary command line interface is currently included for your convenience:

```
$ ash
Usage: ash [OPTIONS] [PAPER]
Simple program that runs Ash on PAPER using DATABASE.
Options:
--database PATH Path to retractions database file.
--clear Clear path to database file.
--help Show this message and exit.
$ ash --database ./retractions.csv
Database path: ./retractions.csv
$ ash questionable_paper.docx
Database path: ./retractions.csv
{'dois': {'10.21105/joss.03440': {'Retracted': False}}, 'zombies': []}
```

The path of the database persists between sessions, so you'll likely need to specify it
only the once.

## Notebook

For a full-fledged demonstration without any need to install on your own machine,
Expand Down
20 changes: 13 additions & 7 deletions ash/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
show_default=True,
type=click.Path(),
)
@click.option(
"--clear", help="Clear saved retractions database file path.", is_flag=True
)
@click.option("--clear", help="Clear path to database file.", is_flag=True)
@click.pass_context
def ash_cli(ctx: click.Context, paper: str, database: str | Path | None, clear: bool):
def ash_cli(
ctx: click.Context,
paper: str | None,
database: str | Path | None,
clear: bool,
):
"""
Simple program that runs Ash on PAPER using DATABASE.
"""
Expand All @@ -38,16 +41,19 @@ def ash_cli(ctx: click.Context, paper: str, database: str | Path | None, clear:
"Error: You must specify the path of a retractions database with --database."
)
ctx.exit()
click.echo(f"Using database at {database}...")
click.echo(f"Database path: {database.resolve()}.")
if paper is None:
ctx.exit()
print_basic_report(paper, database)


def locate_database(database: str | Path | None) -> Path | None:
database = database or stored_database
if database is None or database == "":
return None
_ = config.write_value(table="database", key="path", value=database)
return Path(database)
database_path = Path(database).resolve()
_ = config.write_value(table="database", key="path", value=str(database_path))
return database_path


def print_basic_report(paper_spec: str, database_spec: str | Path):
Expand Down

0 comments on commit 6db8bd4

Please sign in to comment.