def test_config_parsing(self): config = self.make_config(MockedJsonConfig, 'argparse') runner = CliRunner() app = Typer() app.add_typer(typer_config, name='config', context_settings=make_ctx_settings(config)) result = runner.invoke(app, ['config', '--global', 'key', 'value']) print(result.stdout) self.assertEqual(result.exit_code, 0) self.assertDictEqual(config, {'key': 'value'})
def create_cli(*args, **kwargs): cli_config = read_config() app = Typer() app.add_typer( ConfigureApp(cli_config).create_app(help="Manage CLI configuration."), name="configure") app.add_typer(ProfileApp(cli_config).create_app(help="Manage profiles."), name="profile") return app
def generate_app() -> Typer: app = Typer() app.add_typer(sparql.app) app.add_typer(context.app) config = load_config() typer_instances = [ plugin.typer() for plugin in config['plugins'].values() if hasattr(plugin, 'typer') ] typer_instances = filter(bool, typer_instances) consume(map( app.add_typer, typer_instances, ), ) return app
from keyring.backends import Windows try: import win32ctypes except ImportError: print("win32ctypes not found") print("try: \npip install pypiwin32") exit(1) set_keyring(Windows.WinVaultKeyring()) else: # automate platform detection pass cli = Typer() cli.add_typer(repo_cli, name="repository", help="work with repositories") cli.add_typer(authentication_cli, name="auth", help="login and logout") cli.add_typer(package_cli, name="package", help="Work with packages") cli.add_typer(version_cli, name="version", help="Work with versions") cli.add_typer(file_cli, name="file", help="Work with files") cli.add_typer(device_cli, name="device", help="Work with devices") self_cli = Typer(name="self") @self_cli.command(help="Display cli tool version") def version(): print(paxexpress_cli.__version__)
from typer import Typer from plumbum import local jeeves = Typer() switch = Typer() jeeves.add_typer(switch) @jeeves.command() def pypi(): """Switch Octadocs from PyPI.""" print(local.cmd.poetry['remove', 'octadocs'](retcode=None)) print(local.cmd.pip['uninstall', '-y', 'octadocs'](retcode=None)) print(local.cmd.pip['install', 'poetry']()) print(local.cmd.poetry['add', 'octadocs@latest']()) @jeeves.command(name='local') def to_local(): """Switch Octadocs to local directory.""" print(local.cmd.poetry['remove', 'octadocs'](retcode=None)) print(local.cmd.pip['install', 'poetry'](retcode=None)) print(local.cmd.poetry['install'].with_cwd(local.cwd / '../octadocs')()) if __name__ == '__main__': jeeves()
from os import path from typer import Context, Typer from kolombo import conf from kolombo.console import error from kolombo.dkim import dkim_cli from kolombo.domain import domain_cli from kolombo.init import init from kolombo.run import run_cli from kolombo.stop import stop_cli from kolombo.user import user_cli kolombo_cli = Typer(name="kolombo", add_completion=True) kolombo_cli.command("init")(init) kolombo_cli.add_typer(domain_cli, name="domain") kolombo_cli.add_typer(dkim_cli, name="dkim") kolombo_cli.add_typer(user_cli, name="user") kolombo_cli.add_typer(run_cli, name="run") kolombo_cli.add_typer(stop_cli, name="stop") @kolombo_cli.callback() def main(ctx: Context) -> None: if ctx.invoked_subcommand == "init": return if not path.exists("/etc/kolombo/kolombo.conf"): error("Kolombo is not initialized! Run [code]kolombo init[/] first") exit(1)
from igipy.hmp.__main__ import app as hmp_app from igipy.lmp.__main__ import app as lmp_app from igipy.mef.__main__ import app as mef_app from igipy.pic.__main__ import app as pic_app from igipy.qvm.__main__ import app as qvm_app from igipy.spr.__main__ import app as spr_app from igipy.tex.__main__ import app as tex_app from igipy.thm.__main__ import app as thm_app from igipy.tlm.__main__ import app as tlm_app from igipy.tmm.__main__ import app as tmm_app from igipy.wav.__main__ import app as wav_app from igipy.fst.__main__ import app as fst_app app = Typer(add_completion=False) app.add_typer(bit_app, name='bit') app.add_typer(cmd_app, name='cmd') app.add_typer(ctr_app, name='ctr') app.add_typer(fnt_app, name='fnt') app.add_typer(hmp_app, name='hmp') app.add_typer(lmp_app, name='lmp') app.add_typer(mef_app, name='mef') app.add_typer(pic_app, name='pic') app.add_typer(qvm_app, name='qvm') app.add_typer(spr_app, name='spr') app.add_typer(tex_app, name='tex') app.add_typer(thm_app, name='thm') app.add_typer(tlm_app, name='tlm') app.add_typer(tmm_app, name='tmm') app.add_typer(wav_app, name='wav') app.add_typer(fst_app, name='fst')
def load_commands(app: Typer, path: Path) -> None: for f in path.glob("*.py"): name = f.stem module = import_module(f"demo.commands.{name}") app.add_typer(getattr(module, "app"), name=name, help=module.__doc__)
def on_create_app(self, app: Typer, *args, **kwargs) -> Typer: app.add_typer(CredentialsApp( self.config).create_app(help="Manage CLI credentials."), name="credentials") return app
import logging from ipaddress import IPv4Network, IPv6Network from pathlib import Path from typing import Optional from typer import Option, Typer, echo from wgmgr import MainConfig from wgmgr.cli import common, p2p, peer logging.basicConfig(level=logging.INFO) app = Typer() app.add_typer(peer.app, name="peer", help="Manage peers.") app.add_typer(p2p.app, name="p2p", help="Manage point-to-point connections between peers.") @app.command() def new( config_path: Path = common.OPTION_CONFIG_PATH, ipv4_network: Optional[str] = common.OPTION_IPV4_NETWORK, ipv6_network: Optional[str] = common.OPTION_IPV6_NETWORK, default_port: Optional[int] = common.OPTION_PORT, force: bool = Option(False, "-f", "--force", help="Force overwriting of existing config file"), ): """
import arrow from typer import Typer, Option, Argument, Context from . import output, Task, YamlDB, load_user_configuration from .date_utils import parse_date import quest.trello as trello from importlib.metadata import version quest = Typer(help="A commandline quest log.") trello_app = Typer() debug_app = Typer() quest.add_typer(debug_app, name="debug", help="Debug commands.") quest.add_typer(trello_app, name="trello", help="Trello functionality.") config = load_user_configuration() @trello_app.command("boards", help="List Trello boards.") def trello_boards(): trello.get_boards(config.trello) @trello_app.command("cards", help="List Trello cards.") def trello_cards(): tdb = trello.tasks(config.trello) output.taskdb(tdb) @debug_app.command("cal", help="Display a calendar of this month.") def debug_print_calendar(period: str = Option("month")):
from typer import Typer from {{cookiecutter.package_name}}.modules.users import users_cli app = Typer() app.add_typer(users_cli.app, name="users") if __name__ == "__main__": app()