def args_from_strategy_shortcut()

in cstar/cstarcli.py [0:0]


def args_from_strategy_shortcut(args):
    """Returns args
    Takes command options and a strategy shortcut in:
    {--one, --one-per-dc, --topology, --topology-per-dc, --all}
    Returns options (args) with --strategy and --dc-parallel set accordingly
    """

    strategy_shortcuts = {
                            "--one": int(args.strategy_one),
                            "--one-per-dc": int(args.strategy_one_per_dc),
                            "--topology": int(args.strategy_topology),
                            "--topology-per-dc": int(args.strategy_topology_per_dc),
                            "--all": int(args.strategy_all)}

    total_shortcuts_used = sum(strategy_shortcuts.values())

    if total_shortcuts_used > 1:
        error("Exactly one of {} must be used".format(', '.join(strategy_shortcuts.keys())), print_traceback=False)

    if total_shortcuts_used == 1:
        if args.strategy is not None:
            error("--strategy option is not compatible with {} options that "
                  "defines the stratgy already".format(', '.join(strategy_shortcuts.keys())), print_traceback=False)
        elif args.dc_parallel is not None:
            error("--dc-parallel option is not compatible with {} options "
                  "that defines the stratgy already".format(', '.join(strategy_shortcuts.keys())), print_traceback=False)
        else:
            # Identify the strategy_?* option used
            for (k, v) in strategy_shortcuts.items():
                if v == 1:
                    # Set corresponding option
                    if k == "--one":
                        args.strategy = "one"
                        args.dc_parallel = False
                    elif k == "--one-per-dc":
                        args.strategy = "one"
                        args.dc_parallel = True
                    elif k == "--topology":
                        args.strategy = "topology"
                        args.dc_parallel = False
                    elif k == "--topology-per-dc":
                        args.strategy = "topology"
                        args.dc_parallel = True
                    elif k == "--all":
                        args.strategy = "all"
                        args.dc_parallel = True
                    else:
                        error("Unknown shortcut option: {}".format(k))

    return args