-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
91 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .run import run |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import typer | ||
from rich import print | ||
from rich.console import Console | ||
|
||
from taskbadger.exceptions import ConfigurationError | ||
|
||
|
||
def _configure_api(ctx): | ||
config = ctx.meta["tb_config"] | ||
try: | ||
config.init_api() | ||
except ConfigurationError as e: | ||
print(f"[red]{str(e)}[/red]") | ||
raise typer.Exit(code=1) | ||
|
||
|
||
err_console = Console(stderr=True) |
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 typing import Optional | ||
|
||
import typer | ||
from rich import print | ||
|
||
from taskbadger import __version__ | ||
from taskbadger.cli import run | ||
from taskbadger.config import get_config, write_config | ||
|
||
app = typer.Typer( | ||
rich_markup_mode="rich", | ||
context_settings={"help_option_names": ["-h", "--help"]}, | ||
) | ||
|
||
|
||
app.command(context_settings={"allow_extra_args": True, "ignore_unknown_options": False})(run) | ||
|
||
|
||
def version_callback(value: bool): | ||
if value: | ||
print(f"Task Badger CLI Version: {__version__}") | ||
raise typer.Exit() | ||
|
||
|
||
@app.command() | ||
def configure(ctx: typer.Context): | ||
"""Update CLI configuration.""" | ||
config = ctx.meta["tb_config"] | ||
config.organization_slug = typer.prompt(f"Organization slug", default=config.organization_slug) | ||
config.project_slug = typer.prompt(f"Project slug", default=config.project_slug) | ||
config.token = typer.prompt(f"API Key", default=config.token) | ||
path = write_config(config) | ||
print(f"Config written to [green]{path}[/green]") | ||
|
||
|
||
@app.command() | ||
def docs(): | ||
"""Open Task Badger docs in a browser.""" | ||
typer.launch("https://docs.taskbadger.net") | ||
|
||
|
||
@app.command() | ||
def info(ctx: typer.Context): | ||
"""Show CLI configuration.""" | ||
config = ctx.meta["tb_config"] | ||
print(str(config)) | ||
|
||
|
||
@app.callback() | ||
def main( | ||
ctx: typer.Context, | ||
org: Optional[str] = typer.Option( | ||
None, | ||
"--org", | ||
"-o", | ||
metavar="TASKBADGER_ORG", | ||
show_default=False, | ||
help="Organization Slug. This will override values from the config file and environment variables.", | ||
), | ||
project: Optional[str] = typer.Option( | ||
None, | ||
"--project", | ||
"-p", | ||
show_envvar=False, | ||
metavar="TASKBADGER_PROJECT", | ||
show_default=False, | ||
help="Project Slug. This will override values from the config file and environment variables.", | ||
), | ||
version: Optional[bool] = typer.Option( # noqa | ||
None, "--version", callback=version_callback, is_eager=True, help="Show CLI Version" | ||
), | ||
): | ||
""" | ||
Task Badger CLI | ||
""" | ||
config = get_config(org=org, project=project) | ||
ctx.meta["tb_config"] = config | ||
|
||
|
||
if __name__ == "__main__": | ||
app() |
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