Coverage for src/es_fieldusage/cli.py: 86%
21 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-03-26 17:48 -0600
« prev ^ index » next coverage.py v7.7.1, created at 2025-03-26 17:48 -0600
1"""Command-line interface"""
3# pylint: disable=R0913,R0914,R0917,W0613,W0622
4import typing as t
5import click
6from es_client.commands import show_all_options
7from es_client.defaults import OPTION_DEFAULTS
8from es_client.helpers import config as escl
9from es_client.helpers.logging import configure_logging
10from es_fieldusage.defaults import EPILOG
11from es_fieldusage.commands import file, show_indices, stdout
12from es_fieldusage.version import __version__
15@click.group(context_settings=escl.context_settings(), epilog=EPILOG)
16@escl.options_from_dict(OPTION_DEFAULTS)
17@click.version_option(__version__, '-v', '--version', prog_name="es-fieldusage")
18@click.pass_context
19def run(
20 ctx: click.Context,
21 config: t.Optional[str],
22 hosts: t.Optional[str],
23 cloud_id: t.Optional[str],
24 api_token: t.Optional[str],
25 id: t.Optional[str],
26 api_key: t.Optional[str],
27 username: t.Optional[str],
28 password: t.Optional[str],
29 bearer_auth: t.Optional[str],
30 opaque_id: t.Optional[str],
31 request_timeout: t.Optional[float],
32 http_compress: t.Optional[bool],
33 verify_certs: t.Optional[bool],
34 ca_certs: t.Optional[str],
35 client_cert: t.Optional[str],
36 client_key: t.Optional[str],
37 ssl_assert_hostname: t.Optional[bool],
38 ssl_assert_fingerprint: t.Optional[str],
39 ssl_version: t.Optional[str],
40 master_only: t.Optional[bool],
41 skip_version_test: t.Optional[bool],
42 loglevel: t.Optional[str],
43 logfile: t.Optional[str],
44 logformat: t.Optional[str],
45 blacklist: t.Optional[t.List[str]],
46) -> None:
47 """Elasticsearch Index Field Usage Reporting Tool
49 Sum all field query/request access for one or more indices using the Elastic
50 Field Usage API (https://ela.st/usagestats)
52 Generate a report at the command-line with the stdout command for all indices
53 in INDEX_PATTERN:
55 $ es-fieldusage stdout INDEX_PATTERN
57 To avoid errors, be sure to encapsulate wildcards in single-quotes:
59 $ es-fieldusage stdout 'index-*'
60 """
61 escl.get_config(ctx, quiet=False)
62 configure_logging(ctx)
63 escl.generate_configdict(ctx)
66# This is now included with es_client. It works, so ignore weird typing issues
67run.add_command(show_all_options) # type: ignore
69# Add the local subcommands
70run.add_command(show_indices)
71run.add_command(file)
72# run.add_command(index) # Not ready yet
73run.add_command(stdout)