nextmv 0.40.0__py3-none-any.whl → 1.0.0__py3-none-any.whl

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 (163) hide show
  1. nextmv/__about__.py +1 -1
  2. nextmv/__entrypoint__.py +1 -2
  3. nextmv/__init__.py +2 -4
  4. nextmv/cli/CONTRIBUTING.md +583 -0
  5. nextmv/cli/cloud/__init__.py +49 -0
  6. nextmv/cli/cloud/acceptance/__init__.py +27 -0
  7. nextmv/cli/cloud/acceptance/create.py +391 -0
  8. nextmv/cli/cloud/acceptance/delete.py +64 -0
  9. nextmv/cli/cloud/acceptance/get.py +103 -0
  10. nextmv/cli/cloud/acceptance/list.py +62 -0
  11. nextmv/cli/cloud/acceptance/update.py +95 -0
  12. nextmv/cli/cloud/account/__init__.py +28 -0
  13. nextmv/cli/cloud/account/create.py +83 -0
  14. nextmv/cli/cloud/account/delete.py +59 -0
  15. nextmv/cli/cloud/account/get.py +66 -0
  16. nextmv/cli/cloud/account/update.py +70 -0
  17. nextmv/cli/cloud/app/__init__.py +35 -0
  18. nextmv/cli/cloud/app/create.py +140 -0
  19. nextmv/cli/cloud/app/delete.py +57 -0
  20. nextmv/cli/cloud/app/exists.py +44 -0
  21. nextmv/cli/cloud/app/get.py +66 -0
  22. nextmv/cli/cloud/app/list.py +61 -0
  23. nextmv/cli/cloud/app/push.py +432 -0
  24. nextmv/cli/cloud/app/update.py +124 -0
  25. nextmv/cli/cloud/batch/__init__.py +29 -0
  26. nextmv/cli/cloud/batch/create.py +452 -0
  27. nextmv/cli/cloud/batch/delete.py +64 -0
  28. nextmv/cli/cloud/batch/get.py +104 -0
  29. nextmv/cli/cloud/batch/list.py +63 -0
  30. nextmv/cli/cloud/batch/metadata.py +66 -0
  31. nextmv/cli/cloud/batch/update.py +95 -0
  32. nextmv/cli/cloud/data/__init__.py +26 -0
  33. nextmv/cli/cloud/data/upload.py +162 -0
  34. nextmv/cli/cloud/ensemble/__init__.py +33 -0
  35. nextmv/cli/cloud/ensemble/create.py +413 -0
  36. nextmv/cli/cloud/ensemble/delete.py +63 -0
  37. nextmv/cli/cloud/ensemble/get.py +65 -0
  38. nextmv/cli/cloud/ensemble/list.py +63 -0
  39. nextmv/cli/cloud/ensemble/update.py +103 -0
  40. nextmv/cli/cloud/input_set/__init__.py +32 -0
  41. nextmv/cli/cloud/input_set/create.py +168 -0
  42. nextmv/cli/cloud/input_set/delete.py +64 -0
  43. nextmv/cli/cloud/input_set/get.py +63 -0
  44. nextmv/cli/cloud/input_set/list.py +63 -0
  45. nextmv/cli/cloud/input_set/update.py +123 -0
  46. nextmv/cli/cloud/instance/__init__.py +35 -0
  47. nextmv/cli/cloud/instance/create.py +289 -0
  48. nextmv/cli/cloud/instance/delete.py +61 -0
  49. nextmv/cli/cloud/instance/exists.py +39 -0
  50. nextmv/cli/cloud/instance/get.py +62 -0
  51. nextmv/cli/cloud/instance/list.py +60 -0
  52. nextmv/cli/cloud/instance/update.py +216 -0
  53. nextmv/cli/cloud/managed_input/__init__.py +31 -0
  54. nextmv/cli/cloud/managed_input/create.py +144 -0
  55. nextmv/cli/cloud/managed_input/delete.py +64 -0
  56. nextmv/cli/cloud/managed_input/get.py +63 -0
  57. nextmv/cli/cloud/managed_input/list.py +60 -0
  58. nextmv/cli/cloud/managed_input/update.py +97 -0
  59. nextmv/cli/cloud/run/__init__.py +37 -0
  60. nextmv/cli/cloud/run/cancel.py +37 -0
  61. nextmv/cli/cloud/run/create.py +524 -0
  62. nextmv/cli/cloud/run/get.py +199 -0
  63. nextmv/cli/cloud/run/input.py +86 -0
  64. nextmv/cli/cloud/run/list.py +80 -0
  65. nextmv/cli/cloud/run/logs.py +166 -0
  66. nextmv/cli/cloud/run/metadata.py +67 -0
  67. nextmv/cli/cloud/run/track.py +500 -0
  68. nextmv/cli/cloud/scenario/__init__.py +29 -0
  69. nextmv/cli/cloud/scenario/create.py +451 -0
  70. nextmv/cli/cloud/scenario/delete.py +61 -0
  71. nextmv/cli/cloud/scenario/get.py +102 -0
  72. nextmv/cli/cloud/scenario/list.py +63 -0
  73. nextmv/cli/cloud/scenario/metadata.py +67 -0
  74. nextmv/cli/cloud/scenario/update.py +93 -0
  75. nextmv/cli/cloud/secrets/__init__.py +33 -0
  76. nextmv/cli/cloud/secrets/create.py +206 -0
  77. nextmv/cli/cloud/secrets/delete.py +63 -0
  78. nextmv/cli/cloud/secrets/get.py +66 -0
  79. nextmv/cli/cloud/secrets/list.py +60 -0
  80. nextmv/cli/cloud/secrets/update.py +144 -0
  81. nextmv/cli/cloud/shadow/__init__.py +33 -0
  82. nextmv/cli/cloud/shadow/create.py +184 -0
  83. nextmv/cli/cloud/shadow/delete.py +64 -0
  84. nextmv/cli/cloud/shadow/get.py +61 -0
  85. nextmv/cli/cloud/shadow/list.py +63 -0
  86. nextmv/cli/cloud/shadow/metadata.py +66 -0
  87. nextmv/cli/cloud/shadow/start.py +43 -0
  88. nextmv/cli/cloud/shadow/stop.py +53 -0
  89. nextmv/cli/cloud/shadow/update.py +96 -0
  90. nextmv/cli/cloud/switchback/__init__.py +33 -0
  91. nextmv/cli/cloud/switchback/create.py +151 -0
  92. nextmv/cli/cloud/switchback/delete.py +64 -0
  93. nextmv/cli/cloud/switchback/get.py +62 -0
  94. nextmv/cli/cloud/switchback/list.py +63 -0
  95. nextmv/cli/cloud/switchback/metadata.py +68 -0
  96. nextmv/cli/cloud/switchback/start.py +43 -0
  97. nextmv/cli/cloud/switchback/stop.py +53 -0
  98. nextmv/cli/cloud/switchback/update.py +96 -0
  99. nextmv/cli/cloud/upload/__init__.py +22 -0
  100. nextmv/cli/cloud/upload/create.py +39 -0
  101. nextmv/cli/cloud/version/__init__.py +33 -0
  102. nextmv/cli/cloud/version/create.py +96 -0
  103. nextmv/cli/cloud/version/delete.py +61 -0
  104. nextmv/cli/cloud/version/exists.py +39 -0
  105. nextmv/cli/cloud/version/get.py +62 -0
  106. nextmv/cli/cloud/version/list.py +60 -0
  107. nextmv/cli/cloud/version/update.py +92 -0
  108. nextmv/cli/community/__init__.py +24 -0
  109. nextmv/cli/community/clone.py +20 -204
  110. nextmv/cli/community/list.py +61 -126
  111. nextmv/cli/configuration/__init__.py +23 -0
  112. nextmv/cli/configuration/config.py +103 -6
  113. nextmv/cli/configuration/create.py +17 -18
  114. nextmv/cli/configuration/delete.py +25 -13
  115. nextmv/cli/configuration/list.py +4 -4
  116. nextmv/cli/confirm.py +34 -0
  117. nextmv/cli/main.py +68 -36
  118. nextmv/cli/message.py +170 -0
  119. nextmv/cli/options.py +196 -0
  120. nextmv/cli/version.py +20 -1
  121. nextmv/cloud/__init__.py +17 -38
  122. nextmv/cloud/acceptance_test.py +20 -83
  123. nextmv/cloud/account.py +269 -30
  124. nextmv/cloud/application/__init__.py +898 -0
  125. nextmv/cloud/application/_acceptance.py +424 -0
  126. nextmv/cloud/application/_batch_scenario.py +845 -0
  127. nextmv/cloud/application/_ensemble.py +251 -0
  128. nextmv/cloud/application/_input_set.py +263 -0
  129. nextmv/cloud/application/_instance.py +289 -0
  130. nextmv/cloud/application/_managed_input.py +227 -0
  131. nextmv/cloud/application/_run.py +1393 -0
  132. nextmv/cloud/application/_secrets.py +294 -0
  133. nextmv/cloud/application/_shadow.py +320 -0
  134. nextmv/cloud/application/_switchback.py +332 -0
  135. nextmv/cloud/application/_utils.py +54 -0
  136. nextmv/cloud/application/_version.py +304 -0
  137. nextmv/cloud/batch_experiment.py +6 -2
  138. nextmv/cloud/community.py +446 -0
  139. nextmv/cloud/instance.py +11 -1
  140. nextmv/cloud/integration.py +8 -5
  141. nextmv/cloud/package.py +50 -9
  142. nextmv/cloud/shadow.py +254 -0
  143. nextmv/cloud/switchback.py +228 -0
  144. nextmv/deprecated.py +5 -3
  145. nextmv/input.py +20 -88
  146. nextmv/local/application.py +3 -15
  147. nextmv/local/runner.py +1 -1
  148. nextmv/model.py +50 -11
  149. nextmv/options.py +11 -256
  150. nextmv/output.py +0 -62
  151. nextmv/polling.py +54 -16
  152. nextmv/run.py +84 -37
  153. nextmv/status.py +1 -51
  154. {nextmv-0.40.0.dist-info → nextmv-1.0.0.dist-info}/METADATA +37 -11
  155. nextmv-1.0.0.dist-info/RECORD +185 -0
  156. nextmv-1.0.0.dist-info/entry_points.txt +2 -0
  157. nextmv/cli/community/community.py +0 -24
  158. nextmv/cli/configuration/configuration.py +0 -23
  159. nextmv/cli/error.py +0 -22
  160. nextmv/cloud/application.py +0 -4204
  161. nextmv-0.40.0.dist-info/RECORD +0 -66
  162. {nextmv-0.40.0.dist-info → nextmv-1.0.0.dist-info}/WHEEL +0 -0
  163. {nextmv-0.40.0.dist-info → nextmv-1.0.0.dist-info}/licenses/LICENSE +0 -0
@@ -2,19 +2,14 @@
2
2
  This module defines the community clone command for the Nextmv CLI.
3
3
  """
4
4
 
5
- import os
6
- import shutil
7
- import tarfile
8
- import tempfile
9
- from collections.abc import Callable
10
5
  from typing import Annotated
11
6
 
12
- import rich
13
7
  import typer
14
8
 
15
- from nextmv.cli.community.list import download_file, download_manifest, find_app, versions_table
16
- from nextmv.cli.error import error
9
+ from nextmv.cli.configuration.config import build_client
10
+ from nextmv.cli.message import error
17
11
  from nextmv.cli.options import ProfileOption
12
+ from nextmv.cloud.community import clone_community_app
18
13
 
19
14
  # Set up subcommand application.
20
15
  app = typer.Typer()
@@ -53,218 +48,39 @@ def clone(
53
48
  Clone a community app locally.
54
49
 
55
50
  By default, the [magenta]latest[/magenta] version will be used. You can
56
- specify a version with the [code]--version[/code] flag, and customize the
57
- output directory with the [code]--directory[/code] flag. If you want to
58
- list the available apps, use the [code]nextmv community list[/code] command.
51
+ specify a version with the --version flag, and customize the output
52
+ directory with the --directory flag. If you want to list the available
53
+ apps, use the [code]nextmv community list[/code] command.
59
54
 
60
55
  [bold][underline]Examples[/underline][/bold]
61
56
 
62
57
  - Clone the [magenta]go-nextroute[/magenta] community app (under the
63
58
  [magenta]"go-nextroute"[/magenta] directory), using the [magenta]latest[/magenta] version.
64
- $ [green]nextmv community clone --app go-nextroute[/green]
59
+ $ [dim]nextmv community clone --app go-nextroute[/dim]
65
60
 
66
61
  - Clone the [magenta]go-nextroute[/magenta] community app under the
67
62
  [magenta]"~/sample/my_app"[/magenta] directory, using the [magenta]latest[/magenta] version.
68
- $ [green]nextmv community clone --app go-nextroute --directory ~/sample/my_app[/green]
63
+ $ [dim]nextmv community clone --app go-nextroute --directory ~/sample/my_app[/dim]
69
64
 
70
65
  - Clone the [magenta]go-nextroute[/magenta] community app (under the
71
66
  [magenta]"go-nextroute"[/magenta] directory), using version [magenta]v1.2.0[/magenta].
72
- $ [green]nextmv community clone --app go-nextroute --version v1.2.0[/green]
67
+ $ [dim]nextmv community clone --app go-nextroute --version v1.2.0[/dim]
73
68
 
74
69
  - Clone the [magenta]go-nextroute[/magenta] community app (under the
75
70
  [magenta]"go-nextroute"[/magenta] directory), using the [magenta]latest[/magenta] version
76
71
  and a profile named [magenta]hare[/magenta].
77
- $ [green]nextmv community clone --app go-nextroute --profile hare[/green]
72
+ $ [dim]nextmv community clone --app go-nextroute --profile hare[/dim]
78
73
  """
79
74
 
80
- manifest = download_manifest(profile=profile)
81
- app_obj = find_app(manifest, app)
82
-
83
75
  if version is not None and version == "":
84
- error("The [code]--version[/code] flag cannot be an empty string.")
85
-
86
- if not app_has_version(app_obj, version):
87
- # We don't use error() here to allow printing something before exiting.
88
- rich.print(
89
- f"[red]Error:[/red] Version [magenta]{version}[/magenta] not found "
90
- f"for community app [magenta]{app}[/magenta]. Available versions are:"
91
- )
92
- versions_table(manifest, app)
93
-
94
- raise typer.Exit(code=1)
95
-
96
- original_version = version
97
- if version == LATEST_VERSION:
98
- version = app_obj.get("latest_app_version")
99
-
100
- destination = directory
101
- if directory is None or directory == "":
102
- destination = app
103
-
104
- full_destination = get_valid_path(destination, os.stat)
105
- os.makedirs(full_destination, exist_ok=True)
106
-
107
- tarball = f"{app}_{version}.tar.gz"
108
- s3_file_path = f"{app}/{version}/{tarball}"
109
- downloaded_object = download_object(
110
- file=s3_file_path,
111
- path="community-apps",
112
- output_dir=full_destination,
113
- output_file=tarball,
114
- profile=profile,
115
- )
116
-
117
- # Extract the tarball to a temporary directory to handle nested structure
118
- with tempfile.TemporaryDirectory() as temp_dir:
119
- with tarfile.open(downloaded_object, "r:gz") as tar:
120
- tar.extractall(path=temp_dir)
121
-
122
- # Find the extracted directory (typically the app name)
123
- extracted_items = os.listdir(temp_dir)
124
- if len(extracted_items) == 1 and os.path.isdir(os.path.join(temp_dir, extracted_items[0])):
125
- # Move contents from the extracted directory to full_destination
126
- extracted_dir = os.path.join(temp_dir, extracted_items[0])
127
- for item in os.listdir(extracted_dir):
128
- shutil.move(os.path.join(extracted_dir, item), full_destination)
129
- else:
130
- # If structure is unexpected, move everything directly
131
- for item in extracted_items:
132
- shutil.move(os.path.join(temp_dir, item), full_destination)
133
-
134
- # Remove the tarball after extraction
135
- os.remove(downloaded_object)
136
-
137
- rich.print(
138
- f":white_check_mark: Successfully cloned the [magenta]{app}[/magenta] community app, "
139
- f"using version [magenta]{original_version}[/magenta] in path: [magenta]{full_destination}[/magenta]."
76
+ error("The --version flag cannot be an empty string.")
77
+
78
+ client = build_client(profile)
79
+ clone_community_app(
80
+ client=client,
81
+ app=app,
82
+ directory=directory,
83
+ version=version,
84
+ verbose=True,
85
+ rich_print=True,
140
86
  )
141
-
142
-
143
- def app_has_version(app_obj: dict, version: str) -> bool:
144
- """
145
- Check if the given app object has the specified version.
146
-
147
- Parameters
148
- ----------
149
- app_obj : dict
150
- The community app object.
151
- version : str
152
- The version to check.
153
-
154
- Returns
155
- -------
156
- bool
157
- True if the app has the specified version, False otherwise.
158
- """
159
-
160
- if version == LATEST_VERSION:
161
- version = app_obj.get("latest_app_version")
162
-
163
- if version in app_obj.get("app_versions", []):
164
- return True
165
-
166
- return False
167
-
168
-
169
- def get_valid_path(path: str, stat_fn: Callable[[str], os.stat_result], ending: str = "") -> str:
170
- """
171
- Validates and returns a non-existing path. If the path exists,
172
- it will append a number to the path and return it. If the path does not
173
- exist, it will return the path as is.
174
-
175
- The ending parameter is used to check if the path ends with a specific
176
- string. This is useful to specify if it is a file (like foo.json, in which
177
- case the next iteration is foo-1.json) or a directory (like foo, in which
178
- case the next iteration is foo-1).
179
-
180
- Parameters
181
- ----------
182
- path : str
183
- The initial path to validate.
184
- stat_fn : Callable[[str], os.stat_result]
185
- A function that takes a path and returns its stat result.
186
- ending : str, optional
187
- The expected ending of the path (e.g., file extension), by default "".
188
-
189
- Returns
190
- -------
191
- str
192
- A valid, non-existing path.
193
-
194
- Raises
195
- ------
196
- Exception
197
- If an unexpected error occurs during path validation
198
- """
199
- base_name = os.path.basename(path)
200
- name_without_ending = base_name.removesuffix(ending) if ending else base_name
201
-
202
- while True:
203
- try:
204
- stat_fn(path)
205
- # If we get here, the path exists
206
- # Get folder/file name number, increase it and create new path
207
- name = os.path.basename(path)
208
-
209
- # Get folder/file name number
210
- parts = name.split("-")
211
- last = parts[-1].removesuffix(ending) if ending else parts[-1]
212
-
213
- # Save last folder name index to be changed
214
- i = path.rfind(name)
215
-
216
- try:
217
- num = int(last)
218
- # Increase number and create new path
219
- if ending:
220
- temp_path = path[:i] + f"{name_without_ending}-{num + 1}{ending}"
221
- else:
222
- temp_path = path[:i] + f"{base_name}-{num + 1}"
223
- path = temp_path
224
- except ValueError:
225
- # If there is no number, add it
226
- if ending:
227
- temp_path = path[:i] + f"{name_without_ending}-1{ending}"
228
- else:
229
- temp_path = path[:i] + f"{name}-1"
230
- path = temp_path
231
-
232
- except FileNotFoundError:
233
- # Path doesn't exist, we can use it
234
- return path
235
- except Exception:
236
- # Re-raise unexpected errors
237
- error(f"An unexpected error occurred while validating the path: {path}")
238
-
239
-
240
- def download_object(file: str, path: str, output_dir: str, output_file: str, profile: str | None = None) -> str:
241
- """
242
- Downloads an object from the internal bucket and saves it to the specified
243
- output directory.
244
-
245
- Parameters
246
- ----------
247
- file : str
248
- The name of the file to download.
249
- path : str
250
- The directory in the bucket where the file is located.
251
- output_dir : str
252
- The local directory where the file will be saved.
253
- output_file : str
254
- The name of the output file.
255
- profile : str | None
256
- The profile name to use. If None, the default profile is used.
257
-
258
- Returns
259
- -------
260
- str
261
- The path to the downloaded file.
262
- """
263
-
264
- response = download_file(directory=path, file=file, profile=profile)
265
- file_name = os.path.join(output_dir, output_file)
266
-
267
- with open(file_name, "wb") as f:
268
- f.write(response.content)
269
-
270
- return file_name
@@ -2,18 +2,18 @@
2
2
  This module defines the community list command for the Nextmv CLI.
3
3
  """
4
4
 
5
- from typing import Annotated, Any
5
+ from typing import Annotated
6
6
 
7
- import requests
8
7
  import rich
9
8
  import typer
10
- import yaml
11
9
  from rich.console import Console
12
10
  from rich.table import Table
13
11
 
14
12
  from nextmv.cli.configuration.config import build_client
15
- from nextmv.cli.error import error
13
+ from nextmv.cli.message import error
16
14
  from nextmv.cli.options import ProfileOption
15
+ from nextmv.cloud.client import Client
16
+ from nextmv.cloud.community import CommunityApp, list_community_apps
17
17
 
18
18
  # Set up subcommand application.
19
19
  app = typer.Typer()
@@ -37,121 +37,98 @@ def list(
37
37
  """
38
38
  List the available community apps
39
39
 
40
- Use the [code]--app[/code] flag to list that app's versions. Use the
41
- [code]--flat[/code] flag to flatten the list of names/versions. If you
42
- want to clone a community app locally, use the [code]nextmv community clone[/code] command.
40
+ Use the --app flag to list that app's versions. Use the --flat flag to
41
+ flatten the list of names/versions. If you want to clone a community app
42
+ locally, use the [code]nextmv community clone[/code] command.
43
43
 
44
44
  [bold][underline]Examples[/underline][/bold]
45
45
 
46
46
  - List the available community apps.
47
- $ [green]nextmv community list[/green]
47
+ $ [dim]nextmv community list[/dim]
48
48
 
49
49
  - List the available versions of the [magenta]go-nextroute[/magenta] community app.
50
- $ [green]nextmv community list --app go-nextroute[/green]
50
+ $ [dim]nextmv community list --app go-nextroute[/dim]
51
51
 
52
52
  - List the names of the available community apps as a flat list.
53
- $ [green]nextmv community list --flat[/green]
53
+ $ [dim]nextmv community list --flat[/dim]
54
54
 
55
55
  - List the available versions of the [magenta]go-nextroute[/magenta] community app as a flat list.
56
- $ [green]nextmv community list --app go-nextroute --flat[/green]
56
+ $ [dim]nextmv community list --app go-nextroute --flat[/dim]
57
57
 
58
58
  - List the available community apps using a profile named [magenta]hare[/magenta].
59
- $ [green]nextmv community list --profile hare[/green]
59
+ $ [dim]nextmv community list --profile hare[/dim]
60
60
  """
61
61
 
62
62
  if app is not None and app == "":
63
- error("The [code]--app[/code] flag cannot be an empty string.")
63
+ error("The --app flag cannot be an empty string.")
64
64
 
65
- manifest = download_manifest(profile=profile)
65
+ client = build_client(profile)
66
66
  if flat and app is None:
67
- apps_list(manifest)
67
+ _apps_list(client)
68
68
  raise typer.Exit()
69
69
  elif not flat and app is None:
70
- apps_table(manifest)
70
+ _apps_table(client)
71
71
  raise typer.Exit()
72
72
  elif flat and app is not None and app != "":
73
- versions_list(manifest, app)
73
+ _versions_list(client, app)
74
74
  raise typer.Exit()
75
75
  elif not flat and app is not None and app != "":
76
- versions_table(manifest, app)
76
+ _versions_table(client, app)
77
77
  raise typer.Exit()
78
78
 
79
79
 
80
- def download_manifest(profile: str | None = None) -> dict:
80
+ def _apps_table(client: Client) -> None:
81
81
  """
82
- Downloads and returns the community apps manifest.
82
+ This function prints a table of community apps.
83
83
 
84
84
  Parameters
85
85
  ----------
86
- profile : str | None
87
- The profile name to use. If None, the default profile is used.
88
-
89
- Returns
90
- -------
91
- dict
92
- The community apps manifest as a dictionary.
93
-
94
- Raises
95
- requests.HTTPError
96
- If the response status code is not 2xx.
97
- """
98
-
99
- response = download_file(directory="community-apps", file="manifest.yml", profile=profile)
100
- manifest = yaml.safe_load(response.text)
101
-
102
- return manifest
103
-
104
-
105
- def apps_table(manifest: dict[str, Any]) -> None:
106
- """
107
- This function prints a table of community apps from the manifest.
108
-
109
- Parameters
110
- ----------
111
- manifest : dict[str, Any]
112
- The community apps manifest.
86
+ client : Client
87
+ The Nextmv Cloud client to use for the request.
113
88
  """
114
89
 
90
+ apps = list_community_apps(client)
115
91
  table = Table("Name", "Type", "Latest", "Description", border_style="cyan", header_style="cyan")
116
- for app in manifest.get("apps", []):
92
+ for app in apps:
117
93
  table.add_row(
118
- app.get("name", ""),
119
- app.get("type", ""),
120
- app.get("latest_app_version", ""),
121
- app.get("description", ""),
94
+ app.name,
95
+ app.app_type,
96
+ app.latest_app_version if app.latest_app_version is not None else "",
97
+ app.description,
122
98
  )
123
99
 
124
100
  console.print(table)
125
101
 
126
102
 
127
- def apps_list(manifest: dict[str, Any]) -> None:
103
+ def _apps_list(client: Client) -> None:
128
104
  """
129
- This function prints a flat list of community app names from the manifest.
105
+ This function prints a flat list of community app names.
130
106
 
131
107
  Parameters
132
108
  ----------
133
- manifest : dict[str, Any]
134
- The community apps manifest.
109
+ client : Client
110
+ The Nextmv Cloud client to use for the request.
135
111
  """
136
112
 
137
- names = [app.get("name", "") for app in manifest.get("apps", [])]
113
+ apps = list_community_apps(client)
114
+ names = [app.name for app in apps]
138
115
  print("\n".join(names))
139
116
 
140
117
 
141
- def versions_table(manifest: dict[str, Any], app: str) -> None:
118
+ def _versions_table(client: Client, app: str) -> None:
142
119
  """
143
120
  This function prints a table of versions for a specific community app.
144
121
 
145
122
  Parameters
146
123
  ----------
147
- manifest : dict[str, Any]
148
- The community apps manifest.
124
+ client : Client
125
+ The Nextmv Cloud client to use for the request.
149
126
  app : str
150
127
  The name of the community app.
151
128
  """
152
129
 
153
- app_obj = find_app(manifest, app)
154
- latest_version = app_obj.get("latest_app_version", "")
130
+ comm_app = _find_app(client, app)
131
+ latest_version = comm_app.latest_app_version if comm_app.latest_app_version is not None else ""
155
132
 
156
133
  # Add the latest version with indicator
157
134
  table = Table("Version", "Latest?", border_style="cyan", header_style="cyan")
@@ -159,7 +136,7 @@ def versions_table(manifest: dict[str, Any], app: str) -> None:
159
136
  table.add_row("", "") # Empty row to separate latest from others.
160
137
 
161
138
  # Add all other versions (excluding the latest)
162
- versions = app_obj.get("app_versions", [])
139
+ versions = comm_app.app_versions if comm_app.app_versions is not None else []
163
140
  for version in versions:
164
141
  if version != latest_version:
165
142
  table.add_row(version, "")
@@ -167,99 +144,57 @@ def versions_table(manifest: dict[str, Any], app: str) -> None:
167
144
  console.print(table)
168
145
 
169
146
 
170
- def versions_list(manifest: dict[str, Any], app: str) -> None:
147
+ def _versions_list(client: Client, app: str) -> None:
171
148
  """
172
149
  This function prints a flat list of versions for a specific community app.
173
150
 
174
151
  Parameters
175
152
  ----------
176
- manifest : dict[str, Any]
177
- The community apps manifest.
153
+ client : Client
154
+ The Nextmv Cloud client to use for the request.
178
155
  app : str
179
156
  The name of the community app.
180
157
  """
181
158
 
182
- app_obj = find_app(manifest, app)
183
- versions = app_obj.get("app_versions", [])
159
+ comm_app = _find_app(client, app)
160
+ versions = comm_app.app_versions if comm_app.app_versions is not None else []
184
161
 
185
162
  versions_output = ""
186
163
  for version in versions:
187
164
  versions_output += f"{version}\n"
188
165
 
189
- print("\n".join(app_obj.get("app_versions", [])))
190
-
191
-
192
- def download_file(
193
- directory: str,
194
- file: str,
195
- profile: str | None = None,
196
- ) -> requests.Response:
197
- """
198
- Gets a file from an internal bucket and return it.
166
+ print(versions_output.rstrip("\n"))
199
167
 
200
- Parameters
201
- ----------
202
- directory : str
203
- The directory in the bucket where the file is located.
204
- file : str
205
- The name of the file to download.
206
- profile : str | None
207
- The profile name to use. If None, the default profile is used.
208
168
 
209
- Returns
210
- -------
211
- requests.Response
212
- The response object containing the file data.
213
-
214
- Raises
215
- requests.HTTPError
216
- If the response status code is not 2xx.
217
- """
218
-
219
- client = build_client(profile)
220
-
221
- # Request the download URL for the file.
222
- response = client.request(
223
- method="GET",
224
- endpoint="v0/internal/tools",
225
- headers=client.headers | {"request-source": "cli"}, # Pass `client.headers` to preserve auth.
226
- query_params={"file": f"{directory}/{file}"},
227
- )
228
-
229
- # Use the URL obtained to download the file.
230
- body = response.json()
231
- download_response = client.request(
232
- method="GET",
233
- endpoint=body.get("url"),
234
- headers={"Content-Type": "application/json"},
235
- )
236
-
237
- return download_response
238
-
239
-
240
- def find_app(manifest: dict[str, Any], app: str) -> dict[str, Any] | None:
169
+ def _find_app(client: Client, app: str) -> CommunityApp:
241
170
  """
242
171
  Finds and returns a community app from the manifest by its name.
243
172
 
244
173
  Parameters
245
174
  ----------
246
- manifest : dict[str, Any]
247
- The community apps manifest.
175
+ client : Client
176
+ The Nextmv Cloud client to use for the request.
248
177
  app : str
249
178
  The name of the community app to find.
250
179
 
251
180
  Returns
252
181
  -------
253
- dict[str, Any] | None
254
- The community app dictionary if found, otherwise None.
182
+ CommunityApp
183
+ The community app if found.
184
+
185
+ Raises
186
+ ------
187
+ ValueError
188
+ If the community app is not found.
255
189
  """
256
190
 
257
- for manifest_app in manifest.get("apps", []):
258
- if manifest_app.get("name", "") == app:
259
- return manifest_app
191
+ comm_apps = list_community_apps(client)
192
+ for comm_app in comm_apps:
193
+ if comm_app.name == app:
194
+ return comm_app
260
195
 
261
196
  # We don't use error() here to allow printing something before exiting.
262
197
  rich.print(f"[red]Error:[/red] Community app [magenta]{app}[/magenta] was not found. Here are the available apps:")
263
- apps_table(manifest)
198
+ _apps_table(client)
264
199
 
265
200
  raise typer.Exit(code=1)
@@ -0,0 +1,23 @@
1
+ """
2
+ This module defines the configuration command tree for the Nextmv CLI.
3
+ """
4
+
5
+ import typer
6
+
7
+ from nextmv.cli.configuration.create import app as create_app
8
+ from nextmv.cli.configuration.delete import app as delete_app
9
+ from nextmv.cli.configuration.list import app as list_app
10
+
11
+ # Set up subcommand application.
12
+ app = typer.Typer()
13
+ app.add_typer(create_app)
14
+ app.add_typer(delete_app)
15
+ app.add_typer(list_app)
16
+
17
+
18
+ @app.callback()
19
+ def callback() -> None:
20
+ """
21
+ Configure the CLI and manage profiles.
22
+ """
23
+ pass