Utils for FlexMeasures CLI


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, datetime.datetime]

This function returns a time range [start,end] of the last-X period. See input parameters for more details.

  • 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


start:datetime, end:datetime


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:

def bar():
$ flexmeasures foo
DeprecationWarning: renamed to `foo bar`.
$ flexmeasures foo 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.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).