Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/eessi/cli/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@

import typer

from eessi.cli.help import help_callback

app = typer.Typer()


@app.command()
def check():
def check(
help: bool = typer.Option(
None, # default value
"-h",
"--help",
help="Show this message and exit.",
callback=help_callback,
is_eager=True,
),
):
"""
Check CernVM-FS setup for accessing EESSI
"""
Expand Down
34 changes: 34 additions & 0 deletions src/eessi/cli/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# license (SPDX): GPL-2.0-only
#
# authors:
# - Kenneth Hoste (Ghent University)
# - Alex Domingo (Vrije Universiteit Brussel)

import click
import typer
from rich import print as rich_print
from typer import rich_utils

import eessi


def help_callback(ctx: click.Context, param: click.Parameter, value: bool):
"""
Show default help with rich and exit early.
"""
# ensures this doesn't run during completion or other early parsing phases
if not value or ctx.resilient_parsing:
return

# print default help with rich
rich_utils.rich_format_help(obj=ctx.command, ctx=ctx, markup_mode="rich")
ctx.exit()

def version_callback(value: bool):
"""
Show version and exit early.
"""
if value:
rich_print(f"[bold]eessi[/bold] version {eessi.__version__}")
raise typer.Exit()

14 changes: 13 additions & 1 deletion src/eessi/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@

import os
import sys

import typer

from eessi.cli.help import help_callback

app = typer.Typer()


@app.command()
def init():
def init(
help: bool = typer.Option(
None, # default value
"-h",
"--help",
help="Show this message and exit.",
callback=help_callback,
is_eager=True,
),
):
"""
Initialize shell environment for using EESSI
"""
Expand Down
33 changes: 22 additions & 11 deletions src/eessi/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
# license (SPDX): GPL-2.0-only
#
# authors: Kenneth Hoste (Ghent University)
# authors:
# - Kenneth Hoste (Ghent University)
# - Alex Domingo (Vrije Universiteit Brussel)

import typer

import eessi
from eessi.cli.check import app as check_app
from eessi.cli.help import help_callback, version_callback
from eessi.cli.init import app as init_app
from eessi.cli.shell import app as shell_app

app = typer.Typer(
help="User-friendly command line interface to EESSI - https://eessi.io",
context_settings={"help_option_names": ["-h", "--help"]},
# display help if no arguments given
no_args_is_help=True,
# we use custom help option to control its placement
add_help_option=False,
)

app.add_typer(check_app)
app.add_typer(init_app)
app.add_typer(shell_app)

def version_callback(value: bool):
if value:
print(f"eessi version {eessi.__version__}")
raise typer.Exit()


@app.callback()
def main(
help: bool = typer.Option(
None, # default value
"-h",
"--help",
help="Show this message and exit.",
callback=help_callback,
is_eager=True,
),
version: bool = typer.Option(
None, # default value
"-v", # short option
"--version", # long option
help="Show version of eessi CLI",
"-v",
"--version",
help="Show version of eessi CLI.",
callback=version_callback,
is_eager=True,
),
):
"""
Top level eessi command
"""
pass


Expand Down
17 changes: 15 additions & 2 deletions src/eessi/cli/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import subprocess
import sys
import tempfile
from typing import Annotated

import typer
from rich import print as rich_print
from typing import Annotated

from eessi.cli.help import help_callback

app = typer.Typer()

Expand All @@ -24,7 +27,17 @@ def report_error(msg, exit_code: int = 1):

@app.command()
def shell(
eessi_version: Annotated[str, typer.Option(help="EESSI version")] = '',
help: bool = typer.Option(
None, # default value
"-h",
"--help",
help="Show this message and exit.",
callback=help_callback,
is_eager=True,
),
eessi_version: Annotated[str, typer.Option(
help="EESSI version"
)] = '',
):
"""
Create subshell in which EESSI is available and initialised
Expand Down