refactor: reorder and document repo view, pr create
This commit is contained in:
parent
5cbe845e6e
commit
39ffff45c6
1 changed files with 45 additions and 12 deletions
57
frg/cli.py
57
frg/cli.py
|
@ -15,34 +15,67 @@ class CliContext(pydantic.BaseModel):
|
||||||
@click.group()
|
@click.group()
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def cli(ctx):
|
def cli(ctx):
|
||||||
|
"""
|
||||||
|
A command-line tool to interact with different kinds of code forges.
|
||||||
|
"""
|
||||||
|
|
||||||
config = get_configuration()
|
config = get_configuration()
|
||||||
git_context = get_git_context(domain_aliases=config.domain_aliases)
|
git_context = get_git_context(domain_aliases=config.domain_aliases)
|
||||||
ctx.obj = CliContext(git=git_context, config=config)
|
ctx.obj = CliContext(git=git_context, config=config)
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.group()
|
||||||
@click.pass_obj
|
@click.pass_obj
|
||||||
def pr(ctx):
|
def pr(ctx):
|
||||||
forgejo_browser.create_pull_request_via_web(
|
"""Interacts with pull requests."""
|
||||||
head=ctx.git.current_branch,
|
pass
|
||||||
host=ctx.git.host,
|
|
||||||
repo=ctx.git.repo_name,
|
|
||||||
owner=ctx.git.repo_author,
|
@pr.command(name="create")
|
||||||
)
|
@click.option(
|
||||||
|
"-w",
|
||||||
|
"--web",
|
||||||
|
type=bool,
|
||||||
|
is_flag=True,
|
||||||
|
help="Opens the pull-request page in the default browser.",
|
||||||
|
)
|
||||||
|
@click.pass_obj
|
||||||
|
def create_pr(ctx, web: bool):
|
||||||
|
"""Interacts with pull requests."""
|
||||||
|
|
||||||
|
if web:
|
||||||
|
forgejo_browser.create_pull_request_via_web(
|
||||||
|
head=ctx.git.current_branch,
|
||||||
|
host=ctx.git.host,
|
||||||
|
repo=ctx.git.repo_name,
|
||||||
|
owner=ctx.git.repo_author,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@cli.group()
|
@cli.group()
|
||||||
@click.pass_obj
|
@click.pass_obj
|
||||||
def repo(ctx):
|
def repo(ctx):
|
||||||
|
"""Interacts with repositories"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@repo.command()
|
@repo.command(name="view")
|
||||||
|
@click.option(
|
||||||
|
"-w",
|
||||||
|
"--web",
|
||||||
|
type=bool,
|
||||||
|
is_flag=True,
|
||||||
|
help="Opens the repository page in the default browser.",
|
||||||
|
)
|
||||||
@click.pass_obj
|
@click.pass_obj
|
||||||
def view(ctx):
|
def view_repo(ctx, web: bool):
|
||||||
forgejo_browser.view_repository_via_web(
|
"""View the current repository."""
|
||||||
host=ctx.git.host, repo=ctx.git.repo_name, owner=ctx.git.repo_author
|
if web:
|
||||||
)
|
forgejo_browser.view_repository_via_web(
|
||||||
|
host=ctx.git.host, repo=ctx.git.repo_name, owner=ctx.git.repo_author
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise NotImplementedError("--web is the only mode supported.")
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in a new issue