Skip to content

Commit

Permalink
fix: help text fixes (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Sep 10, 2021
1 parent 1311178 commit 4ee59d5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 59 deletions.
33 changes: 33 additions & 0 deletions src/ape/options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import click

from ape import networks


class NetworkChoice(click.Choice):
"""Wraps ``click.Choice`` to provide network choice defaults for the active project."""

def __init__(self, case_sensitive=True):
super().__init__(list(networks.network_choices), case_sensitive)

def get_metavar(self, param):
return "[ecosystem-name][:[network-name][:[provider-name]]]"


network_option = click.option(
"--network",
type=NetworkChoice(case_sensitive=False),
default=networks.default_ecosystem.name,
help="Override the default network and provider. (see ``ape networks list`` for options)",
show_default=True,
show_choices=False,
)


def verbose_option(help=""):
return click.option(
"-v",
"--verbose",
is_flag=True,
default=False,
help=help,
)
22 changes: 3 additions & 19 deletions src/ape_console/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,13 @@

from ape import networks
from ape import project as default_project
from ape.options import network_option, verbose_option
from ape.version import version as ape_version # type: ignore


class NetworkChoice(click.Choice):
"""Wraps ``click.Choice`` to provide network choice defaults for the active project."""

def __init__(self, case_sensitive=True):
super().__init__(list(networks.network_choices), case_sensitive)

def get_metavar(self, param):
return "[ecosystem-name][:[network-name][:[provider-name]]]"


@click.command(short_help="Load the console", context_settings=dict(ignore_unknown_options=True))
@click.option("--verbose", is_flag=True, flag_value=True, default=False)
@click.option(
"--network",
type=NetworkChoice(case_sensitive=False),
default=networks.default_ecosystem.name,
help="Override the default network and provider. (see ``ape networks list`` for options)",
show_default=True,
show_choices=False,
)
@verbose_option(help="Display more information in the console")
@network_option
def cli(verbose, network):
"""
Opens a console for the local project."""
Expand Down
38 changes: 14 additions & 24 deletions src/ape_plugins/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@
notify("WARNING", "$GITHUB_ACCESS_TOKEN not set, skipping 2nd class plugins")


def yes_option(help=""):
return click.option(
"-y",
"--yes",
"skip_confirmation",
default=False,
is_flag=True,
help=help,
)


def is_plugin_installed(plugin: str) -> bool:
try:
__import__(plugin)
Expand Down Expand Up @@ -83,14 +94,7 @@ def _list(display_all):
@cli.command(short_help="Install an ape plugin")
@click.argument("plugin")
@click.option("-v", "--version", help="Specify version (Default is latest)")
@click.option(
"-y",
"--yes",
"skip_confirmation",
default=False,
is_flag=True,
help="Don't ask for confirmation to remove plugin",
)
@yes_option(help="Don't ask for confirmation to add the plugin")
def add(plugin, version, skip_confirmation):
if plugin.startswith("ape"):
raise Abort(f"Namespace 'ape' in '{plugin}' is not required")
Expand Down Expand Up @@ -120,14 +124,7 @@ def add(plugin, version, skip_confirmation):


@cli.command(short_help="Install all plugins in the local config file")
@click.option(
"-y",
"--yes",
"skip_confirmation",
default=False,
is_flag=True,
help="Don't ask for confirmation to remove plugin",
)
@yes_option("Don't ask for confirmation to install the plugins")
def install(skip_confirmation):
for plugin, version in config.get_config("plugins").items():
if not plugin.startswith("ape-"):
Expand All @@ -149,14 +146,7 @@ def install(skip_confirmation):

@cli.command(short_help="Uninstall an ape plugin")
@click.argument("plugin")
@click.option(
"-y",
"--yes",
"skip_confirmation",
default=False,
is_flag=True,
help="Don't ask for confirmation to remove plugin",
)
@yes_option("Don't ask for confirmation to remove the plugin")
def remove(plugin, skip_confirmation):
if plugin.startswith("ape"):
raise Abort(f"Namespace 'ape' in '{plugin}' is not required")
Expand Down
20 changes: 4 additions & 16 deletions src/ape_run/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import click

from ape import config, networks
from ape.options import network_option, verbose_option
from ape.utils import Abort, get_relative_path
from ape_console._cli import NetworkChoice, console
from ape_console._cli import console

# TODO: Migrate this to a CLI toolkit under ``ape``

Expand Down Expand Up @@ -54,28 +55,15 @@ def _run_script(script_path, interactive=False, verbose=False):

@click.command(short_help="Run scripts from the `scripts` folder")
@click.argument("scripts", nargs=-1)
@click.option(
"-v",
"--verbose",
is_flag=True,
default=False,
help="Display errors from scripts",
)
@verbose_option(help="Display errors from scripts")
@click.option(
"-i",
"--interactive",
is_flag=True,
default=False,
help="Drop into interactive console session after running",
)
@click.option(
"--network",
type=NetworkChoice(case_sensitive=False),
default=networks.default_ecosystem.name,
help="Override the default network and provider. (see `ape networks list` for options)",
show_default=True,
show_choices=False,
)
@network_option
def cli(scripts, verbose, interactive, network):
"""
NAME - Path or script name (from ``scripts/`` folder)
Expand Down

0 comments on commit 4ee59d5

Please sign in to comment.