aspera-cli 4.29.1 → 4.30.0

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 (264) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +4 -4
  3. data/CHANGELOG.md +119 -0
  4. data/CONTRIBUTING.md +8 -1
  5. data/README.md +2 -0
  6. data/TODO.md +4 -5
  7. data/bin/asession +2 -2
  8. data/docs/README.md +616 -86
  9. data/docs/test-mcp-with-ai.md +4 -0
  10. data/lib/aspera/agent/base.rb +62 -6
  11. data/lib/aspera/agent/factory.rb +127 -20
  12. data/lib/aspera/ascp/data_repository.rb +71 -0
  13. data/lib/aspera/ascp/installation.rb +16 -11
  14. data/lib/aspera/ascp/log_analyzer/lines.rb +4 -4
  15. data/lib/aspera/ascp/log_analyzer/log_file.rb +5 -3
  16. data/lib/aspera/ascp/log_analyzer/records.rb +11 -6
  17. data/lib/aspera/ascp/log_analyzer.rb +43 -18
  18. data/lib/aspera/ascp/log_locations.rb +2 -2
  19. data/lib/aspera/assert.rb +8 -0
  20. data/lib/aspera/bundle_registry.rb +528 -0
  21. data/lib/aspera/cli/argument.rb +110 -0
  22. data/lib/aspera/cli/bool_value.rb +41 -0
  23. data/lib/aspera/cli/bootstrapper.rb +31 -24
  24. data/lib/aspera/cli/command/mount.rb +53 -0
  25. data/lib/aspera/cli/command/registry.rb +434 -0
  26. data/lib/aspera/cli/command.rb +95 -0
  27. data/lib/aspera/cli/command_line.rb +91 -91
  28. data/lib/aspera/cli/complete.rb +22 -0
  29. data/lib/aspera/cli/completion_actions.rb +28 -26
  30. data/lib/aspera/cli/context.rb +29 -6
  31. data/lib/aspera/cli/error.rb +39 -0
  32. data/lib/aspera/cli/extended_value.rb +25 -4
  33. data/lib/aspera/cli/formatter.rb +8 -8
  34. data/lib/aspera/cli/hints.rb +17 -52
  35. data/lib/aspera/cli/http.rb +17 -12
  36. data/lib/aspera/cli/mailer.rb +7 -24
  37. data/lib/aspera/cli/mcp/tool.rb +10 -2
  38. data/lib/aspera/cli/option/declarator.rb +80 -0
  39. data/lib/aspera/cli/option/registry.rb +74 -0
  40. data/lib/aspera/cli/option/source.rb +38 -0
  41. data/lib/aspera/cli/option/type.rb +37 -0
  42. data/lib/aspera/cli/option/value.rb +376 -0
  43. data/lib/aspera/cli/option.rb +78 -0
  44. data/lib/aspera/cli/options.schema.yaml +28 -783
  45. data/lib/aspera/cli/parser.rb +73 -41
  46. data/lib/aspera/cli/plugins/base.rb +122 -42
  47. data/lib/aspera/cli/plugins/basic_auth.rb +13 -2
  48. data/lib/aspera/cli/plugins/config.rb +101 -167
  49. data/lib/aspera/cli/plugins/factory.rb +139 -43
  50. data/lib/aspera/cli/plugins/mcp.rb +61 -54
  51. data/lib/aspera/cli/plugins/oauth.rb +19 -6
  52. data/lib/aspera/cli/poll.rb +14 -20
  53. data/lib/aspera/cli/preset_actions.rb +11 -3
  54. data/lib/aspera/cli/preset_manager.rb +16 -6
  55. data/lib/aspera/cli/result.rb +2 -2
  56. data/lib/aspera/cli/runner.rb +71 -99
  57. data/lib/aspera/cli/secret_finder.rb +1 -1
  58. data/lib/aspera/cli/security.rb +102 -4
  59. data/lib/aspera/{preview/terminal.rb → cli/terminal_image.rb} +93 -94
  60. data/lib/aspera/cli/vault_manager.rb +3 -3
  61. data/lib/aspera/cli/version.rb +1 -1
  62. data/lib/aspera/cli/wizard.rb +9 -3
  63. data/lib/aspera/coverage.rb +1 -2
  64. data/lib/aspera/line_logger.rb +35 -6
  65. data/lib/aspera/log.rb +3 -2
  66. data/lib/aspera/oauth/client/base.rb +19 -1
  67. data/lib/aspera/oauth/client/factory.rb +1 -7
  68. data/lib/aspera/plugin.schema.yaml +178 -0
  69. data/lib/aspera/plugins/alee/api.rb +25 -0
  70. data/lib/aspera/{cli/plugins/alee.rb → plugins/alee/commands.rb} +10 -8
  71. data/lib/aspera/plugins/alee/plugin.yaml +3 -0
  72. data/lib/aspera/plugins/aoc/admin_resources.rb +148 -0
  73. data/lib/aspera/plugins/aoc/api.rb +783 -0
  74. data/lib/aspera/{cli/plugins/aoc.rb → plugins/aoc/commands.rb} +404 -330
  75. data/lib/aspera/plugins/aoc/graphql.rb +45 -0
  76. data/lib/aspera/plugins/aoc/plugin.yaml +31 -0
  77. data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +15042 -7076
  78. data/lib/aspera/plugins/aoc/schemas/options.yaml +47 -0
  79. data/lib/aspera/plugins/ats/api.rb +51 -0
  80. data/lib/aspera/{cli/plugins/ats.rb → plugins/ats/commands.rb} +33 -33
  81. data/lib/aspera/plugins/ats/plugin.yaml +6 -0
  82. data/lib/aspera/plugins/connect/agent.rb +199 -0
  83. data/lib/aspera/plugins/connect/plugin.yaml +11 -0
  84. data/lib/aspera/plugins/connect/schemas/agent_options.yaml +6 -0
  85. data/lib/aspera/{cli/plugins/console.rb → plugins/console/commands.rb} +41 -33
  86. data/lib/aspera/plugins/console/plugin.yaml +8 -0
  87. data/lib/aspera/plugins/cos/api.rb +114 -0
  88. data/lib/aspera/{cli/plugins/cos.rb → plugins/cos/commands.rb} +19 -16
  89. data/lib/aspera/plugins/cos/plugin.yaml +9 -0
  90. data/lib/aspera/plugins/cos/schemas/options.yaml +30 -0
  91. data/lib/aspera/plugins/desktop/agent.rb +165 -0
  92. data/lib/aspera/plugins/desktop/plugin.yaml +11 -0
  93. data/lib/aspera/plugins/desktop/schemas/agent_options.yaml +6 -0
  94. data/lib/aspera/plugins/direct/agent.rb +518 -0
  95. data/lib/aspera/plugins/direct/plugin.yaml +11 -0
  96. data/lib/aspera/plugins/direct/schemas/agent_options.yaml +86 -0
  97. data/lib/aspera/plugins/faspex4/gateway_options.rb +18 -0
  98. data/lib/aspera/plugins/faspex4/gw_servlet.rb +122 -0
  99. data/lib/aspera/plugins/faspex4/plugin.yaml +7 -0
  100. data/lib/aspera/plugins/faspex4/schemas/options.yaml +57 -0
  101. data/lib/aspera/plugins/faspex5/api.rb +269 -0
  102. data/lib/aspera/{cli/plugins/faspex5.rb → plugins/faspex5/commands.rb} +152 -114
  103. data/lib/aspera/plugins/faspex5/faspex4_post_proc_servlet.rb +241 -0
  104. data/lib/aspera/plugins/faspex5/plugin.yaml +14 -0
  105. data/lib/aspera/{schema → plugins/faspex5/schemas}/IBM Aspera Faspex API-5.0-enhanced.yaml +279 -76
  106. data/lib/aspera/plugins/faspex5/schemas/options.yaml +87 -0
  107. data/lib/aspera/{cli/plugins/faspio.rb → plugins/faspio/commands.rb} +11 -7
  108. data/lib/aspera/plugins/faspio/plugin.yaml +8 -0
  109. data/lib/aspera/{schema → plugins/faspio/schemas}/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml +4 -2
  110. data/lib/aspera/plugins/httpgw/agent.rb +126 -0
  111. data/lib/aspera/plugins/httpgw/api.rb +411 -0
  112. data/lib/aspera/{cli/plugins/httpgw.rb → plugins/httpgw/commands.rb} +9 -9
  113. data/lib/aspera/plugins/httpgw/plugin.yaml +12 -0
  114. data/lib/aspera/plugins/httpgw/schemas/agent_options.yaml +24 -0
  115. data/lib/aspera/plugins/node/agent.rb +184 -0
  116. data/lib/aspera/plugins/node/api.rb +699 -0
  117. data/lib/aspera/{cli/plugins/node.rb → plugins/node/commands.rb} +166 -141
  118. data/lib/aspera/plugins/node/emulator.rb +774 -0
  119. data/lib/aspera/plugins/node/plugin.yaml +20 -0
  120. data/lib/aspera/plugins/node/schemas/agent_options.yaml +20 -0
  121. data/lib/aspera/plugins/node/schemas/options.yaml +190 -0
  122. data/lib/aspera/{cli/plugins/orchestrator.rb → plugins/orchestrator/commands.rb} +139 -110
  123. data/lib/aspera/plugins/orchestrator/plugin.yaml +34 -0
  124. data/lib/aspera/{schema → plugins/orchestrator/schemas}/IBM Aspera Orchestrator API-v1-enhanced.yaml +486 -16
  125. data/lib/aspera/plugins/orchestrator/schemas/options.yaml +143 -0
  126. data/lib/aspera/plugins/orchestrator/workflow_checker.rb +692 -0
  127. data/lib/aspera/{cli/plugins/preview.rb → plugins/preview/commands.rb} +53 -51
  128. data/lib/aspera/plugins/preview/file_types.rb +121 -0
  129. data/lib/aspera/plugins/preview/generator.rb +350 -0
  130. data/lib/aspera/plugins/preview/plugin.yaml +12 -0
  131. data/lib/aspera/{preview/options.schema.yaml → plugins/preview/schemas/options.yaml} +1 -1
  132. data/lib/aspera/plugins/preview/utils.rb +213 -0
  133. data/lib/aspera/plugins/server/ascmd.rb +374 -0
  134. data/lib/aspera/{cli/plugins/server.rb → plugins/server/commands.rb} +48 -32
  135. data/lib/aspera/plugins/server/plugin.yaml +9 -0
  136. data/lib/aspera/plugins/server/schemas/options.yaml +30 -0
  137. data/lib/aspera/{cli/plugins/shares.rb → plugins/shares/commands.rb} +29 -21
  138. data/lib/aspera/plugins/shares/plugin.yaml +10 -0
  139. data/lib/aspera/plugins/shares/shares_web.rb +97 -0
  140. data/lib/aspera/plugins/transferd/agent.rb +258 -0
  141. data/lib/aspera/plugins/transferd/api.rb +180 -0
  142. data/lib/aspera/plugins/transferd/client.rb +67 -0
  143. data/lib/aspera/{cli/plugins/transferd.rb → plugins/transferd/commands.rb} +43 -42
  144. data/lib/aspera/plugins/transferd/config_commands.rb +38 -0
  145. data/lib/aspera/plugins/transferd/plugin.yaml +27 -0
  146. data/lib/aspera/plugins/transferd/product.rb +146 -0
  147. data/lib/aspera/plugins/transferd/schemas/agent_options.yaml +31 -0
  148. data/lib/aspera/plugins/transferd/schemas/options.yaml +80 -0
  149. data/lib/aspera/plugins/transferd/service.rb +617 -0
  150. data/lib/aspera/plugins/xfer/ascp_actions.rb +131 -0
  151. data/lib/aspera/plugins/xfer/ascp_logs_actions.rb +198 -0
  152. data/lib/aspera/plugins/xfer/async_transfer_store.rb +131 -0
  153. data/lib/aspera/plugins/xfer/config_commands.rb +119 -0
  154. data/lib/aspera/plugins/xfer/helper.rb +19 -0
  155. data/lib/aspera/plugins/xfer/plugin.yaml +42 -0
  156. data/lib/aspera/plugins/xfer/schemas/agent_extension.schema.yaml +26 -0
  157. data/lib/aspera/plugins/xfer/schemas/options.yaml +125 -0
  158. data/lib/aspera/plugins/xfer/sync_actions.rb +253 -0
  159. data/lib/aspera/plugins/xfer/transfer_actions.rb +176 -0
  160. data/lib/aspera/plugins/xfer/transfer_agent.rb +505 -0
  161. data/lib/aspera/products/cli_v3.rb +34 -0
  162. data/lib/aspera/products/connect.rb +1 -1
  163. data/lib/aspera/products/drive.rb +29 -0
  164. data/lib/aspera/products/hsts.rb +34 -0
  165. data/lib/aspera/products/transferd.rb +25 -3
  166. data/lib/aspera/products.rb +54 -0
  167. data/lib/aspera/prompt.rb +184 -0
  168. data/lib/aspera/proxy_auto_config.rb +3 -3
  169. data/lib/aspera/rest/aspera_errors.rb +4 -38
  170. data/lib/aspera/rest/error_analyzer.rb +6 -2
  171. data/lib/aspera/rest/list.rb +4 -5
  172. data/lib/aspera/schema/reader.rb +15 -0
  173. data/lib/aspera/schema/registry.rb +239 -45
  174. data/lib/aspera/schema/validator.rb +63 -17
  175. data/lib/aspera/sealed_hash.rb +4 -0
  176. data/lib/aspera/secret/hider.rb +159 -24
  177. data/lib/aspera/secret/reference.rb +8 -0
  178. data/lib/aspera/secret/resolver.rb +8 -4
  179. data/lib/aspera/secret/store/base.rb +10 -9
  180. data/lib/aspera/secret/store/encrypted_hash.rb +6 -6
  181. data/lib/aspera/secret/store/hashicorp_vault.rb +3 -3
  182. data/lib/aspera/secret/store/keeper.rb +2 -2
  183. data/lib/aspera/secret/store/macos_security.rb +2 -3
  184. data/lib/aspera/secret/store/one_password_api.rb +2 -2
  185. data/lib/aspera/secret/store/one_password_cli.rb +3 -3
  186. data/lib/aspera/secret/store/secret_service.rb +2 -2
  187. data/lib/aspera/ssl.rb +3 -3
  188. data/lib/aspera/standard_input.rb +20 -0
  189. data/lib/aspera/{schema → sync}/async_tables.yaml +1 -1
  190. data/lib/aspera/sync/database.rb +7 -0
  191. data/lib/aspera/sync/log_parser.rb +138 -0
  192. data/lib/aspera/sync/operations.rb +59 -34
  193. data/lib/aspera/transfer/command_line_builder.rb +248 -0
  194. data/lib/aspera/transfer/command_line_converter.rb +37 -0
  195. data/lib/aspera/transfer/faux_file.rb +2 -2
  196. data/lib/aspera/transfer/parameters.rb +9 -10
  197. data/lib/aspera/transfer/spec.rb +28 -1
  198. data/lib/aspera/transfer/spec.schema.yaml +30 -5
  199. data/lib/aspera/units/decimal.rb +1 -1
  200. data/lib/aspera/units/timestamp.rb +84 -0
  201. data/lib/aspera/uri_reader.rb +2 -2
  202. data/lib/aspera/web_auth/paste.rb +2 -2
  203. data/lib/aspera/web_server_simple.rb +10 -4
  204. data.tar.gz.sig +0 -0
  205. metadata +137 -80
  206. metadata.gz.sig +0 -0
  207. data/lib/aspera/agent/connect.rb +0 -188
  208. data/lib/aspera/agent/desktop.rb +0 -154
  209. data/lib/aspera/agent/direct.rb +0 -496
  210. data/lib/aspera/agent/httpgw.rb +0 -100
  211. data/lib/aspera/agent/node.rb +0 -166
  212. data/lib/aspera/agent/transferd.rb +0 -341
  213. data/lib/aspera/api/alee.rb +0 -19
  214. data/lib/aspera/api/aoc.rb +0 -776
  215. data/lib/aspera/api/ats.rb +0 -49
  216. data/lib/aspera/api/cos_node.rb +0 -107
  217. data/lib/aspera/api/faspex.rb +0 -258
  218. data/lib/aspera/api/httpgw.rb +0 -409
  219. data/lib/aspera/api/node.rb +0 -684
  220. data/lib/aspera/ascmd.rb +0 -248
  221. data/lib/aspera/cli/ascp_actions.rb +0 -113
  222. data/lib/aspera/cli/ascp_logs_actions.rb +0 -188
  223. data/lib/aspera/cli/async_transfer_store.rb +0 -129
  224. data/lib/aspera/cli/command_registry.rb +0 -371
  225. data/lib/aspera/cli/command_spec.rb +0 -273
  226. data/lib/aspera/cli/option_declarator.rb +0 -74
  227. data/lib/aspera/cli/option_registry.rb +0 -72
  228. data/lib/aspera/cli/option_types.rb +0 -120
  229. data/lib/aspera/cli/option_value.rb +0 -345
  230. data/lib/aspera/cli/prompt.rb +0 -186
  231. data/lib/aspera/cli/sync_actions.rb +0 -181
  232. data/lib/aspera/cli/transfer_actions.rb +0 -98
  233. data/lib/aspera/cli/transfer_agent.rb +0 -348
  234. data/lib/aspera/command_line_builder.rb +0 -244
  235. data/lib/aspera/command_line_converter.rb +0 -35
  236. data/lib/aspera/data_repository.rb +0 -69
  237. data/lib/aspera/faspex_gw.rb +0 -172
  238. data/lib/aspera/faspex_postproc.rb +0 -237
  239. data/lib/aspera/graphql.rb +0 -41
  240. data/lib/aspera/node_emulator.rb +0 -758
  241. data/lib/aspera/oauth/client/shares_web.rb +0 -94
  242. data/lib/aspera/orchestrator_workflow_checker.rb +0 -688
  243. data/lib/aspera/preview/file_types.rb +0 -119
  244. data/lib/aspera/preview/generator.rb +0 -345
  245. data/lib/aspera/preview/utils.rb +0 -211
  246. data/lib/aspera/products/other.rb +0 -92
  247. data/lib/aspera/products/transferd_service.rb +0 -610
  248. /data/lib/aspera/{data → ascp/data}/1 +0 -0
  249. /data/lib/aspera/{data → ascp/data}/2 +0 -0
  250. /data/lib/aspera/{data → ascp/data}/3 +0 -0
  251. /data/lib/aspera/{data → ascp/data}/4 +0 -0
  252. /data/lib/aspera/{data → ascp/data}/5 +0 -0
  253. /data/lib/aspera/{data → ascp/data}/6 +0 -0
  254. /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_account.graphql +0 -0
  255. /data/lib/aspera/{api → plugins/aoc}/queries/bss_subscription_usage.graphql +0 -0
  256. /data/lib/aspera/{schema → plugins/aoc/schemas}/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +0 -0
  257. /data/lib/aspera/{schema → plugins/console/schemas}/IBM Aspera Console-enhanced.yaml +0 -0
  258. /data/lib/aspera/{schema → plugins/node/schemas}/IBM Aspera Node API-4.4.6.yaml +0 -0
  259. /data/lib/aspera/{preview → plugins/preview}/image_error.png +0 -0
  260. /data/lib/aspera/{preview → plugins/preview}/video_error.png +0 -0
  261. /data/lib/aspera/{schema → plugins/shares/schemas}/IBM_Aspera_Shares.yaml +0 -0
  262. /data/lib/{transferd_pb.rb → aspera/plugins/transferd/grpc/transferd_pb.rb} +0 -0
  263. /data/lib/{transferd_services_pb.rb → aspera/plugins/transferd/grpc/transferd_services_pb.rb} +0 -0
  264. /data/lib/aspera/{schema → plugins/transferd/schemas}/transferd-config.schema.json +0 -0
@@ -1,371 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: IBM Corp.
4
- # SPDX-License-Identifier: Apache-2.0
5
-
6
- require_relative 'command_spec'
7
- require_relative 'option_types'
8
-
9
- module Aspera
10
- module Cli
11
- # Stores CommandSpec objects indexed by their full path (Array<Symbol>).
12
- # Each plugin class gets its own instance (not shared across the inheritance chain).
13
- #
14
- # Public API:
15
- # register(spec) - store a CommandSpec; raises on duplicate full_path
16
- # register_option(spec) - store an OptionSpec by name
17
- # option_specs - Hash{Symbol => OptionSpec} of all registered options
18
- # [](path) - retrieve a CommandSpec by full path (follows mounts)
19
- # children_of(path) - Hash{Symbol => CommandSpec} of direct children (follows mounts)
20
- # resolve(path) - [registry, path] owning the spec at path (follows mounts)
21
- # local?(path) - true if path is owned by this registry (not reached through a mount)
22
- # mount_of(path) - MountSpec of the local node at path, if any
23
- # mount_at(path) - MountSpec of the node at path, if any (follows mounts)
24
- # own_children_of(path) - Hash{Symbol => CommandSpec} of direct children declared on the node, without mounted ones
25
- # arguments_at(path) - Array of ArgumentSpec read by the node at path (mount arguments first)
26
- # leaf_paths - Array of all leaf paths (follows mounts, or stops at mount nodes)
27
- # command_path(words) - command path designated by command line words (aliases, prefixes, arguments)
28
- # command_position(words) - command path and number of its arguments, as read by the dispatcher
29
- # all_paths - Array of all locally registered full paths
30
- # any? - true if at least one spec has been registered
31
- # validate! - cross-spec consistency checks; raises on violation
32
- #
33
- # Paths are always expressed in this registry's namespace: a path going through a
34
- # mounted node (see MountSpec) is translated to the target registry transparently.
35
- # Specs returned for mounted paths are the target's specs (their full_path is in the
36
- # target namespace).
37
- class CommandRegistry
38
- # @param path [Array<Symbol>] full path to look up
39
- # @return [CommandSpec, nil]
40
- def [](path)
41
- registry, local_path = resolve(path)
42
- registry.equal?(self) ? @specs[local_path] : registry[local_path]
43
- end
44
-
45
- # Find the registry owning `path`, following mounts.
46
- # A host child always takes precedence over a mounted child with the same id.
47
- # @param path [Array<Symbol>] path in this registry's namespace
48
- # @return [Array(CommandRegistry, Array<Symbol>)] owning registry and path in its namespace
49
- def resolve(path)
50
- path = Array(path)
51
- path.each_index do |i|
52
- prefix = path[0, i]
53
- mount = @specs[prefix]&.mount
54
- next if mount.nil? || @children_index[prefix]&.key?(path[i]) || !mount.accepts?(path[i])
55
- return mount.registry.resolve(mount.at + path[i..])
56
- end
57
- [self, path]
58
- end
59
-
60
- # @param path [Array<Symbol>] path in this registry's namespace
61
- # @return [Boolean] true if the node at path is declared in this registry (not mounted)
62
- def local?(path)
63
- resolve(path).first.equal?(self)
64
- end
65
-
66
- # @param path [Array<Symbol>] local path of a node
67
- # @return [MountSpec, nil] the mount declared on that node
68
- def mount_of(path)
69
- @specs[Array(path)]&.mount
70
- end
71
-
72
- # @param path [Array<Symbol>] path in this registry's namespace
73
- # @return [MountSpec, nil] the mount declared on the node at path, following mounts
74
- def mount_at(path)
75
- registry, local_path = resolve(path)
76
- registry.mount_of(local_path)
77
- end
78
-
79
- # Children declared on the node itself, without the ones exposed by its mount.
80
- # @param path [Array<Symbol>] path in this registry's namespace
81
- # @return [Hash{Symbol => CommandSpec}]
82
- def own_children_of(path)
83
- registry, local_path = resolve(path)
84
- return registry.own_children_of(local_path) unless registry.equal?(self)
85
- @children_index[local_path] || {}
86
- end
87
-
88
- # Arguments read by the node at path, in order.
89
- # For a child exposed by a mount, the mount's arguments come first (read by the host).
90
- # @param path [Array<Symbol>] path in this registry's namespace
91
- # @return [Array<ArgumentSpec>]
92
- def arguments_at(path)
93
- path = Array(path)
94
- (path.empty? ? [] : mount_arguments(path)) + (self[path]&.arguments || [])
95
- end
96
-
97
- # Register a CommandSpec. Raises if the full_path is already registered.
98
- # Also updates the children index so children_of remains O(1).
99
- # @param spec [CommandSpec]
100
- # @raise [ArgumentError] on duplicate full path
101
- # @return [CommandSpec] the registered spec
102
- def register(spec)
103
- path = spec.full_path
104
- raise ArgumentError, "Duplicate command path: #{path.inspect}" if @specs.key?(path)
105
- @specs[path] = spec
106
- # Index: parent_path -> { child_id -> spec }
107
- parent = path[0..-2] # [] for root-level commands
108
- (@children_index[parent] ||= {})[spec.id] = spec
109
- spec
110
- end
111
-
112
- # Returns a Hash mapping each child id to its CommandSpec for all direct
113
- # children of `path`. Empty hash if no children are registered.
114
- # For a mount node: mounted children (filtered) followed by local children,
115
- # local ones overriding mounted ones with the same id.
116
- # @param path [Array<Symbol>] parent path ([] for root-level commands)
117
- # @return [Hash{Symbol => CommandSpec}]
118
- def children_of(path)
119
- registry, local_path = resolve(path)
120
- return registry.children_of(local_path) unless registry.equal?(self)
121
- own = @children_index[local_path] || {}
122
- mount = @specs[local_path]&.mount
123
- return own if mount.nil?
124
- mount.registry.children_of(mount.at).select { |id, _| mount.accepts?(id) }.merge(own)
125
- end
126
-
127
- # All leaf paths under path, in tree order, following mounts.
128
- # A mount cycle (a sub-tree mounting one of its ancestors) is not expanded twice.
129
- # @param path [Array<Symbol>] root of the listing ([] for all)
130
- # @param expand_mounts [Boolean] `false`: a mount node is listed as a leaf, followed by its own children only
131
- # @return [Array<Array<Symbol>>]
132
- def leaf_paths(path = [], chain = [], expand_mounts: true)
133
- children_of(path).keys.flat_map do |id|
134
- child = path + [id]
135
- key = subtree_key(child)
136
- next [] if chain.include?(key)
137
- if !expand_mounts && mount_at(child)
138
- next [child] + own_children_of(child).keys.flat_map do |own_id|
139
- own_child = child + [own_id]
140
- children_of(own_child).empty? ? [own_child] : leaf_paths(own_child, chain + [key], expand_mounts: false)
141
- end
142
- end
143
- children_of(child).empty? ? [child] : leaf_paths(child, chain + [key], expand_mounts: expand_mounts)
144
- end
145
- end
146
-
147
- # Command path designated by words of a command line: sub-commands (or their aliases, or a unique prefix),
148
- # each possibly followed by its positional arguments, e.g. `packages receive ALL` designates `packages receive`.
149
- # Words after a leaf command are its arguments.
150
- # @param words [Array<Symbol>] words following the plugin name
151
- # @return [Array(Array<Symbol>, Symbol)] command path, and the first word that is neither a sub-command
152
- # nor an expected argument (`nil` if none)
153
- def command_path(words)
154
- path = []
155
- # Number of positional arguments still accepted by the node at path
156
- args_left = 0
157
- words.each do |word|
158
- children = children_of(path)
159
- break if children.empty?
160
- id = child_id(children, word)
161
- if id
162
- path += [id]
163
- arguments = arguments_at(path)
164
- args_left = arguments.any?(&:multiple) ? Float::INFINITY : arguments.length
165
- elsif args_left.positive?
166
- args_left -= 1
167
- else
168
- return [path, word]
169
- end
170
- end
171
- [path, nil]
172
- end
173
-
174
- # Position reached by words of a command line, as read by the dispatcher: an intermediate command reads
175
- # its positional arguments before its sub-command, a leaf command reads the following words as arguments.
176
- # Unlike `command_path`, a word expected as argument is never taken as a sub-command.
177
- # @param words [Array<Symbol>] words following the plugin name
178
- # @return [Array(Array<Symbol>, Integer), nil] command path, and number of its positional arguments given;
179
- # `nil` if a word is neither a sub-command nor an expected argument
180
- def command_position(words)
181
- path = []
182
- given = 0
183
- words.each do |word|
184
- children = children_of(path)
185
- arguments = arguments_at(path)
186
- if given < arguments.length || (children.empty? && arguments.last&.multiple)
187
- given += 1
188
- else
189
- id = child_id(children, word)
190
- return nil if id.nil?
191
- path += [id]
192
- given = 0
193
- end
194
- end
195
- [path, given]
196
- end
197
-
198
- # @return [Array<Array<Symbol>>] all locally registered full paths
199
- def all_paths
200
- @specs.keys
201
- end
202
-
203
- # Register an OptionSpec. Raises if the option name is already registered.
204
- # @param spec [OptionSpec]
205
- # @raise [ArgumentError] on duplicate option name
206
- # @return [OptionSpec] the registered spec
207
- def register_option(spec)
208
- raise ArgumentError, "Duplicate option: #{spec.name.inspect}" if @option_specs.key?(spec.name)
209
- @option_specs[spec.name] = spec
210
- end
211
-
212
- # @return [Hash{Symbol => OptionSpec}] all registered option specs
213
- def option_specs
214
- @option_specs.dup
215
- end
216
-
217
- # @return [Boolean] true if at least one spec is registered
218
- def any?
219
- !@specs.empty?
220
- end
221
-
222
- # @return [Boolean] true if no specs have been registered
223
- def none?
224
- @specs.empty?
225
- end
226
-
227
- # Cross-spec consistency checks.
228
- # @param plugin_class [Class, nil] when given, also verify that methods referenced by Symbol
229
- # (implicit and explicit actions, `setup:`, `condition:`, `lookup:`, mount `instance:`) exist
230
- # @raise [ArgumentError] on any violation
231
- # @return [self]
232
- def validate!(plugin_class: nil)
233
- @children_index.each do |parent_path, children|
234
- # Rule: every non-root parent path that appears in the children index must have
235
- # a registered CommandSpec. A missing parent means commands_under(:x) was used
236
- # without a matching command :x declaration.
237
- unless parent_path.empty? || @specs.key?(parent_path)
238
- raise ArgumentError,
239
- "commands_under(#{parent_path.map(&:inspect).join(', ')}) used but #{parent_path.last.inspect} has no command declaration"
240
- end
241
- # Rule: an alias designates a single command, and does not hide a sibling command
242
- aliases = children.values.flat_map { |c| Array(c.aliases) }
243
- conflicts = aliases.select { |a| children.key?(a) || aliases.count(a) > 1 }.uniq
244
- raise ArgumentError, "#{parent_path.inspect}: alias conflicts with a sibling command or alias: #{conflicts.inspect}" unless conflicts.empty?
245
- end
246
-
247
- @specs.each_value do |spec|
248
- path = spec.full_path
249
-
250
- validate_arguments(path, spec.arguments, plugin_class)
251
- # Rule: methods called on the plugin instance exist
252
- if plugin_class
253
- {setup: spec.setup, condition: spec.condition}.each do |attribute, method_name|
254
- raise ArgumentError, "#{path.inspect}: no method #{method_name} on #{plugin_class} for #{attribute}:" unless method_name.nil? || instance_method?(plugin_class, method_name)
255
- end
256
- end
257
-
258
- if (mount = spec.mount)
259
- # Rule: a mount needs an instance method, no action, and must point to existing target nodes
260
- raise ArgumentError, "#{path.inspect}: mount requires instance:" if mount.instance.nil?
261
- # Mount arguments precede the arguments of the mounted command: they cannot be optional
262
- raise ArgumentError, "#{path.inspect}: mount arguments must be mandatory" unless mount.arguments.all?(&:mandatory)
263
- validate_arguments(path, mount.arguments, plugin_class)
264
- raise ArgumentError, "#{path.inspect}: mount and action: are exclusive" if spec.action
265
- raise ArgumentError, "#{path.inspect}: mount and read_only: are exclusive" if spec.read_only.eql?(true)
266
- raise ArgumentError, "#{path.inspect}: mount at #{mount.at.inspect} not found in #{mount.plugin}" unless mount.at.empty? || mount.registry[mount.at]
267
- target_ids = mount.registry.children_of(mount.at).keys
268
- unknown = Array(mount.only) + Array(mount.except) - target_ids
269
- raise ArgumentError, "#{path.inspect}: mount only/except unknown in #{mount.plugin}: #{unknown.inspect}" unless unknown.empty?
270
- instance_defined = plugin_class.nil? || instance_method?(plugin_class, mount.instance)
271
- raise ArgumentError, "#{path.inspect}: no method #{mount.instance} on #{plugin_class}" unless instance_defined
272
- next
273
- end
274
-
275
- # Rule: only a leaf is executed, so only a leaf is read-only
276
- raise ArgumentError, "#{path.inspect}: read_only: only on a leaf" if spec.read_only.eql?(true) && @children_index[path]&.any?
277
- next if @children_index[path]&.any? # intermediate node: skip
278
- action = spec.action
279
- if action.nil?
280
- next unless plugin_class
281
- # Rule: leaf commands with no explicit action must have a matching instance method
282
- action = CommandSpec.action_method(path)
283
- unless instance_method?(plugin_class, action)
284
- raise ArgumentError,
285
- "#{path.inspect}: no action: and no method #{action} on #{plugin_class}"
286
- end
287
- end
288
- action = plugin_class.instance_method(action) if action.is_a?(Symbol) && plugin_class && instance_method?(plugin_class, action)
289
- # Rule: the action receives the whole dispatch context as keywords (setup results, arguments),
290
- # so it must accept any keyword (`**`): a lambda or method with fixed arity would raise ArgumentError.
291
- # A non-lambda Proc ignores extra keywords.
292
- next if action.is_a?(Symbol) || (action.is_a?(Proc) && !action.lambda?)
293
- raise ArgumentError, "#{path.inspect}: action must accept any keyword (**), parameters: #{action.parameters.inspect}" unless action.parameters.any? { |kind, _| kind.eql?(:keyrest) }
294
- end
295
- self
296
- end
297
-
298
- private
299
-
300
- # As the parser: an exact name, else the unique name starting with word (e.g. `brow` for alias `browse` of `ls`).
301
- # @param children [Hash{Symbol => CommandSpec}] children of a node
302
- # @param word [Symbol] command line word
303
- # @return [Symbol, nil] id of the child designated by word: id or alias, or unique prefix of one
304
- def child_id(children, word)
305
- # Name (id or alias) => id
306
- names = children.each_with_object({}) do |(id, spec), h|
307
- h[id] = id
308
- Array(spec.aliases).each { |a| h[a] = id }
309
- end
310
- return names[word] if names.key?(word)
311
- matching = names.keys.select { |name| name.to_s.start_with?(word.to_s) }
312
- names[matching.first] if matching.length.eql?(1)
313
- end
314
-
315
- # @return [Boolean] true if plugin_class defines instance method name (public or private)
316
- def instance_method?(plugin_class, name)
317
- plugin_class.method_defined?(name) || plugin_class.private_method_defined?(name)
318
- end
319
-
320
- # Consistency of the positional arguments of a node, in reading order.
321
- # @param path [Array<Symbol>] node path, for error messages
322
- # @param arg_specs [Array<ArgumentSpec>] arguments of the node (or of its mount)
323
- # @param plugin_class [Class, nil] when given, verify that `lookup:` methods exist
324
- # @raise [ArgumentError] on any violation
325
- def validate_arguments(path, arg_specs, plugin_class)
326
- previous = nil
327
- Array(arg_specs).each do |arg|
328
- where = "#{path.inspect}: argument #{arg.name}"
329
- # Rule: an argument following an optional one, or one that takes all remaining arguments, is never read reliably
330
- raise ArgumentError, "#{where}: mandatory after optional #{previous.name}" if previous && arg.mandatory && !previous.mandatory
331
- raise ArgumentError, "#{where}: after #{previous.name}, which takes all remaining arguments" if previous&.multiple.eql?(true)
332
- raise ArgumentError, "#{where}: complete: #{arg.complete.inspect} is not one of #{Complete::KINDS.inspect}" unless arg.complete.nil? || Complete::KINDS.include?(arg.complete)
333
- unless arg.lookup.nil?
334
- # Rule: the percent-selector lookup is only used for identifiers
335
- raise ArgumentError, "#{where}: lookup: requires type: :identifier" unless arg.type.eql?(:identifier)
336
- raise ArgumentError, "#{where}: no method #{arg.lookup} on #{plugin_class} for lookup:" if arg.lookup.is_a?(Symbol) && plugin_class && !instance_method?(plugin_class, arg.lookup)
337
- end
338
- previous = arg
339
- end
340
- end
341
-
342
- # @param path [Array<Symbol>] non-empty path in this registry's namespace
343
- # @return [Array<ArgumentSpec>] arguments of the mount exposing the last segment of path, if any
344
- def mount_arguments(path)
345
- registry, parent = resolve(path[0..-2])
346
- return registry.send(:mount_arguments, parent + [path.last]) unless registry.equal?(self)
347
- mount = @specs[parent]&.mount
348
- return [] if mount.nil? || @children_index[parent]&.key?(path.last) || !mount.accepts?(path.last)
349
- mount.arguments
350
- end
351
-
352
- # Identity of the sub-tree exposed at path: the mount point for a mount node, else the owning node.
353
- # @return [Array(Integer, Array<Symbol>)]
354
- def subtree_key(path)
355
- registry, local_path = resolve(path)
356
- mount = registry.mount_of(local_path)
357
- mount ? [mount.registry.object_id, mount.at] : [registry.object_id, local_path]
358
- end
359
-
360
- def initialize
361
- # Keyed by Array<Symbol> full path
362
- @specs = {}
363
- # Keyed by Symbol option name
364
- @option_specs = {}
365
- # Children index: parent Array<Symbol> -> Hash{child_id Symbol => CommandSpec}
366
- # Built incrementally in register(); enables O(1) children_of lookups.
367
- @children_index = {}
368
- end
369
- end
370
- end
371
- end
@@ -1,273 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # SPDX-FileCopyrightText: IBM Corp.
4
- # SPDX-License-Identifier: Apache-2.0
5
-
6
- require_relative '../schema/registry'
7
- require_relative 'option_types'
8
- require_relative 'security'
9
-
10
- module Aspera
11
- module Cli
12
- # Declares a positional argument consumed by a command.
13
- # Declaration order in a command's `arguments:` array defines parsing order.
14
- # Mandatory arguments must come before optional ones.
15
- #
16
- # @!attribute name [Symbol] Name used in help and error messages
17
- # @!attribute description [String] User-facing description
18
- # @!attribute type [Class, Array<Class>, :identifier, nil] Validated type; :identifier triggers instance_identifier.
19
- # Default: String (unless allowed:); explicit nil accepts any value
20
- # @!attribute mandatory [Boolean] Default true; optional args must come after all mandatory ones
21
- # @!attribute multiple [Boolean, String] true: consume all remaining; String: consume until named marker
22
- # @!attribute default [Object, nil] Default value when mandatory: false and no argument provided
23
- # @!attribute schema [String, nil] JSON schema name for validation and --help introspection
24
- # @!attribute bulk [Boolean] When true, wraps read+loop for bulk mode (Array if --bulk yes)
25
- # @!attribute lookup [Symbol, Proc, nil] Percent-selector resolver (only used when type: :identifier).
26
- # Symbol → resolved via send(lookup, field, value, **ctx).
27
- # Proc/lambda → called via instance_exec(field, value, **ctx, &lookup).
28
- # Style: use Symbol for named methods; ->(){} for 1-liners; lambda do…end for 2–3 statements.
29
- # @!attribute allowed [Array<Symbol>, nil] Allowed Symbol values; when set, type is forced to Symbol and accept_list is applied
30
- # @!attribute interactive [Boolean] When true, prompts for this argument (only) when no CLI args are provided
31
- # @!attribute evaluate [Symbol] How the value is read, one of `EVALUATIONS`. Default `:extended`.
32
- # `:extended`: extended value (`@json:`, `@file:`, `@val:`...); a value without prefix stays a string.
33
- # `:smart`: `true`/`yes`/`false`/`no` and numbers are converted, else extended value (as dotted options).
34
- # `:none`: the string as typed, not evaluated (e.g. `@env:`).
35
- # @!attribute complete [Symbol, nil] Values proposed by shell completion, one of `Complete::KINDS` (e.g. `:file`)
36
- # @!attribute omit_absent [Boolean] For an optional argument: when not given, it is not passed to the action,
37
- # so that the action (with its own default) can tell it from a value `nil` (`@none:`)
38
- # Ways to evaluate the value of an argument, see `ArgumentSpec#evaluate`
39
- EVALUATIONS = %i[extended smart none].freeze
40
-
41
- ArgumentSpec = Struct.new(
42
- :name,
43
- :description,
44
- :type,
45
- :mandatory,
46
- :multiple,
47
- :default,
48
- :schema,
49
- :bulk,
50
- :lookup,
51
- :allowed,
52
- :interactive,
53
- :evaluate,
54
- :complete,
55
- :omit_absent,
56
- keyword_init: true
57
- ) do
58
- def initialize(**kwargs)
59
- kwargs[:mandatory] = true if kwargs[:mandatory].nil?
60
- kwargs[:multiple] = false if kwargs[:multiple].nil?
61
- kwargs[:bulk] = false if kwargs[:bulk].nil?
62
- kwargs[:interactive] = false if kwargs[:interactive].nil?
63
- kwargs[:evaluate] = :extended if kwargs[:evaluate].nil?
64
- kwargs[:omit_absent] = false if kwargs[:omit_absent].nil?
65
- raise ArgumentError, "omit_absent: only for an optional argument: #{kwargs[:name]}" if kwargs[:omit_absent] && kwargs[:mandatory]
66
- kwargs[:type] = String unless kwargs.key?(:type) || kwargs[:allowed]
67
- raise ArgumentError, "evaluate: #{kwargs[:evaluate].inspect}, expecting one of: #{EVALUATIONS.join(', ')}" unless EVALUATIONS.include?(kwargs[:evaluate])
68
- super
69
- end
70
-
71
- # Syntax of argument for help, e.g. `<name>`, `[<name>]`, `<paths...>`, `<account:Hash>`.
72
- # Type is shown only when the argument is not free text.
73
- # @return [String]
74
- def syntax
75
- token = allowed ? allowed.join('|') : name.to_s
76
- token += '...' if multiple
77
- types = Array(type).grep(Class)
78
- token += ":#{types.map(&:name).join('|')}" unless allowed || types.empty? || types.include?(String)
79
- mandatory ? "<#{token}>" : "[<#{token}>]"
80
- end
81
- end
82
-
83
- # Declares an option referenced by name from command declarations.
84
- # Mirrors the existing `options.declare` call but associates the option with
85
- # the command(s) that use it.
86
- #
87
- # @!attribute name [Symbol] Option name (same symbol used in options.declare)
88
- # @!attribute description [String, nil] User-facing description; nil derives it from schema:
89
- # @!attribute allowed [Array, nil] Allowed values (forwarded to options.declare)
90
- # @!attribute default [Object, nil] Default value
91
- # @!attribute short [String, nil] Single-character short form (e.g. 'x')
92
- # @!attribute on_set [Symbol, Proc, #call, nil] Called with the new value each time the value is set
93
- # (for a flag: called without argument when the flag is found)
94
- # - Symbol: method of the plugin instance
95
- # - Proc: executed with instance_exec on the plugin instance
96
- # - other: object responding to `call`, e.g. `Log.instance.method(:level=)`
97
- # - nil: no callback, the value is read with `get_option`
98
- # @!attribute shorthand [String, nil] For a `Hash` option: a `String` value is stored as `{shorthand => value}`
99
- # @!attribute deprecation [Hash, nil] Forwarded to options.declare as deprecation: `{last:, message:}`
100
- # @!attribute schema [String, nil] JSON schema name; also derives description when nil
101
- # @!attribute complete [Symbol, nil] Values proposed by shell completion, one of `Complete::KINDS` (e.g. `:file`)
102
- # @!attribute security [Symbol, nil] Most restrictive security level at which the option is available (`:low`: executes code), see `Security`
103
- OptionSpec = Struct.new(
104
- :name,
105
- :description,
106
- :allowed,
107
- :default,
108
- :short,
109
- :on_set,
110
- :shorthand,
111
- :deprecation,
112
- :schema,
113
- :complete,
114
- :security,
115
- keyword_init: true
116
- ) do
117
- # Declare this option on a parser, resolving the `on_set` callback.
118
- # @param parser [Parser] Parser to declare the option on
119
- # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks (plugin instance); nil: such callbacks are not bound
120
- # @return [void]
121
- def declare_on(parser, target: nil)
122
- parser.declare(
123
- name,
124
- description: description,
125
- short: short,
126
- allowed: allowed,
127
- default: default,
128
- on_set: resolved_on_set(target),
129
- shorthand: shorthand,
130
- deprecation: deprecation,
131
- schema: schema,
132
- complete: complete,
133
- security: security
134
- )
135
- end
136
-
137
- private
138
-
139
- # @param target [Object, nil] Object for Symbol and Proc `on_set` callbacks
140
- # @return [#call, nil] `on_set` callback for `Parser#declare`
141
- def resolved_on_set(target)
142
- case on_set
143
- when Symbol then target&.method(on_set)
144
- when Proc
145
- return if target.nil?
146
- proc_on_set = on_set
147
- ->(*value) { target.instance_exec(*value, &proc_on_set) }
148
- else on_set
149
- end
150
- end
151
- end
152
-
153
- # Declares that a command node exposes a sub-tree of another plugin class.
154
- # The mounted children appear in the host registry (dispatch, --help, completion)
155
- # as if they were declared by the host; host children with the same id take precedence.
156
- #
157
- # @!attribute plugin [Class] Target plugin class (subclass of Plugins::Base)
158
- # @!attribute at [Array<Symbol>] Path in the target registry whose children are mounted ([] = root)
159
- # @!attribute instance [Symbol] Host instance method called with **ctx, returning the target plugin
160
- # instance, or [instance, ctx] where ctx seeds the target dispatch
161
- # (it replaces what the setups of `at` and its ancestors would provide)
162
- # @!attribute only [Array<Symbol>, nil] Restrict mounted children to these ids
163
- # @!attribute except [Array<Symbol>, nil] Exclude these ids from mounted children
164
- # @!attribute arguments [Array<ArgumentSpec>] Arguments read by the host after the mounted command, before its own
165
- # arguments; resolved values are passed to `instance`
166
- # (e.g. `packages ls <package_id> <path>`)
167
- MountSpec = Struct.new(
168
- :plugin,
169
- :at,
170
- :instance,
171
- :only,
172
- :except,
173
- :arguments,
174
- keyword_init: true
175
- ) do
176
- def initialize(**kwargs)
177
- kwargs[:at] = Array(kwargs[:at]).freeze
178
- kwargs[:arguments] = Array(kwargs[:arguments]).map { |a| a.is_a?(Hash) ? ArgumentSpec.new(**a) : a }.freeze
179
- super
180
- end
181
-
182
- # @return [CommandRegistry] registry of the target plugin class
183
- def registry
184
- plugin.command_registry
185
- end
186
-
187
- # @param id [Symbol] id of a child of `at` in the target registry
188
- # @return [Boolean] true if this child is exposed by the mount
189
- def accepts?(id)
190
- (only.nil? || only.include?(id)) && !except&.include?(id)
191
- end
192
- end
193
-
194
- # Ids of the commands read-only by default (`read_only: :default`): they change nothing
195
- READ_ONLY_IDS = %i[list show status info health ls browse find].freeze
196
-
197
- # Declares a single command node in the flat registry.
198
- #
199
- # @!attribute id [Symbol] Unique identifier within its parent's namespace
200
- # @!attribute parent [Symbol, Array<Symbol>, nil] Full path to parent; nil for root commands
201
- # @!attribute description [String] User-facing help text
202
- # @!attribute arguments [Array<ArgumentSpec>] Positional arguments, in order.
203
- # The first ArgumentSpec with type: :identifier is treated as the instance
204
- # identifier for intermediate nodes (consumed in Phase A) and leaf nodes.
205
- # @!attribute action [Symbol, Proc, nil] Instance method (Symbol) or inline block (Proc) called when this is a leaf command
206
- # @!attribute setup [Symbol, nil] Instance method called before dispatching to children; returns Hash merged into ctx
207
- # @!attribute aliases [Array<Symbol>, nil] Alternative names accepted for this command (each resolves to this command's id)
208
- # @!attribute transfer_paths [:send, :receive, nil] File-list resolution delegated to TransferAgent; mutually exclusive with arguments
209
- # @!attribute condition [Symbol, nil] Instance method returning Boolean; if false command is hidden from dispatch
210
- # @!attribute query_schema [String, nil] Schema path for --query help; when set, the runner hints `--query=help`
211
- # @!attribute mount [MountSpec, Hash, nil] Expose children of another plugin's registry under this node
212
- # @!attribute security [Symbol, nil] Most restrictive security level at which the command is available (`:low`: executes code), see `Security`
213
- # @!attribute read_only [Boolean, :default] Leaf only: the command changes nothing (on the server or locally), so it can be repeated (option `poll`).
214
- # `:default` (default): read-only if the id is one of READ_ONLY_IDS (`list`, `show`, ...)
215
- CommandSpec = Struct.new(
216
- :id,
217
- :parent,
218
- :description,
219
- :arguments,
220
- :action,
221
- :setup,
222
- :aliases,
223
- :transfer_paths,
224
- :condition,
225
- :query_schema,
226
- :mount,
227
- :security,
228
- :read_only,
229
- keyword_init: true
230
- ) do
231
- def initialize(**kwargs)
232
- Aspera.assert_values(kwargs[:security], Security::LEVELS + [nil]) { "#{kwargs[:id]}: security" }
233
- kwargs[:read_only] = :default if kwargs[:read_only].nil?
234
- Aspera.assert_values(kwargs[:read_only], [true, false, :default]) { "#{kwargs[:id]}: read_only" }
235
- # Coerce each element of arguments: from Hash to ArgumentSpec if needed
236
- if kwargs[:arguments]
237
- kwargs[:arguments] = kwargs[:arguments].map do |a|
238
- a.is_a?(Hash) ? ArgumentSpec.new(**a) : a
239
- end
240
- end
241
- kwargs[:mount] = MountSpec.new(**kwargs[:mount]) if kwargs[:mount].is_a?(Hash)
242
- super
243
- end
244
-
245
- class << self
246
- # Derive the implicit action method name from a path array.
247
- # e.g. [:admin, :user, :list] -> :action_admin_user_list
248
- # @param path [Array<Symbol>]
249
- # @return [Symbol]
250
- def action_method(path)
251
- :"action_#{path.join('_')}"
252
- end
253
- end
254
-
255
- # @return [Boolean] `true` if the command changes nothing: explicit `read_only`, or from its id (READ_ONLY_IDS)
256
- def read_only?
257
- read_only.eql?(:default) ? READ_ONLY_IDS.include?(id) : read_only
258
- end
259
-
260
- # Compute the full path as Array<Symbol> from parent + id.
261
- # @return [Array<Symbol>]
262
- def full_path
263
- Array(parent) + [id]
264
- end
265
-
266
- # Derive the implicit action method name from the full path.
267
- # @return [Symbol]
268
- def action_method_name
269
- self.class.action_method(full_path)
270
- end
271
- end
272
- end
273
- end