opensearchcli 0.2.3__tar.gz → 0.2.5__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.3 → opensearchcli-0.2.5}/PKG-INFO +1 -1
  2. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/pyproject.toml +1 -1
  3. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli/cli.py +6 -0
  4. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli/commands/cluster.py +6 -5
  5. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli/commands/cluster_settings.py +2 -2
  6. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli/commands/index.py +4 -4
  7. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli/commands/index_settings.py +3 -5
  8. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli/commands/raw.py +5 -2
  9. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli/commands/snapshot.py +2 -1
  10. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli.egg-info/PKG-INFO +1 -1
  11. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/README.md +0 -0
  12. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/setup.cfg +0 -0
  13. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli/__init__.py +0 -0
  14. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli/commands/__init__.py +0 -0
  15. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli/commands/commands.py +0 -0
  16. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli/commands/config.py +0 -0
  17. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli/commands/exceptions.py +0 -0
  18. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli/commands/helpers.py +0 -0
  19. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli.egg-info/SOURCES.txt +0 -0
  20. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli.egg-info/dependency_links.txt +0 -0
  21. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli.egg-info/entry_points.txt +0 -0
  22. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/src/opensearchcli.egg-info/requires.txt +0 -0
  23. {opensearchcli-0.2.3 → opensearchcli-0.2.5}/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.3
3
+ Version: 0.2.5
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.3"
4
+ version = "0.2.5"
5
5
  requires-python = " <4,>=3.10"
6
6
  dependencies = [
7
7
  "typer>=0.20.0",
@@ -58,11 +58,13 @@ class OpenSearchCli:
58
58
  config: config.Config,
59
59
  profile: config.ConfigProfile,
60
60
  config_file_path: str,
61
+ json_output: bool = False,
61
62
  ) -> None:
62
63
  self._opensearch: OpenSearch | None = None
63
64
  self.config = config
64
65
  self.profile = profile
65
66
  self.config_file_path = config_file_path
67
+ self.json_output = json_output
66
68
 
67
69
  @property
68
70
  def opensearch(self) -> OpenSearch:
@@ -78,6 +80,7 @@ class OpenSearchCli:
78
80
  use_ssl=True,
79
81
  verify_certs=False,
80
82
  ssl_show_warn=False,
83
+ headers={"Accept": "application/json"} if self.json_output else {},
81
84
  )
82
85
  return self._opensearch
83
86
 
@@ -91,6 +94,7 @@ def common(
91
94
  profile: Annotated[
92
95
  str, typer.Option(help="OpenSearch profile name", envvar="OPENSEARCH_PROFILE")
93
96
  ] = "default",
97
+ json_output: Annotated[bool, typer.Option("--json", help="Output results as JSON")]=False,
94
98
  ) -> None:
95
99
  """OpenSearch CLI - Manage your OpenSearch clusters."""
96
100
 
@@ -105,7 +109,9 @@ def common(
105
109
  config=_config,
106
110
  profile=_profile,
107
111
  config_file_path=config_file,
112
+ json_output=json_output,
108
113
  )
114
+ ctx.meta["json_output"] = json_output
109
115
 
110
116
 
111
117
  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()
@@ -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.3
3
+ Version: 0.2.5
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