<commit_before>#!/usr/bin/env python

from os.path import exists
from os.path import join
import sys

from paasta_tools.paasta_cli.fsm.questions import _yamlize
from paasta_tools.paasta_cli.fsm.questions import get_clusternames_from_deploy_stanza
from paasta_tools.paasta_cli.fsm.questions import get_deploy_stanza
from paasta_tools.paasta_cli.fsm.questions import get_marathon_stanza
from paasta_tools.paasta_cli.fsm.questions import get_monitoring_stanza
from paasta_tools.paasta_cli.fsm.questions import get_service_stanza
from paasta_tools.paasta_cli.fsm.questions import get_smartstack_stanza
from paasta_tools.paasta_cli.fsm.questions import get_srvname
from paasta_tools.paasta_cli.fsm.service import Service
from paasta_tools.paasta_cli.utils import list_teams
from paasta_tools.paasta_cli.utils import lazy_choices_completer
from paasta_tools.utils import PaastaColors


def add_subparser(subparsers):
    fsm_parser = subparsers.add_parser(
        "fsm",
        description="Configure A New PaaSTA Service -- http://y/paasta-deploy For Details",
        help="Start A New Service From Scratch",
    )
    fsm_parser.add_argument(
        "-y", "--yelpsoa-config-root",
        dest="yelpsoa_config_root",
        default=None,
        required=True,
        help="Path to root of yelpsoa-configs checkout (required)")
    fsm_parser.add_argument(
        "-s", "--service-name",
        dest="srvname",
        default=None,
        help="Name of service being configured (--auto not available)")
    fsm_parser.add_argument(
        "--description",
        dest="description",
        default=None,
        help="One line description of the service. If AUTO will have placeholder text")
    fsm_parser.add_argument(
        "--external-link",
        dest="external_link",
        default=None,
        help="Link to a CEP or SCF of the service. If AUTO will have placeholder text")
    fsm_parser.add_argument(
        "-a",
        "--auto",
        dest="auto",
        default=False,
        action="store_true",
        help="Automatically calculate and use sane defaults. Exit violently if "
             "any values cannot be automatically calculated.",
    )
    fsm_parser.add_argument(
        "-p", "--port",
        dest="port",
        default=None,
        help="Smartstack proxy port used by service.")
    fsm_parser.add_argument(
        "-t", "--team",
        dest="team",
        default=None,
        help="Team responsible for the service. Used by various notification "
             "systems. (--auto not available)",
    ).completer = lazy_choices_completer(list_teams())
    fsm_parser.set_defaults(command=paasta_fsm)


def validate_args(args):
    """Does sys.exit() if an invalid combination of args is specified.
    Otherwise returns None (implicitly)."""
    if not exists(args.yelpsoa_config_root):
        sys.exit(
            "I'd Really Rather You Didn't Use A Non-Existent --yelpsoa-config-root"
            "Like %s" % args.yelpsoa_config_root<commit_msg>This is supposed to be a function so it can be handled lazily.<commit_after>#!/usr/bin/env python

from os.path import exists
from os.path import join
import sys

from paasta_tools.paasta_cli.fsm.questions import _yamlize
from paasta_tools.paasta_cli.fsm.questions import get_clusternames_from_deploy_stanza
from paasta_tools.paasta_cli.fsm.questions import get_deploy_stanza
from paasta_tools.paasta_cli.fsm.questions import get_marathon_stanza
from paasta_tools.paasta_cli.fsm.questions import get_monitoring_stanza
from paasta_tools.paasta_cli.fsm.questions import get_service_stanza
from paasta_tools.paasta_cli.fsm.questions import get_smartstack_stanza
from paasta_tools.paasta_cli.fsm.questions import get_srvname
from paasta_tools.paasta_cli.fsm.service import Service
from paasta_tools.paasta_cli.utils import list_teams
from paasta_tools.paasta_cli.utils import lazy_choices_completer
from paasta_tools.utils import PaastaColors


def add_subparser(subparsers):
    fsm_parser = subparsers.add_parser(
        "fsm",
        description="Configure A New PaaSTA Service -- http://y/paasta-deploy For Details",
        help="Start A New Service From Scratch",
    )
    fsm_parser.add_argument(
        "-y", "--yelpsoa-config-root",
        dest="yelpsoa_config_root",
        default=None,
        required=True,
        help="Path to root of yelpsoa-configs checkout (required)")
    fsm_parser.add_argument(
        "-s", "--service-name",
        dest="srvname",
        default=None,
        help="Name of service being configured (--auto not available)")
    fsm_parser.add_argument(
        "--description",
        dest="description",
        default=None,
        help="One line description of the service. If AUTO will have placeholder text")
    fsm_parser.add_argument(
        "--external-link",
        dest="external_link",
        default=None,
        help="Link to a CEP or SCF of the service. If AUTO will have placeholder text")
    fsm_parser.add_argument(
        "-a",
        "--auto",
        dest="auto",
        default=False,
        action="store_true",
        help="Automatically calculate and use sane defaults. Exit violently if "
             "any values cannot be automatically calculated.",
    )
    fsm_parser.add_argument(
        "-p", "--port",
        dest="port",
        default=None,
        help="Smartstack proxy port used by service.")
    fsm_parser.add_argument(
        "-t", "--team",
        dest="team",
        default=None,
        help="Team responsible for the service. Used by various notification "
             "systems. (--auto not available)",
    ).completer = lazy_choices_completer(list_teams)
    fsm_parser.set_defaults(command=paasta_fsm)


def validate_args(args):
    """Does sys.exit() if an invalid combination of args is specified.
    Otherwise returns None (implicitly)."""
    if not exists(args.yelpsoa_config_root):
        sys.exit(
            "I'd Really Rather You Didn't Use A Non-Existent --yelpsoa-config-root"
            "Like %s" % args.yelpsoa_config_root
{'fraction_non_alphanumeric': 0.09420887642303251, 'fraction_numerical': 0.0, 'mean_word_length': 3.129427792915531, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4133962', 'n_tokens_mistral': 1887, 'n_tokens_neox': 1824, 'n_words': 463}