Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hhstore committed Dec 28, 2023
1 parent 3e5aa07 commit 992619f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 deletions.
33 changes: 29 additions & 4 deletions packages/mod-cli/src/mod_cli/commands/add.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,36 @@
from typing import Optional

import typer
from typing_extensions import Annotated

cmd_add = typer.Typer(help="Add a package")
cmd_add = typer.Typer(
help="Add a package", no_args_is_help=True, invoke_without_command=True
)


@cmd_add.command()
def add():
@cmd_add.callback()
def cb(
package: Annotated[
str,
typer.Argument(
metavar="PACKAGE",
help="Add a package to dependencies",
),
],
dev: Annotated[
Optional[bool],
typer.Option(
"--dev",
"-d",
help="Add a development package to dependencies",
),
] = False,
):
"""
Add
"""
typer.echo("Add a package")

if dev:
typer.echo(f"Add {package} to development dependencies")
else:
typer.echo(f"Add {package} to dependencies")
43 changes: 40 additions & 3 deletions packages/mod-cli/src/mod_cli/commands/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,46 @@ def version_callback(value: bool):


# todo x: add global --options
@app.callback(short_help="-h")
@app.callback(invoke_without_command=True)
def main(
h: Annotated[
Optional[bool],
typer.Option(
"--help",
"-h",
help="Show this help message",
),
] = False,
version: Annotated[
Optional[bool],
typer.Option(
"--version", "-v", callback=version_callback, help="Show the version"
"--version",
"-v",
# callback=version_callback,
help="Show the version",
),
] = None,
] = False,
):
"""
Awesome Mojo Package Manager
"""
from mod_cli.core.cache import PackageCacheHelper

ph = PackageCacheHelper()
ph.init()

# -v option
if version:
print(f"🔥 Mod: {__version__}")
raise typer.Exit()

# -h option
if h:
import subprocess

subprocess.run(["mod"])
print("🔥 Mod: %s" % __version__)
raise typer.Exit()


class NewType(str, Enum):
Expand Down Expand Up @@ -153,3 +181,12 @@ def doctor():
)
def remove_dep():
typer.echo("Remove dependencies")


@app.command(
"add2",
help="Add a package",
rich_help_panel=AppPanelType.development,
)
def add_package():
typer.echo("Add a package")
1 change: 1 addition & 0 deletions packages/mod-cli/src/mod_cli/core/cache/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .cache import PackageCacheHelper

0 comments on commit 992619f

Please sign in to comment.