cli
pacsanini.cli
special
#
Expose the main CLI entry point command.
base
#
Expose custom click classes to enable prettier help messages
from the command line.
GroupCommand
#
The GroupCommand class knows how to handle GroupOption
instances so that they may be printed together.
format_options(self, ctx, formatter)
#
Write all the options in the formatter if they exist.
Source code in pacsanini/cli/base.py
def format_options(self, ctx, formatter):
"""Write all the options in the formatter if they exist."""
opts = OrderedDict()
for param in self.get_params(ctx):
retval = param.get_help_record(ctx)
if retval is not None:
if hasattr(param, "help_group") and param.help_group:
opts.setdefault(str(param.help_group), []).append(retval)
else:
opts.setdefault("Other Options", []).append(retval)
for name, opts_group in opts.items():
with formatter.section(name):
formatter.write_dl(opts_group)
GroupOption
#
GroupOption enables users to group command options
by adding the "help_group" kwarg to the @click.option decorator. Such options should also have cls=GroupOption
config_option(function)
#
Return the configuration option that is used in most commands.
Source code in pacsanini/cli/base.py
def config_option(function: Callable) -> Callable:
"""Return the configuration option that is used in most commands."""
def validate_path(ctx, param, value):
if not value:
value = default_config_path()
if not value:
msg = (
"No configuration file provided and no default"
" configuration file in the following locations:\n"
f" (1) Using the {PACSANINI_CONF_ENVVAR} env var,\n"
f" (2) Using a {DEFAULT_CONFIG_NAME} file in your current dir,\n"
f" (3) Using the {DEFAULT_CONFIG_NAME} file in your homedir."
)
raise BadParameter(msg, ctx=ctx, param=param)
if not os.path.exists(value):
raise BadParameter(f"'{value}' does not exist")
ext = value.rsplit(".", 1)[-1].lower()
load_func = (
PacsaniniConfig.from_json if ext == "json" else PacsaniniConfig.from_yaml
)
pacsanini_config = load_func(value)
return pacsanini_config
function = option(
"-f",
"--config",
required=False,
type=UNPROCESSED,
callback=validate_path,
help=(
"The pacsanini configuration file to use. The order of evaluation is:"
" (1) the value you explicitely provided,\n"
f" (2) the value provided by the {PACSANINI_CONF_ENVVAR} env var,\n"
f" (3) a file named {DEFAULT_CONFIG_NAME} in your current directory,\n"
f" (4) a file named {DEFAULT_CONFIG_NAME} in your home directory.\n"
),
)(function)
return function
commands
#
The commands module exposes the different command lines methods
that can be used with pacsanini.
print_version(ctx, param, value)
#
Print the program's version.
Source code in pacsanini/cli/commands.py
def print_version(ctx, param, value): # pylint: disable=unused-argument
"""Print the program's version."""
if not value or ctx.resilient_parsing:
return
echo(f"Version {__version__}")
ctx.exit()
config
#
Expose configuration functionalities to the command line.
dashboard
#
Expose the commands needed to spawn the dashboard server.
db
#
Database utility commands that are used from the command line.
net
#
Use pacsanini's network functionalities from the command line.
parse
#
The parse module exposes DICOM tag parsing functionalities to the
command line.
pipeline
#
Expose the complete collection pipeline from the CLI.