-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from aseemsavio/ux-improvements
Ux improvements
- Loading branch information
Showing
21 changed files
with
310 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
import click | ||
|
||
from catholic.commands import register_commands | ||
from catholic.core.utils.docs import welcome_text | ||
from catholic.commands.choice import interactive_cli | ||
from catholic.core.utils.console import display_welcome_text | ||
from catholic.version import version | ||
from typer import Typer, Context | ||
|
||
__version__ = version | ||
|
||
# This is the root object to which all the commands get registered to. | ||
cli = Typer() | ||
|
||
|
||
@cli.callback(invoke_without_command=True) | ||
def catholic_features_callback(ctx: Context): | ||
# Execute this only if there is no sub command. | ||
# https://typer.tiangolo.com/tutorial/commands/context/#exclusive-executable-callback | ||
|
||
@click.group(help=welcome_text(__version__)) | ||
@click.version_option(__version__) | ||
@click.pass_context | ||
def cli(ctx: click.Context): | ||
""" | ||
Welcome to catholic-cli! | ||
""" | ||
ctx.obj = "Aseem Savio" | ||
pass | ||
if ctx.invoked_subcommand is None: | ||
display_welcome_text() | ||
interactive_cli() | ||
|
||
|
||
register_commands(cli) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,35 @@ | ||
import click | ||
from typing import Optional | ||
|
||
from catholic.commands.canon import canon | ||
from catholic.commands.catechism import catechism | ||
from catholic.commands.missal import missal | ||
from typer import Typer, Option | ||
|
||
from catholic.core.utils.docs import paragraph_help_text, search_help_text | ||
|
||
def register_commands(group: click.Group): | ||
group.add_command(cmd=catechism, name="catechism") | ||
group.add_command(cmd=canon, name="canon") | ||
group.add_command(cmd=missal, name="missal") | ||
import catholic.core.catechism.api as catechism_api | ||
import catholic.core.canon.api as canon_api | ||
import catholic.core.missal.api as missal_api | ||
|
||
|
||
def register_commands(cli: Typer): | ||
""" | ||
This function contains the logic to register the commands in this CLI. | ||
:param cli: Typer Object to which we register commands | ||
:return: None | ||
""" | ||
|
||
@cli.command(name="catechism", help="Query The catechism of The Catholic Church.") | ||
def catechism_impl(paragraph: Optional[str] = Option(None, "--paragraph", "-p", help=paragraph_help_text()), | ||
search: Optional[str] = Option(None, "--search", "-s", help=search_help_text()) | ||
): | ||
catechism_api.execute(paragraph=paragraph, search=search) | ||
|
||
@cli.command(name="canon", help="Query The Canon Law of The Catholic Church.") | ||
def canon_impl(paragraph: Optional[str] = Option(None, "--paragraph", "-p", help=paragraph_help_text()), | ||
search: Optional[str] = Option(None, "--search", "-s", help=search_help_text()) | ||
): | ||
canon_api.execute(law=paragraph, search=search) | ||
|
||
@cli.command(name="missal", help="Query The general Instruction of The Roman Missal.") | ||
def missal_impl(paragraph: Optional[str] = Option(None, "--paragraph", "-p", help=paragraph_help_text()), | ||
search: Optional[str] = Option(None, "--search", "-s", help=search_help_text()) | ||
): | ||
missal_api.execute(missal_id=paragraph, search=search) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
from dataclasses import dataclass | ||
from enum import Enum | ||
from typing import List | ||
|
||
import questionary as q | ||
from catholic.core.canon import api as canon_api | ||
from catholic.core.catechism import api as catechism_api | ||
from catholic.core.missal import api as missal_api | ||
|
||
|
||
def interactive_cli(): | ||
""" | ||
This function runs the CLI in an interactive mode for non-tech-savy users. | ||
:return: None | ||
""" | ||
|
||
root = InteractiveCli( | ||
messages=[ | ||
Resource("catechism", "The Catechism of The Catholic Church", [SearchBy.Para, SearchBy.Text]), | ||
Resource("canon", "The Canon Law of The Church", [SearchBy.Para, SearchBy.Text]), | ||
Resource("missal", "The Roman Missal", [SearchBy.Para, SearchBy.Text]), | ||
] | ||
) | ||
|
||
### | ||
# root = { | ||
# "messages": { | ||
# "catechism": "The Catechism of The Catholic Church", | ||
# "canon": "The Canon Law of The Church", | ||
# "missal": "The Roman Missal" | ||
# } | ||
# } | ||
|
||
# by_para = "Search by Paragraph ID(s)" | ||
# by_text = "Search by Text" | ||
|
||
resource = q.select( | ||
"What do you want to search?", | ||
choices=[r.long_name for r in root.messages] | ||
).ask() | ||
|
||
resource_name = [r.short_name for r in root.messages if resource == r.long_name][0] | ||
|
||
search_by = q.select( | ||
"How do you want to search?", | ||
choices=[str(v.value) for v in | ||
[r for r in root.messages if r.short_name == resource_name][0].search_by_possibilities] | ||
).ask() | ||
|
||
para, search_text = None, None | ||
|
||
# if search_by == by_para: | ||
# para = q.text(f"Enter the {str(resource_name).capitalize()} paragraphs you wish to search: ").ask() | ||
# else: | ||
# search_text = q.text(f"Enter the exact text you wish to search in {resource}: ").ask() | ||
|
||
if resource_name == "catechism": | ||
catechism_api.execute(paragraph=None, search=None, search_by=SearchBy(search_by).name) | ||
|
||
elif resource_name == "canon": | ||
canon_api.execute(law=None, search=None, search_by=SearchBy(search_by).name) | ||
|
||
elif resource_name == "missal": | ||
missal_api.execute(missal_id=None, search=None, search_by=SearchBy(search_by).name) | ||
|
||
|
||
class SearchBy(Enum): | ||
Para = "Search by Paragraph ID(s)" | ||
Text = "Search by Text" | ||
|
||
|
||
@dataclass | ||
class Resource: | ||
short_name: str | ||
long_name: str | ||
search_by_possibilities: List[SearchBy] | ||
|
||
|
||
@dataclass | ||
class InteractiveCli: | ||
messages: List[Resource] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.