flexmeasures.cli.utils
Utils for FlexMeasures CLI
Functions
- flexmeasures.cli.utils.get_timerange_from_flag(last_hour: bool = False, last_day: bool = False, last_7_days: bool = False, last_month: bool = False, last_year: bool = False, timezone: ~pytz.tzinfo.BaseTzInfo = <DstTzInfo 'Asia/Seoul' LMT+8:28:00 STD>) tuple[datetime, datetime]
This function returns a time range [start,end] of the last-X period. See input parameters for more details.
- Parameters:
last_hour (bool) – flag to get the time range of the last finished hour.
last_day (bool) – flag to get the time range for yesterday.
last_7_days (bool) – flag to get the time range of the previous 7 days.
last_month (bool) – flag to get the time range of last calendar month
last_year (bool) – flag to get the last completed calendar year
timezone – timezone object to represent
- Returns:
start:datetime, end:datetime
- flexmeasures.cli.utils.validate_unique(ctx, param, value)
Callback function to ensure multiple values are unique.
Classes
- class flexmeasures.cli.utils.DeprecatedDefaultGroup(*args, **kwargs)
Invokes a default subcommand, and shows a deprecation message.
Also adds the invoked_default boolean attribute to the context. A group callback can use this information to figure out if it’s being executed directly (invoking the default subcommand) or because the execution flow passes onwards to a subcommand. By default it’s None, but it can be the name of the default subcommand to execute.
import click from flexmeasures.cli.utils import DeprecatedDefaultGroup @click.group(cls=DeprecatedDefaultGroup, default="bar", deprecation_message="renamed to `foo bar`.") def foo(ctx): if ctx.invoked_default: click.echo("foo") @foo.command() def bar(): click.echo("bar")
$ flexmeasures foo DeprecationWarning: renamed to `foo bar`. foo bar $ flexmeasures foo bar bar
- __init__(*args, **kwargs)
- get_command(ctx, cmd_name)
Given a context and a command name, this returns a
Command
object if it exists or returns None.
- class flexmeasures.cli.utils.DeprecatedOption(*args, **kwargs)
A custom option that can be used to mark an option as deprecated.
References
Copied from https://stackoverflow.com/a/50402799/13775459
- __init__(*args, **kwargs)
- class flexmeasures.cli.utils.DeprecatedOptionsCommand(name: str | None, context_settings: MutableMapping[str, Any] | None = None, callback: Callable[[...], Any] | None = None, params: List[Parameter] | None = None, help: str | None = None, epilog: str | None = None, short_help: str | None = None, options_metavar: str | None = '[OPTIONS]', add_help_option: bool = True, no_args_is_help: bool = False, hidden: bool = False, deprecated: bool = False)
A custom command that can be used to mark options as deprecated.
References
Adapted from https://stackoverflow.com/a/50402799/13775459
- make_parser(ctx)
Hook ‘make_parser’ and during processing check the name used to invoke the option to see if it is preferred
- class flexmeasures.cli.utils.MsgStyle
Stores the text styles for the different events
Styles options are the attributes of the click.style which can be found [here](https://click.palletsprojects.com/en/8.1.x/api/#click.style).