<commit_before># Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import argparse
import logging
import os
import sys
import warnings

from cliff import app
from cliff import commandmanager
from keystoneauth1 import adapter
from keystoneauth1 import exceptions
from keystoneauth1 import loading

from gnocchiclient import client
from gnocchiclient import noauth
from gnocchiclient.v1 import archive_policy_cli
from gnocchiclient.v1 import archive_policy_rule_cli as ap_rule_cli
from gnocchiclient.v1 import capabilities_cli
from gnocchiclient.v1 import metric_cli
from gnocchiclient.v1 import resource_cli
from gnocchiclient.version import __version__

LOG = logging.getLogger(__name__)

SHELL_COMMANDS = {
    "resource list": resource_cli.CliResourceList,
    "resource show": resource_cli.CliResourceShow,
    "resource history": resource_cli.CliResourceHistory,
    "resource search": resource_cli.CliResourceSearch,
    "resource create": resource_cli.CliResourceCreate,
    "resource update": resource_cli.CliResourceUpdate,
    "resource delete": resource_cli.CliResourceDelete,
    "archive-policy list": archive_policy_cli.CliArchivePolicyList,
    "archive-policy show": archive_policy_cli.CliArchivePolicyShow,
    "archive-policy create": archive_policy_cli.CliArchivePolicyCreate,
    "archive-policy delete": archive_policy_cli.CliArchivePolicyDelete,
    "archive-policy-rule list": ap_rule_cli.CliArchivePolicyRuleList,
    "archive-policy-rule show": ap_rule_cli.CliArchivePolicyRuleShow,
    "archive-policy-rule create": ap_rule_cli.CliArchivePolicyRuleCreate,
    "archive-policy-rule delete": ap_rule_cli.CliArchivePolicyRuleDelete,
    "metric list": metric_cli.CliMetricList,
    "metric show": metric_cli.CliMetricShow,
    "metric create": metric_cli.CliMetricCreate,
    "metric delete": metric_cli.CliMetricDelete,
    "measures get": metric_cli.CliMeasuresGet,
    "measures add": metric_cli.CliMeasuresAdd,
    "measures aggregation": metric_cli.CliMeasuresAggregation,
    "capabilities list": capabilities_cli.CliCapabilitiesList,
}


def _positive_non_zero_int(argument_value):
    if argument_value is None:
        return None
    try:
        value = int(argument_value)
    except ValueError:
        msg = "%s must be an integer" % argument_value
        raise argparse.ArgumentTypeError(msg)
    if value <= 0:
        msg = "%s must be greater than 0" % argument_value
        raise argparse.ArgumentTypeError(msg)
    return value


class GnocchiCommandManager(commandmanager.CommandManager):
    def load_commands(self, namespace):
        for name, command_class in SHELL_COMMANDS.items():
            self.add_command(name, command_class)


class GnocchiShell(app.App):
    def __init__(self, api_version):
        super(GnocchiShell, self).__init__(
            description='Gnocchi command line client',
            # FIXME(sileht): get version from pbr
            version=__version__,
            command_manager=GnocchiCommandManager(None),
            deferred_help=True,
            )

        self.api_version = api_version
        self._client = None

    def build_option_parser(self, description, version):
        """Return an argparse option parser for this application.

        Subclasses may override this method to extend
        the parser with more global options.

        :param description: full description of the application
        :paramtype description: str
        :param version: version number for the application<commit_msg>shell: move command definition to the class using it<commit_after># Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import argparse
import logging
import os
import sys
import warnings

from cliff import app
from cliff import commandmanager
from keystoneauth1 import adapter
from keystoneauth1 import exceptions
from keystoneauth1 import loading

from gnocchiclient import client
from gnocchiclient import noauth
from gnocchiclient.v1 import archive_policy_cli
from gnocchiclient.v1 import archive_policy_rule_cli as ap_rule_cli
from gnocchiclient.v1 import capabilities_cli
from gnocchiclient.v1 import metric_cli
from gnocchiclient.v1 import resource_cli
from gnocchiclient.version import __version__

LOG = logging.getLogger(__name__)


def _positive_non_zero_int(argument_value):
    if argument_value is None:
        return None
    try:
        value = int(argument_value)
    except ValueError:
        msg = "%s must be an integer" % argument_value
        raise argparse.ArgumentTypeError(msg)
    if value <= 0:
        msg = "%s must be greater than 0" % argument_value
        raise argparse.ArgumentTypeError(msg)
    return value


class GnocchiCommandManager(commandmanager.CommandManager):
    SHELL_COMMANDS = {
        "resource list": resource_cli.CliResourceList,
        "resource show": resource_cli.CliResourceShow,
        "resource history": resource_cli.CliResourceHistory,
        "resource search": resource_cli.CliResourceSearch,
        "resource create": resource_cli.CliResourceCreate,
        "resource update": resource_cli.CliResourceUpdate,
        "resource delete": resource_cli.CliResourceDelete,
        "archive-policy list": archive_policy_cli.CliArchivePolicyList,
        "archive-policy show": archive_policy_cli.CliArchivePolicyShow,
        "archive-policy create": archive_policy_cli.CliArchivePolicyCreate,
        "archive-policy delete": archive_policy_cli.CliArchivePolicyDelete,
        "archive-policy-rule list": ap_rule_cli.CliArchivePolicyRuleList,
        "archive-policy-rule show": ap_rule_cli.CliArchivePolicyRuleShow,
        "archive-policy-rule create": ap_rule_cli.CliArchivePolicyRuleCreate,
        "archive-policy-rule delete": ap_rule_cli.CliArchivePolicyRuleDelete,
        "metric list": metric_cli.CliMetricList,
        "metric show": metric_cli.CliMetricShow,
        "metric create": metric_cli.CliMetricCreate,
        "metric delete": metric_cli.CliMetricDelete,
        "measures get": metric_cli.CliMeasuresGet,
        "measures add": metric_cli.CliMeasuresAdd,
        "measures aggregation": metric_cli.CliMeasuresAggregation,
        "capabilities list": capabilities_cli.CliCapabilitiesList,
    }

    def load_commands(self, namespace):
        for name, command_class in self.SHELL_COMMANDS.items():
            self.add_command(name, command_class)


class GnocchiShell(app.App):
    def __init__(self, api_version):
        super(GnocchiShell, self).__init__(
            description='Gnocchi command line client',
            # FIXME(sileht): get version from pbr
            version=__version__,
            command_manager=GnocchiCommandManager(None),
            deferred_help=True,
            )

        self.api_version = api_version
        self._client = None

    def build_option_parser(self, description, version):
        """Return an argparse option parser for this application.

        Subclasses may override this method to extend
        the parser with more global options.

        :param description: full description of the application
        :paramtype description: str
        :param version: version number for the application
{'fraction_non_alphanumeric': 0.06690734055354994, 'fraction_numerical': 0.004332129963898917, 'mean_word_length': 3.798498845265589, 'pattern_counts': {'":': 46, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2093825', 'n_tokens_mistral': 2310, 'n_tokens_neox': 2233, 'n_words': 679}