opensearchcli 0.2.2__tar.gz → 0.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/PKG-INFO +1 -1
  2. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/pyproject.toml +1 -1
  3. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli/cli.py +8 -2
  4. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli/commands/cluster.py +6 -5
  5. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli/commands/cluster_settings.py +2 -2
  6. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli/commands/config.py +1 -1
  7. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli/commands/index.py +4 -4
  8. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli/commands/index_settings.py +3 -5
  9. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli/commands/raw.py +5 -2
  10. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli/commands/snapshot.py +2 -1
  11. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli.egg-info/PKG-INFO +1 -1
  12. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/README.md +0 -0
  13. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/setup.cfg +0 -0
  14. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli/__init__.py +0 -0
  15. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli/commands/__init__.py +0 -0
  16. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli/commands/commands.py +0 -0
  17. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli/commands/exceptions.py +0 -0
  18. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli/commands/helpers.py +0 -0
  19. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli.egg-info/SOURCES.txt +0 -0
  20. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli.egg-info/dependency_links.txt +0 -0
  21. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli.egg-info/entry_points.txt +0 -0
  22. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli.egg-info/requires.txt +0 -0
  23. {opensearchcli-0.2.2 → opensearchcli-0.2.4}/src/opensearchcli.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opensearchcli
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: A CLI tool for OpenSearch
5
5
  Requires-Python: <4,>=3.10
6
6
  Requires-Dist: typer>=0.20.0
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "opensearchcli"
3
3
  description = "A CLI tool for OpenSearch"
4
- version = "0.2.2"
4
+ version = "0.2.4"
5
5
  requires-python = " <4,>=3.10"
6
6
  dependencies = [
7
7
  "typer>=0.20.0",
@@ -91,17 +91,23 @@ def common(
91
91
  profile: Annotated[
92
92
  str, typer.Option(help="OpenSearch profile name", envvar="OPENSEARCH_PROFILE")
93
93
  ] = "default",
94
+ json_output: Annotated[bool, typer.Option("--json", help="Output results as JSON")]=False,
94
95
  ) -> None:
95
96
  """OpenSearch CLI - Manage your OpenSearch clusters."""
96
97
 
97
- _config = config.read_config(config_file=config_file)
98
- _profile = _config.find_profile_by_name(profile_name=profile)
98
+ try:
99
+ _config = config.read_config(config_file=config_file)
100
+ _profile = _config.find_profile_by_name(profile_name=profile)
101
+ except Exception as ex:
102
+ console.log(f"Error while reading config {config_file}:", ex, style="red")
103
+ exit(1)
99
104
 
100
105
  ctx.obj = OpenSearchCli(
101
106
  config=_config,
102
107
  profile=_profile,
103
108
  config_file_path=config_file,
104
109
  )
110
+ ctx.meta["json_output"] = json_output
105
111
 
106
112
 
107
113
  if __name__ == "__main__":
@@ -1,5 +1,6 @@
1
1
  from typing import Annotated
2
2
 
3
+ import json
3
4
  import typer
4
5
  from opensearchpy import RequestError
5
6
  from rich.console import Console
@@ -22,7 +23,7 @@ def info(
22
23
  ):
23
24
  """Retrieve cluster information."""
24
25
  info = ctx.obj.opensearch.info()
25
- console.print(info)
26
+ typer.echo(json.dumps(info, indent=2))
26
27
 
27
28
 
28
29
  @app.command()
@@ -31,7 +32,7 @@ def health(
31
32
  ):
32
33
  """Check the health of the OpenSearch cluster."""
33
34
  health = ctx.obj.opensearch.cluster.health()
34
- console.print(health)
35
+ typer.echo(json.dumps(health, indent=2))
35
36
 
36
37
 
37
38
  @app.command()
@@ -48,7 +49,7 @@ def allocation_explain(
48
49
  else:
49
50
  explanation = ctx.obj.opensearch.cluster.allocation_explain()
50
51
 
51
- console.print(explanation)
52
+ typer.echo(json.dumps(explanation, indent=2))
52
53
 
53
54
 
54
55
  @app.command()
@@ -57,11 +58,11 @@ def pending_tasks(
57
58
  ):
58
59
  """List pending tasks in the OpenSearch cluster."""
59
60
  tasks = ctx.obj.opensearch.cluster.pending_tasks()
60
- console.print(tasks)
61
+ typer.echo(json.dumps(tasks, indent=2))
61
62
 
62
63
 
63
64
  @app.command()
64
65
  def stats(ctx: typer.Context):
65
66
  """Retrieve cluster statistics."""
66
67
  stats = ctx.obj.opensearch.cluster.stats()
67
- console.print(stats)
68
+ typer.echo(json.dumps(stats, indent=2))
@@ -1,5 +1,5 @@
1
1
  from typing import Annotated
2
-
2
+ import json
3
3
  import typer
4
4
  from opensearchpy import RequestError
5
5
  from rich.console import Console
@@ -28,7 +28,7 @@ def get(
28
28
  else:
29
29
  _params[p] = "true"
30
30
  _settings = ctx.obj.opensearch.cluster.get_settings(params=_params)
31
- console.print(_settings)
31
+ typer.echo(json.dumps(_settings, indent=2))
32
32
 
33
33
 
34
34
  @app.command()
@@ -61,7 +61,7 @@ class Config:
61
61
  for profile in self.profiles:
62
62
  if profile.profile_name == profile_name:
63
63
  return profile
64
- return ConfigProfile(profile_name="", data={})
64
+ raise KeyError(f'Profile "{profile_name}" not found')
65
65
 
66
66
 
67
67
  def read_config(config_file: str) -> Config:
@@ -1,3 +1,4 @@
1
+ import json
1
2
  import typer
2
3
  from rich.console import Console
3
4
 
@@ -21,8 +22,7 @@ def list(
21
22
  ):
22
23
  """List indices matching the given pattern."""
23
24
  indices = ctx.obj.opensearch.indices.get(index=index_pattern)
24
- for index_name in indices.keys():
25
- console.print(index_name)
25
+ typer.echo(json.dumps(list(indices.keys()), indent=2))
26
26
 
27
27
 
28
28
  @app.command()
@@ -34,7 +34,7 @@ def get(
34
34
  ):
35
35
  """Retrieve information for a specific index."""
36
36
  index_info = ctx.obj.opensearch.indices.get(index=index)
37
- console.print(index_info)
37
+ typer.echo(json.dumps(index_info, indent=2))
38
38
 
39
39
 
40
40
  @app.command()
@@ -46,7 +46,7 @@ def ism(
46
46
  ):
47
47
  """Retrieve ISM information for a specific index."""
48
48
  index_info = ctx.obj.opensearch.plugins.index_management.explain_index(index=index)
49
- console.print(index_info)
49
+ typer.echo(json.dumps(index_info, indent=2))
50
50
 
51
51
 
52
52
  @app.command()
@@ -1,5 +1,5 @@
1
-
2
1
  import typer
2
+ import json
3
3
  from rich.console import Console
4
4
 
5
5
  from opensearchcli.commands.helpers import body_dict_from_flags, parse_params
@@ -21,11 +21,9 @@ def get(
21
21
  ),
22
22
  ):
23
23
  """Retrieve settings for a specific index."""
24
-
25
24
  _params = parse_params(params)
26
-
27
25
  settings = ctx.obj.opensearch.indices.get_settings(index=index, params=_params)
28
- console.print(settings)
26
+ typer.echo(json.dumps(settings, indent=2))
29
27
 
30
28
 
31
29
  @app.command()
@@ -39,4 +37,4 @@ def set(
39
37
  """Update settings for a specific index."""
40
38
  payload = body_dict_from_flags(settings)
41
39
  response = ctx.obj.opensearch.indices.put_settings(index=index, body=payload)
42
- console.print(response)
40
+ typer.echo(json.dumps(response, indent=2))
@@ -1,4 +1,4 @@
1
-
1
+ import json
2
2
  import typer
3
3
  from rich.console import Console
4
4
 
@@ -32,4 +32,7 @@ def do(
32
32
  body=payload if body else None,
33
33
  params=query_params if params else None,
34
34
  )
35
- console.print(response)
35
+ if ctx.meta.get("json_output"):
36
+ typer.echo(json.dumps(response, indent=2))
37
+ else:
38
+ console.print(response)
@@ -1,4 +1,5 @@
1
1
  import typer
2
+ import json
2
3
  from rich.console import Console
3
4
 
4
5
  app = typer.Typer(
@@ -11,4 +12,4 @@ console = Console()
11
12
  def repository(ctx: typer.Context):
12
13
  """Get snapshot information."""
13
14
  snapshot_info = ctx.obj.opensearch.snapshot.get_repository()
14
- console.print(snapshot_info)
15
+ typer.echo(json.dumps(snapshot_info, indent=2))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opensearchcli
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: A CLI tool for OpenSearch
5
5
  Requires-Python: <4,>=3.10
6
6
  Requires-Dist: typer>=0.20.0
File without changes
File without changes