Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft option #20

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions markdown_anki_decks/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def convertMarkdown(
"--prefix",
help="Can be used to make your markdown decks part of a single subdeck. Anki uses `::` to indicate sub decks. `markdown-decks::` could be used to make all generated decks part of a single root deck `markdown-decks`",
),
filetype: str = typer.Option(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the name of this parameter to extension with a short option of --ext? That would match the API exposed by other similar programs. For example, see eslint.

Can we allow the user to pass multiple extensions instead of just a single string? See the page multiple cli options in the typer docs for instructions on how to do this. We would have to change the default value to ["md"] and the type to Optional[List[str]].

"md",
"--ft",
help="Can be use to specify the use of other filetypes. Specify just the fine extension, e.g., 'txt'",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the help text to something like.

"This option lets you specify which file extensions markdown-anki-decks will use when searching for files to convert into Anki decks. By default, it uses 'md' as the only file extension."

),
delete_cards: bool = typer.Option(
False,
"--delete",
Expand All @@ -62,11 +67,12 @@ def convertMarkdown(
False, "--version", callback=version_callback, help="Show version information"
),
):

"""Interface for the cli convert command."""
# iterate over the source directory
for root, _, files in os.walk(input_dir):
for file in files:
if is_markdown_file(file):
if is_correct_filetype(file, filetype):
deck = parse_markdown(
os.path.join(root, file), deck_title_prefix, cloze
)
Expand Down Expand Up @@ -242,10 +248,9 @@ def read_file(file):


# check if a file is a markdown file
def is_markdown_file(file):
"""Check if a file is a markdown file."""
# TODO(lukemurray): parameterize markdown extensions?
return file.endswith(".md")
def is_correct_filetype(file, filetype: str):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change is_correct_filetype to has_file_extension.

change the filetype parameter to extension or extensions (up to you). Also the second parameter will be a list once you make the changes from above so you'll have to change some of the types and logic here.

"""Check if a file has the correct extension."""
return file.endswith(f".{filetype}")


def integer_hash(s: str):
Expand Down