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
@@ -13,110 +13,110 @@ require 'yaml'
13
13
 
14
14
  module Aspera
15
15
  module Cli
16
- # Positional (non-option) command line token.
17
- class Argument
18
- # @return [String] the raw argument value
19
- attr_reader :value
20
- # @return [Option, nil] option token claiming this token as its value (`--opt value` form)
21
- attr_accessor :owner
22
- # @return [Boolean] `true` once used, as positional argument or as option value
23
- attr_accessor :consumed
24
-
25
- def initialize(value)
26
- @value = value
27
- @owner = nil
28
- @consumed = false
29
- end
30
-
31
- # @return [Boolean] `true` if available as positional argument
32
- def positional? = !@consumed && @owner.nil?
16
+ # Command line split in tokens, in original order.
17
+ # Tokens are never removed, only marked as consumed, so that positions are kept.
18
+ #
19
+ # An option without inline value claims the next token as its value (`--opt val`, `-O val`),
20
+ # unless that token looks like an option.
21
+ # If the option turns out to be a flag, the claimed token is given back to positional arguments.
22
+ class CommandLine
23
+ # Positional (non-option) command line token.
24
+ class Argument
25
+ # @return [String] the raw argument value
26
+ attr_reader :value
27
+ # @return [Option, nil] option token claiming this token as its value (`--opt value` form)
28
+ attr_accessor :owner
29
+ # @return [Boolean] `true` once used, as positional argument or as option value
30
+ attr_accessor :consumed
31
+
32
+ def initialize(value)
33
+ @value = value
34
+ @owner = nil
35
+ @consumed = false
36
+ end
33
37
 
34
- # @return [String] raw argument value
35
- def to_s = @value
36
- end
38
+ # @return [Boolean] `true` if available as positional argument
39
+ def positional? = !@consumed && @owner.nil?
37
40
 
38
- # Option command line token (long or short form).
39
- class Option
40
- # @return [String] raw token as it appeared in argv (e.g. "--log-level=debug", "-Pval")
41
- attr_reader :raw
42
- # @return [String, nil] option name with underscores (e.g. "log_level"), nil for short options
43
- attr_reader :name
44
- # @return [String, nil] single-char short option letter (e.g. "P"), nil for long options
45
- attr_reader :short_char
46
- # @return [Array<String>, nil] sub-keys for dot-path notation (e.g. ["field"] for --custom.field)
47
- attr_reader :dot_path
48
- # @return [String, nil] value given in the same token (`--opt=val` or `-Oval`)
49
- attr_reader :inline_value
50
- # @return [Argument, nil] next token, claimed as value when there is no inline value (`--opt val` or `-O val`)
51
- attr_accessor :value_token
52
- # @return [Boolean] `true` once applied to a declared option
53
- attr_accessor :consumed
54
- # @return [Symbol, nil] option this token was resolved to, when `name` is an abbreviation
55
- attr_accessor :abbreviation_of
56
-
57
- def initialize(raw:, name: nil, short_char: nil, dot_path: nil, inline_value: nil)
58
- @raw = raw
59
- @name = name
60
- @short_char = short_char
61
- @dot_path = dot_path
62
- @inline_value = inline_value
63
- @value_token = nil
64
- @consumed = false
65
- @abbreviation_of = nil
41
+ # @return [String] raw argument value
42
+ def to_s = @value
66
43
  end
67
44
 
68
- # @return [Boolean] `true` if value is in the same token
69
- def inline? = !@inline_value.nil?
45
+ # Option command line token (long or short form).
46
+ class Option
47
+ # @return [String] raw token as it appeared in argv (e.g. "--log-level=debug", "-Pval")
48
+ attr_reader :raw
49
+ # @return [String, nil] option name with underscores (e.g. "log_level"), nil for short options
50
+ attr_reader :name
51
+ # @return [String, nil] single-char short option letter (e.g. "P"), nil for long options
52
+ attr_reader :short_char
53
+ # @return [Array<String>, nil] sub-keys for dot-path notation (e.g. ["field"] for --custom.field)
54
+ attr_reader :dot_path
55
+ # @return [String, nil] value given in the same token (`--opt=val` or `-Oval`)
56
+ attr_reader :inline_value
57
+ # @return [Argument, nil] next token, claimed as value when there is no inline value (`--opt val` or `-O val`)
58
+ attr_accessor :value_token
59
+ # @return [Boolean] `true` once applied to a declared option
60
+ attr_accessor :consumed
61
+ # @return [Symbol, nil] option this token was resolved to, when `name` is an abbreviation
62
+ attr_accessor :abbreviation_of
63
+
64
+ def initialize(raw:, name: nil, short_char: nil, dot_path: nil, inline_value: nil)
65
+ @raw = raw
66
+ @name = name
67
+ @short_char = short_char
68
+ @dot_path = dot_path
69
+ @inline_value = inline_value
70
+ @value_token = nil
71
+ @consumed = false
72
+ @abbreviation_of = nil
73
+ end
70
74
 
71
- # @return [String, nil] inline value, or value of next token
72
- def value = @inline_value || @value_token&.value
75
+ # @return [Boolean] `true` if value is in the same token
76
+ def inline? = !@inline_value.nil?
73
77
 
74
- # @return [String] raw token, with declared secret value hidden (logs, messages)
75
- def raw_hidden = inline? ? "#{@raw.delete_suffix(@inline_value)}#{Secret::Hider.instance.hidden_copy(@inline_value)}" : @raw
78
+ # @return [String, nil] inline value, or value of next token
79
+ def value = @inline_value || @value_token&.value
76
80
 
77
- # @return [String] raw token, followed by its separate value if any, with declared secret value hidden (logs, messages)
78
- def to_s = @value_token.nil? ? raw_hidden : "#{@raw} #{Secret::Hider.instance.hidden_copy(@value_token.value)}"
81
+ # @return [String] raw token, with declared secret value hidden (logs, messages)
82
+ def raw_hidden = inline? ? "#{@raw.delete_suffix(@inline_value)}#{Secret::Hider.instance.hidden_copy(@inline_value)}" : @raw
79
83
 
80
- class << self
81
- # @param token [String] command line token
82
- # @return [Boolean] `true` if token is an option, i.e. not `-`, `--`, or a negative number
83
- def option?(token)
84
- token.match?(/\A-\D/) && !token.eql?(STOP)
85
- end
84
+ # @return [String] raw token, followed by its separate value if any, with declared secret value hidden (logs, messages)
85
+ def to_s = @value_token.nil? ? raw_hidden : "#{@raw} #{Secret::Hider.instance.hidden_copy(@value_token.value)}"
86
86
 
87
- # Build an Option from a raw token
88
- # @param raw [String] e.g. "--log-level=debug", "--custom.field", "-P", "-Pval"
89
- # @return [Option]
90
- def parse(raw)
91
- if raw.start_with?(PREFIX)
92
- name_raw, value = raw.delete_prefix(PREFIX).split(VALUE_SEP, 2)
93
- root, *dot_path = name_raw.to_s.split(DotContainer::SEPARATOR)
94
- new(raw: raw, name: root.to_s.gsub(NAME_SEP_LINE, NAME_SEP_SYMBOL), dot_path: dot_path.empty? ? nil : dot_path, inline_value: value)
95
- else
96
- new(raw: raw, short_char: raw[1], inline_value: raw.length > 2 ? raw[2..] : nil)
87
+ class << self
88
+ # @param token [String] command line token
89
+ # @return [Boolean] `true` if token is an option, i.e. not `-`, `--`, or a negative number
90
+ def option?(token)
91
+ token.match?(/\A-\D/) && !token.eql?(STOP)
92
+ end
93
+
94
+ # Build an Option from a raw token
95
+ # @param raw [String] e.g. "--log-level=debug", "--custom.field", "-P", "-Pval"
96
+ # @return [Option]
97
+ def parse(raw)
98
+ if raw.start_with?(PREFIX)
99
+ name_raw, value = raw.delete_prefix(PREFIX).split(VALUE_SEP, 2)
100
+ root, *dot_path = name_raw.to_s.split(DotContainer::SEPARATOR)
101
+ new(raw: raw, name: root.to_s.gsub(NAME_SEP_LINE, NAME_SEP_SYMBOL), dot_path: dot_path.empty? ? nil : dot_path, inline_value: value)
102
+ else
103
+ new(raw: raw, short_char: raw[1], inline_value: raw.length > 2 ? raw[2..] : nil)
104
+ end
97
105
  end
98
106
  end
99
- end
100
107
 
101
- # Option name separator on command line (e.g. `--option-name`, the `-` between words)
102
- NAME_SEP_LINE = '-'
103
- # Option name separator in code/symbol (e.g. `:option_name`, the `_` between words)
104
- NAME_SEP_SYMBOL = '_'
105
- # Separator between option name and its inline value (e.g. `--opt=val`, the `=`)
106
- VALUE_SEP = '='
107
- # Long-option prefix (e.g. `--opt`)
108
- PREFIX = '--'
109
- # When alone, stops option processing: following tokens are positional arguments
110
- STOP = '--'
111
- end
108
+ # Option name separator on command line (e.g. `--option-name`, the `-` between words)
109
+ NAME_SEP_LINE = '-'
110
+ # Option name separator in code/symbol (e.g. `:option_name`, the `_` between words)
111
+ NAME_SEP_SYMBOL = '_'
112
+ # Separator between option name and its inline value (e.g. `--opt=val`, the `=`)
113
+ VALUE_SEP = '='
114
+ # Long-option prefix (e.g. `--opt`)
115
+ PREFIX = '--'
116
+ # When alone, stops option processing: following tokens are positional arguments
117
+ STOP = '--'
118
+ end
112
119
 
113
- # Command line split in tokens, in original order.
114
- # Tokens are never removed, only marked as consumed, so that positions are kept.
115
- #
116
- # An option without inline value claims the next token as its value (`--opt val`, `-O val`),
117
- # unless that token looks like an option.
118
- # If the option turns out to be a flag, the claimed token is given back to positional arguments.
119
- class CommandLine
120
120
  # Decoders of extended values whose content is checked for secrets by key name
121
121
  STRUCTURED_DECODERS = {
122
122
  '@json:' => ->(v) { JSON.parse(v) },
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: IBM Corp.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ module Aspera
7
+ module Cli
8
+ # Values proposed by shell completion for an option, an argument or a schema key (`complete:`, `x-cli-complete`),
9
+ # when they are not a list of allowed values:
10
+ # - `file`: local file or folder
11
+ # - `folder`: local folder
12
+ # - `destination_folder`: local folder, unless the command sends files (the destination is then remote)
13
+ # - `preset`: name of option preset
14
+ # - `preset_parameter`: parameter of the option preset given as first argument of the command
15
+ # - `transfer_job`: identifier of an asynchronous transfer job
16
+ module Complete
17
+ KINDS = %i[file folder destination_folder preset preset_parameter transfer_job].freeze
18
+ # Kinds that complete to a local path chosen by the client: an argument with one of these must declare `access:` (see `Argument`)
19
+ LOCAL_PATH_KINDS = %i[file folder].freeze
20
+ end
21
+ end
22
+ end
@@ -11,6 +11,7 @@ require_relative 'special_values'
11
11
  require_relative '../environment'
12
12
  require_relative '../schema/documentation'
13
13
  require_relative '../schema/registry'
14
+ require_relative '../units/timestamp'
14
15
 
15
16
  module Aspera
16
17
  module Cli
@@ -40,11 +41,11 @@ module Aspera
40
41
  # @!attribute option [Option, nil] option token whose value is built, `nil` for a positional argument
41
42
  Collecting = Struct.new(:marker, :assigned, :option, keyword_init: true)
42
43
  # Command reached by the positional words
43
- # @!attribute registry [CommandRegistry, nil] registry of plugin, `nil` at root
44
+ # @!attribute registry [Command::Registry, nil] registry of plugin, `nil` at root
44
45
  # @!attribute path [Array<Symbol>, nil] command path, `nil` if words are not a command
45
46
  # @!attribute arguments [Array<String>] arguments given to the command
46
47
  Position = Struct.new(:registry, :path, :arguments, keyword_init: true) do
47
- # @return [CommandSpec, nil] command reached
48
+ # @return [Command, nil] command reached
48
49
  def spec = path && registry[path]
49
50
  end
50
51
  # Value starting a structure built with `@:`: the optional text after `:` is the end marker
@@ -57,14 +58,12 @@ module Aspera
57
58
  MODIFIERS_DECODING = %i[base64 csvt json lines list re ruby s yaml zlib].freeze
58
59
  # Modifiers whose value is not evaluated
59
60
  MODIFIERS_LITERAL = %i[val extend].freeze
60
- # Modes of `@stdin:`
61
- STDIN_MODES = ['', 'bin', 'chomp'].freeze
62
61
  # End of sentence in a description: a period, not of `e.g.` or `i.e.`, followed by a word not in lower case
63
62
  REGEX_SENTENCE_END = /(?<!\be\.g|\bi\.e)\.\s+(?=[^a-z])/
64
63
  # Maximum length of a hint listing the keys of a structure
65
64
  HINT_MAX_LENGTH = 72
66
65
  private_constant :COMPLETION_SHELLS, :COMPLETION_FOLDER, :Completion, :Collecting, :Position, :REGEX_EXTEND_ARGS, :REGEX_MODIFIER,
67
- :MARKER_MODIFIER, :MODIFIERS_DECODING, :MODIFIERS_LITERAL, :STDIN_MODES, :REGEX_SENTENCE_END, :HINT_MAX_LENGTH
66
+ :MARKER_MODIFIER, :MODIFIERS_DECODING, :MODIFIERS_LITERAL, :REGEX_SENTENCE_END, :HINT_MAX_LENGTH
68
67
 
69
68
  # List words that can follow the given words, one per line.
70
69
  # When a value is expected but cannot be proposed, its type is listed (e.g. `<String>`), or `<file>` (or `<folder>`) for a local path.
@@ -129,9 +128,9 @@ module Aspera
129
128
  # @param current [String] word at cursor
130
129
  # @return [String] part of the word that precedes the value of an option given in the same word: `--opt=` or `-O`, empty if none
131
130
  def completion_inline_prefix(current)
132
- return current[0..current.index(Option::VALUE_SEP)] if current.start_with?(Option::PREFIX) && current.include?(Option::VALUE_SEP)
133
- return '' if current.start_with?(Option::PREFIX) || !Option.option?(current)
134
- short = completion_option(Option.parse(current[0, 2]))
131
+ return current[0..current.index(CommandLine::Option::VALUE_SEP)] if current.start_with?(CommandLine::Option::PREFIX) && current.include?(CommandLine::Option::VALUE_SEP)
132
+ return '' if current.start_with?(CommandLine::Option::PREFIX) || !CommandLine::Option.option?(current)
133
+ short = completion_option(CommandLine::Option.parse(current[0, 2]))
135
134
  short.nil? || short.flag? ? '' : current[0, 2]
136
135
  end
137
136
 
@@ -197,10 +196,10 @@ module Aspera
197
196
  Completion.new(candidates: candidates)
198
197
  end
199
198
 
200
- # @param registry [CommandRegistry] registry of plugin
199
+ # @param registry [Command::Registry] registry of plugin
201
200
  # @param path [Array<Symbol>] command path
202
201
  # @param given [Integer] number of arguments given to the command
203
- # @return [ArgumentSpec, nil] argument expected after the given ones
202
+ # @return [Argument, nil] argument expected after the given ones
204
203
  def completion_next_argument(registry, path, given)
205
204
  arguments = registry.arguments_at(path)
206
205
  return arguments[given] if given < arguments.length
@@ -225,7 +224,7 @@ module Aspera
225
224
  path, given = registry.command_position(positional[1..-2].map(&:to_sym))
226
225
  completion_next_argument(registry, path, given)&.schema unless path.nil?
227
226
  end
228
- if (index = value.index(Option::VALUE_SEP))
227
+ if (index = value.index(CommandLine::Option::VALUE_SEP))
229
228
  return completion_key_value(schema, value[0...index].split(DotContainer::SEPARATOR), value[(index + 1)..], position).prefixed(value[0..index])
230
229
  end
231
230
  end_marker = collecting.assigned.empty? ? [] : [[collecting.marker, 'End of structure built with @:']]
@@ -245,7 +244,7 @@ module Aspera
245
244
  if join_next
246
245
  result[-1] += word
247
246
  join_next = false
248
- elsif word.eql?(Option::VALUE_SEP) && result.last&.start_with?(Option::PREFIX) && !result.last.include?(Option::VALUE_SEP)
247
+ elsif word.eql?(CommandLine::Option::VALUE_SEP) && result.last&.start_with?(CommandLine::Option::PREFIX) && !result.last.include?(CommandLine::Option::VALUE_SEP)
249
248
  result[-1] += word
250
249
  join_next = true
251
250
  else
@@ -267,11 +266,11 @@ module Aspera
267
266
  collecting = nil
268
267
  stop = false
269
268
  words.each do |word|
270
- if !stop && word.eql?(Option::STOP)
269
+ if !stop && word.eql?(CommandLine::Option::STOP)
271
270
  stop = true
272
271
  waiting = nil
273
- elsif !stop && Option.option?(word)
274
- tok = Option.parse(word)
272
+ elsif !stop && CommandLine::Option.option?(word)
273
+ tok = CommandLine::Option.parse(word)
275
274
  # `--opt=` at end of line (from bash split): value is being typed
276
275
  waiting = (tok.inline? && !tok.inline_value.empty?) || completion_option(tok)&.flag? ? nil : tok
277
276
  collecting = completion_collecting_start(tok.inline_value, tok) || collecting
@@ -283,7 +282,7 @@ module Aspera
283
282
  if word.eql?(collecting.marker)
284
283
  collecting = nil
285
284
  else
286
- collecting.assigned.push(word.split(Option::VALUE_SEP, 2).first)
285
+ collecting.assigned.push(word.split(CommandLine::Option::VALUE_SEP, 2).first)
287
286
  end
288
287
  else
289
288
  positional.push(word)
@@ -303,13 +302,13 @@ module Aspera
303
302
  end
304
303
 
305
304
  # @param tok [Option] option token
306
- # @return [OptionValue, nil] declared option designated by the token
305
+ # @return [Option::Value, nil] declared option designated by the token
307
306
  def completion_option(tok)
308
307
  return options.declared_options.values.find { |o| o.short.eql?(tok.short_char) } if tok.short_char
309
308
  options.declared_options[tok.name.to_sym]
310
309
  end
311
310
 
312
- # @param option [OptionValue] declared option
311
+ # @param option [Option::Value] declared option
313
312
  # @param position [Position] command reached
314
313
  # @return [String, nil] schema of the value of option: the one of option `query` depends on the command
315
314
  def completion_option_schema(option, position)
@@ -350,10 +349,12 @@ module Aspera
350
349
  # @param key [String] key of a `String` value
351
350
  # @return [Array(Array<String>, Symbol)] allowed values of the key, from its schema or the discriminator of its variants, and kind of value
352
351
  def completion_shorthand(schema, key)
353
- row = completion_schema_row(schema, [key])
354
- return [completion_row_values(row), row['complete']&.to_sym] unless row.nil?
355
352
  node = Schema::Registry.instance.reader(schema).current
356
- [(node.dig('discriminator', 'mapping')&.keys if node.dig('discriminator', 'propertyName').eql?(key)), nil]
353
+ # Key that selects the variant: its values are those of the variants
354
+ return [node.dig('discriminator', 'mapping')&.keys, nil] if node.dig('discriminator', 'propertyName').eql?(key)
355
+ row = completion_schema_row(schema, [key])
356
+ return [nil, nil] if row.nil?
357
+ [completion_row_values(row), row['complete']&.to_sym]
357
358
  rescue StandardError
358
359
  [nil, nil]
359
360
  end
@@ -368,7 +369,7 @@ module Aspera
368
369
  option = options.declared_options[Parser.option_line_to_name(match[1]).to_sym]
369
370
  return Completion.new(candidates: []) if option.nil?
370
371
  rows = completion_schema_rows(completion_option_schema(option, position))
371
- Completion.new(candidates: completion_schema_keys(rows, match[2])).prefixed("#{Option::PREFIX}#{match[1]}#{DotContainer::SEPARATOR}")
372
+ Completion.new(candidates: completion_schema_keys(rows, match[2])).prefixed("#{CommandLine::Option::PREFIX}#{match[1]}#{DotContainer::SEPARATOR}")
372
373
  end
373
374
 
374
375
  # Keys of a structure at the level of the path typed: `key=` for a value, `key.` for a structure, `key.0.` for a list of structures.
@@ -388,10 +389,10 @@ module Aspera
388
389
  suffix =
389
390
  if names.any? { |n| n.start_with?("#{row['name']}#{DotContainer::SEPARATOR}") } then DotContainer::SEPARATOR
390
391
  elsif names.any? { |n| n.start_with?("#{row['name']}[]#{DotContainer::SEPARATOR}") } then "#{DotContainer::SEPARATOR}0#{DotContainer::SEPARATOR}"
391
- else Option::VALUE_SEP
392
+ else CommandLine::Option::VALUE_SEP
392
393
  end
393
394
  key = "#{parents}#{path.last}"
394
- next if suffix.eql?(Option::VALUE_SEP) && assigned.include?(key)
395
+ next if suffix.eql?(CommandLine::Option::VALUE_SEP) && assigned.include?(key)
395
396
  description = completion_description(row['description']) || completion_type(row['type'])
396
397
  description = [description, '(required)'].compact.join(' ') if required && row['required']
397
398
  ["#{key}#{suffix}", description, required && row['required']]
@@ -489,7 +490,8 @@ module Aspera
489
490
  when :file, :path then Completion.new(candidates: [], files: complete.eql?(:folder) ? :folder : :file)
490
491
  when :preset then Completion.new(candidates: completion_preset_names(rest))
491
492
  when :env then Completion.new(candidates: ENV.keys.sort.map { |k| [k, nil] })
492
- when :stdin then Completion.new(candidates: STDIN_MODES.map { |m| [m, nil] })
493
+ when :stdin then Completion.new(candidates: ExtendedValue::STDIN_MODES.map { |m| [m, nil] })
494
+ when :date then Completion.new(candidates: Units::Timestamp::KEYWORDS.to_a)
493
495
  when *MODIFIERS_DECODING then Completion.new(candidates: [])
494
496
  else Completion.new(candidates: [], hint: ExtendedValue.instance.description(last))
495
497
  end
@@ -548,7 +550,7 @@ module Aspera
548
550
  type.to_s.split(', ').reject { |t| t.eql?('null') }.map { |t| Schema::Documentation::JSON_TYPE_TO_DOC.fetch(t, t) }.join('|')
549
551
  end
550
552
 
551
- # @param arg_spec [ArgumentSpec] expected argument
553
+ # @param arg_spec [Argument] expected argument
552
554
  # @param value [String] value typed
553
555
  # @param position [Position] command reached
554
556
  # @return [Completion] allowed values of the argument, or its type (and keys of its schema) as hint
@@ -4,6 +4,8 @@
4
4
  # SPDX-License-Identifier: Apache-2.0
5
5
 
6
6
  require_relative '../assert'
7
+ require_relative '../bundle_registry'
8
+ require_relative 'error'
7
9
  require_relative 'mailer'
8
10
  require_relative 'secret_finder'
9
11
 
@@ -13,11 +15,9 @@ module Aspera
13
15
  class Context
14
16
  # @type [Array<Symbol>]
15
17
  # Members that must be non-nil after bootstrap (validated in #validate)
16
- MEMBERS = %i[options transfer config formatter persistency man_header presets vault http_config main_folder mailer secret_finder].freeze
18
+ MEMBERS = %i[options config formatter persistency man_header presets vault http_config main_folder mailer secret_finder].freeze
17
19
  # @!attribute [rw] options
18
20
  # @return [Parser] the command line options manager
19
- # @!attribute [rw] transfer
20
- # @return [TransferAgent] the transfer agent, used by transfer plugins
21
21
  # @!attribute [rw] config
22
22
  # @return [Plugins::Config] the configuration plugin, used by plugins to get configuration values and presets
23
23
  # @!attribute [rw] formatter
@@ -45,12 +45,35 @@ module Aspera
45
45
  attr_accessor :help_requested
46
46
 
47
47
  # Initialize all members to nil, so that they are defined and can be validated later
48
+ # @param registry [BundleRegistry] Registry of the bundles that provide services
48
49
  # @return [nil]
49
- def initialize
50
+ def initialize(registry: BundleRegistry.instance)
50
51
  MEMBERS.each { |i| instance_variable_set(:"@#{i}", nil) }
51
52
  @progress_bar = nil
52
53
  @pac_executor = nil
53
54
  @help_requested = false
55
+ @registry = registry
56
+ # Services created, by name
57
+ @services = {}
58
+ end
59
+
60
+ # Object shared by plugins, provided by a bundle (manifest `services`): created once, on first use, with the context (`new(context)`).
61
+ # @param name [Symbol] Name of the service
62
+ # @return [Object] The service
63
+ # @raise [Cli::Error] If no available bundle provides the service, or its code cannot be loaded
64
+ def service(name)
65
+ @services[name] ||= @registry.load_entry(@registry.service(name)).new(self)
66
+ rescue BundleRegistry::Unavailable => e
67
+ raise Cli::Error, e.message
68
+ end
69
+
70
+ # Service `transfer`: transfer agent of bundle `xfer`, used by plugins that transfer files
71
+ # @return [Object] The service, see `service`
72
+ def transfer = service(:transfer)
73
+
74
+ # @param value [Object] Object used as service `transfer` (e.g. a test double)
75
+ def transfer=(value)
76
+ @services[:transfer] = value
54
77
  end
55
78
 
56
79
  # Validate that all mandatory members are non-nil (detect bootstrap bugs)
@@ -66,13 +89,13 @@ module Aspera
66
89
  # Check if the context is in manual-only mode
67
90
  # @return [Boolean] true if in manual-only mode
68
91
  def only_manual?
69
- transfer.eql?(:only_manual)
92
+ @services[:transfer].eql?(:only_manual)
70
93
  end
71
94
 
72
95
  # Set the context to manual-only mode
73
96
  # @return [Symbol] :only_manual
74
97
  def only_manual!
75
- @transfer = :only_manual
98
+ self.transfer = :only_manual
76
99
  end
77
100
  end
78
101
  end
@@ -32,8 +32,30 @@ module Aspera
32
32
  # OAuth 2.0 error codes of a refused authentication (RFC 6749, RFC 6750)
33
33
  OAUTH_AUTH_ERRORS = %w[invalid_client invalid_grant unauthorized_client access_denied invalid_token insufficient_scope].freeze
34
34
  private_constant :OAUTH_AUTH_ERRORS
35
+ # Category of errors of the code used by bundles (e.g. domain library), by class, see `add_error`
36
+ @errors = {}
35
37
 
36
38
  class << self
39
+ # Add the category of an error class (and its subclasses) raised by code that is not of the CLI, e.g. the domain library used by a bundle.
40
+ # The runner gives such an error its label and exit code, instead of `Other`.
41
+ # @param error_class [Class] Class of the error
42
+ # @param label [String] Label of the error message, e.g. `Transfer`
43
+ # @param code [Integer] Exit code, one of the constants of this module
44
+ # @return [nil]
45
+ def add_error(error_class, label:, code:)
46
+ raise ArgumentError, "not an error class: #{error_class}" unless error_class.is_a?(Class) && error_class <= StandardError
47
+ raise ArgumentError, "unknown exit code: #{code}" unless DESCRIPTIONS.key?(code)
48
+ @errors[error_class] = {label: label, code: code}.freeze
49
+ nil
50
+ end
51
+
52
+ # @param error [Exception] An error
53
+ # @return [Hash, nil] `label` and `code` of the most specific added class of the error (whatever the order of `add_error`), `nil` if none
54
+ def error_category(error)
55
+ error.class.ancestors.each { |klass| return @errors[klass] if @errors.key?(klass) }
56
+ nil
57
+ end
58
+
37
59
  # @param error [Rest::CallError] Failed API call
38
60
  # @return [Integer] Exit code for the HTTP status, or OAuth error
39
61
  def for_call_error(error)
@@ -73,6 +95,23 @@ module Aspera
73
95
  # Raised when the condition of option `poll` (`until`) is not met after the last run.
74
96
  class PollConditionNotMet < Error; end
75
97
 
98
+ # Exception raised when schema is asked (`help`)
99
+ class SchemaRequest < Error
100
+ # Value of option or argument that requests its schema
101
+ KEYWORD = 'help'
102
+
103
+ # @return [String, nil] path to schema file
104
+ attr_reader :path
105
+
106
+ # @param type [Symbol] :argument or :option
107
+ # @param name [String] name of the option/argument
108
+ # @param schema_path [String, nil] path to schema file, or `nil` if not available
109
+ def initialize(type, name, schema_path)
110
+ super("#{type}: #{name}")
111
+ @path = schema_path
112
+ end
113
+ end
114
+
76
115
  # Raised when a lookup for a specific entity fails to return exactly one result.
77
116
  #
78
117
  # Provides a formatted message indicating whether the entity was missing
@@ -10,9 +10,11 @@ require_relative '../log'
10
10
  require_relative '../assert'
11
11
  require_relative '../secret/hider'
12
12
  require_relative 'error'
13
- require_relative 'prompt'
13
+ require_relative '../prompt'
14
14
  require_relative 'security'
15
15
  require_relative '../rainbow'
16
+ require_relative '../standard_input'
17
+ require_relative '../units/timestamp'
16
18
  require 'json'
17
19
  require 'base64'
18
20
  require 'zlib'
@@ -32,6 +34,8 @@ module Aspera
32
34
 
33
35
  # First is default
34
36
  DEFAULT_DECODERS = %i[none json ruby yaml].freeze
37
+ # Modes of `@stdin:`: text, binary, text without the last end of line, or the standard input read by the command (where a file is read)
38
+ STDIN_MODES = ['', 'bin', 'chomp', 'stream'].freeze
35
39
 
36
40
  class << self
37
41
  # Decode comma separated table text
@@ -88,12 +92,15 @@ module Aspera
88
92
  WebSecret.ask(prompt)
89
93
  end
90
94
 
95
+ # @param mode [String] one of `STDIN_MODES`
96
+ # @return [String, StandardInput] the content of the standard input, or for mode `stream` the standard input itself, read by the command
91
97
  def read_stdin(mode)
92
98
  case mode
93
99
  when '' then $stdin.read
94
100
  when 'bin' then $stdin.binmode.read
95
101
  when 'chomp' then $stdin.read.chomp
96
- else raise BadArgument, "`stdin` supports only: '', 'bin' or 'chomp'"
102
+ when 'stream' then StandardInput.new
103
+ else raise BadArgument, "`stdin` supports only: #{STDIN_MODES.map(&:inspect).join(', ')}"
97
104
  end
98
105
  end
99
106
  end
@@ -109,7 +116,8 @@ module Aspera
109
116
  val: lambda { |i| i },
110
117
  base64: lambda { |i| Base64.decode64(i) },
111
118
  csvt: lambda { |i| ExtendedValue.decode_csvt(i) },
112
- env: lambda { |i| ENV.fetch(i, nil) },
119
+ date: lambda { |i| Units::Timestamp.parse(i).getutc.iso8601 },
120
+ env: lambda { |i| ENV.fetch(i) { raise BadArgument, "environment variable #{i} is not set" } },
113
121
  file: lambda { |i| Security.instance.read_file(i) },
114
122
  uri: lambda { |i| UriReader.read(i) },
115
123
  json: lambda { |i| ExtendedValue.JSON_parse(i) },
@@ -132,6 +140,7 @@ module Aspera
132
140
  val: 'Value as is: modifiers on the right are not evaluated',
133
141
  base64: 'Decode Base64',
134
142
  csvt: 'Decode titled CSV: Array of Hash',
143
+ date: 'Date in UTC, ISO 8601: a date, or now, today, yesterday, tomorrow, optionally followed by -<duration> or +<duration>, e.g. now-24h',
135
144
  env: 'Value of environment variable',
136
145
  file: 'Content of local file',
137
146
  uri: 'Content of URL: http:, https:, data:, file:',
@@ -144,7 +153,7 @@ module Aspera
144
153
  ruby: 'Evaluate Ruby code',
145
154
  s: 'Convert to String',
146
155
  secret: 'Ask secret, with prompt',
147
- stdin: 'Read standard input: empty, bin or chomp',
156
+ stdin: 'Read standard input: empty, bin, chomp, or stream (read by a command that reads a file)',
148
157
  yaml: 'Decode YAML',
149
158
  zlib: 'Decompress zlib',
150
159
  extend: 'Evaluate embedded @<modifier>:<value>@'
@@ -194,6 +203,14 @@ module Aspera
194
203
  update_regex
195
204
  end
196
205
 
206
+ # Disable a handler: its use raises an error.
207
+ # e.g. `@stdin:` in MCP server mode, where the standard input is the JSON-RPC stream: also the argument `-`, which is `@stdin:stream`.
208
+ # @param name [Symbol] Extended Value method
209
+ # @param reason [String] Why it is disabled, for the error message, e.g. `in MCP server mode`
210
+ def disable(name, reason)
211
+ on(name) { |_| raise BadArgument, "@#{name}: extended value is disabled #{reason}" }
212
+ end
213
+
197
214
  # Parses a `String` value to extended value.
198
215
  # If it is a String using supported extended value modifiers, then evaluate them.
199
216
  # Other value types are returned as is.
@@ -218,6 +235,8 @@ module Aspera
218
235
  end
219
236
  Log.log.trace1 { "evaluating: #{handlers_reversed}, value: #{value.class}:#{Secret::Hider.instance.hidden_copy(value)}" }
220
237
  handlers_reversed.each_with_index do |handler, index|
238
+ # The standard input read by the command is not a value
239
+ raise BadArgument, '@stdin:stream is read by the command, it cannot be decoded: use @stdin:' if value.is_a?(StandardInput)
221
240
  Security.instance.check_extended_value(handler)
222
241
  # The value read by the previous handler may be a secret
223
242
  Security.instance.check_secret_processing("@#{handler}") { Secret::Hider.instance.contains_secret?(value) } if index.positive?
@@ -229,6 +248,8 @@ module Aspera
229
248
  rescue => e
230
249
  raise BadArgument, "Evaluation of #{MARKER_START}#{handler}#{MARKER_END} for #{context}: #{e.message}"
231
250
  end
251
+ # Only where a command reads a file, see `Argument#stdin`
252
+ raise BadArgument, "@stdin:stream is only for a command that reads a file, not for #{context}: use @stdin:" if value.is_a?(StandardInput) && !allowed&.include?(StandardInput)
232
253
  return value
233
254
  end
234
255