aspera-cli 4.27.5 → 4.29.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 (249) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/BUGS.md +5 -10
  4. data/CHANGELOG.md +301 -4
  5. data/CODE_OF_CONDUCT.md +18 -0
  6. data/CONTRIBUTING.md +139 -58
  7. data/GOVERNANCE.md +30 -0
  8. data/LICENSE +201 -0
  9. data/README.md +103 -26
  10. data/SECURITY.md +70 -0
  11. data/bin/ascli +8 -5
  12. data/bin/asession +10 -7
  13. data/docs/README.md +2551 -772
  14. data/docs/test-mcp-with-ai.md +13 -11
  15. data/lib/aspera/agent/base.rb +23 -2
  16. data/lib/aspera/agent/connect.rb +16 -12
  17. data/lib/aspera/agent/desktop.rb +10 -7
  18. data/lib/aspera/agent/direct.rb +34 -22
  19. data/lib/aspera/agent/factory.rb +8 -4
  20. data/lib/aspera/agent/httpgw.rb +7 -5
  21. data/lib/aspera/agent/node.rb +15 -7
  22. data/lib/aspera/agent/transferd.rb +167 -43
  23. data/lib/aspera/api/alee.rb +4 -1
  24. data/lib/aspera/api/aoc.rb +14 -11
  25. data/lib/aspera/api/ats.rb +4 -2
  26. data/lib/aspera/api/cos_node.rb +8 -5
  27. data/lib/aspera/api/faspex.rb +16 -9
  28. data/lib/aspera/api/httpgw.rb +9 -6
  29. data/lib/aspera/api/node.rb +23 -19
  30. data/lib/aspera/ascmd.rb +8 -5
  31. data/lib/aspera/ascp/installation.rb +84 -42
  32. data/lib/aspera/ascp/log.schema.yaml +1084 -0
  33. data/lib/aspera/ascp/log_analyzer/advice.rb +97 -0
  34. data/lib/aspera/ascp/log_analyzer/diagnostics.rb +344 -0
  35. data/lib/aspera/ascp/log_analyzer/lines.rb +75 -0
  36. data/lib/aspera/ascp/log_analyzer/log_file.rb +593 -0
  37. data/lib/aspera/ascp/log_analyzer/records.rb +379 -0
  38. data/lib/aspera/ascp/log_analyzer/rules.rb +172 -0
  39. data/lib/aspera/ascp/log_analyzer/session.rb +782 -0
  40. data/lib/aspera/ascp/log_analyzer.rb +354 -0
  41. data/lib/aspera/ascp/management.rb +102 -48
  42. data/lib/aspera/ascp/session_errors.rb +217 -0
  43. data/lib/aspera/assert.rb +4 -0
  44. data/lib/aspera/cli/ascp_actions.rb +16 -37
  45. data/lib/aspera/cli/ascp_logs_actions.rb +176 -0
  46. data/lib/aspera/cli/async_transfer_store.rb +7 -4
  47. data/lib/aspera/cli/bootstrapper.rb +37 -34
  48. data/lib/aspera/cli/command_line.rb +24 -6
  49. data/lib/aspera/cli/command_registry.rb +49 -4
  50. data/lib/aspera/cli/command_spec.rb +34 -4
  51. data/lib/aspera/cli/completion/ascli.bash +53 -5
  52. data/lib/aspera/cli/completion/ascli.fish +27 -8
  53. data/lib/aspera/cli/completion/ascli.ps1 +63 -0
  54. data/lib/aspera/cli/completion/ascli.zsh +36 -4
  55. data/lib/aspera/cli/completion_actions.rb +594 -0
  56. data/lib/aspera/cli/context.rb +9 -4
  57. data/lib/aspera/cli/deprecation.rb +5 -2
  58. data/lib/aspera/cli/error.rb +45 -0
  59. data/lib/aspera/cli/extended_value.rb +83 -24
  60. data/lib/aspera/cli/formatter.rb +142 -73
  61. data/lib/aspera/cli/gem_checker.rb +9 -6
  62. data/lib/aspera/cli/hints.rb +22 -11
  63. data/lib/aspera/cli/http.rb +17 -13
  64. data/lib/aspera/cli/info.rb +17 -6
  65. data/lib/aspera/cli/mailer.rb +7 -4
  66. data/lib/aspera/cli/mcp/http_servlet.rb +155 -0
  67. data/lib/aspera/cli/mcp/secrets.rb +146 -0
  68. data/lib/aspera/cli/mcp/tool.rb +232 -0
  69. data/lib/aspera/cli/option_declarator.rb +10 -4
  70. data/lib/aspera/cli/option_registry.rb +6 -3
  71. data/lib/aspera/cli/option_types.rb +17 -2
  72. data/lib/aspera/cli/option_value.rb +72 -11
  73. data/lib/aspera/cli/options.schema.yaml +856 -81
  74. data/lib/aspera/cli/parser.rb +64 -31
  75. data/lib/aspera/cli/plugins/alee.rb +7 -4
  76. data/lib/aspera/cli/plugins/aoc.rb +250 -44
  77. data/lib/aspera/cli/plugins/ats.rb +9 -8
  78. data/lib/aspera/cli/plugins/base.rb +51 -25
  79. data/lib/aspera/cli/plugins/basic_auth.rb +5 -2
  80. data/lib/aspera/cli/plugins/config.rb +207 -141
  81. data/lib/aspera/cli/plugins/console.rb +9 -4
  82. data/lib/aspera/cli/plugins/cos.rb +8 -4
  83. data/lib/aspera/cli/plugins/factory.rb +22 -8
  84. data/lib/aspera/cli/plugins/faspex5.rb +37 -44
  85. data/lib/aspera/cli/plugins/faspio.rb +41 -8
  86. data/lib/aspera/cli/plugins/httpgw.rb +8 -4
  87. data/lib/aspera/cli/plugins/mcp.rb +186 -121
  88. data/lib/aspera/cli/plugins/node.rb +41 -34
  89. data/lib/aspera/cli/plugins/oauth.rb +5 -1
  90. data/lib/aspera/cli/plugins/orchestrator.rb +572 -59
  91. data/lib/aspera/cli/plugins/preview.rb +69 -44
  92. data/lib/aspera/cli/plugins/server.rb +66 -12
  93. data/lib/aspera/cli/plugins/shares.rb +288 -48
  94. data/lib/aspera/cli/plugins/transferd.rb +223 -0
  95. data/lib/aspera/cli/preset_actions.rb +155 -33
  96. data/lib/aspera/cli/preset_manager.rb +72 -16
  97. data/lib/aspera/cli/prompt.rb +7 -2
  98. data/lib/aspera/cli/result.rb +28 -11
  99. data/lib/aspera/cli/runner.rb +193 -80
  100. data/lib/aspera/cli/secret_finder.rb +4 -1
  101. data/lib/aspera/cli/security.rb +204 -0
  102. data/lib/aspera/cli/special_values.rb +4 -1
  103. data/lib/aspera/cli/sync_actions.rb +13 -10
  104. data/lib/aspera/cli/table_fitter.rb +119 -0
  105. data/lib/aspera/cli/terminal_formatter.rb +32 -40
  106. data/lib/aspera/cli/transfer_actions.rb +11 -8
  107. data/lib/aspera/cli/transfer_agent.rb +31 -19
  108. data/lib/aspera/cli/transfer_progress.rb +13 -45
  109. data/lib/aspera/cli/vault_actions.rb +45 -0
  110. data/lib/aspera/cli/vault_manager.rb +197 -50
  111. data/lib/aspera/cli/version.rb +4 -1
  112. data/lib/aspera/cli/web_secret.html.erb +61 -0
  113. data/lib/aspera/cli/web_secret.rb +222 -0
  114. data/lib/aspera/cli/wizard.rb +58 -45
  115. data/lib/aspera/command_line_builder.rb +35 -5
  116. data/lib/aspera/command_line_converter.rb +4 -1
  117. data/lib/aspera/coverage.rb +103 -33
  118. data/lib/aspera/data_repository.rb +42 -25
  119. data/lib/aspera/dot_container.rb +4 -1
  120. data/lib/aspera/duration.rb +45 -0
  121. data/lib/aspera/environment.rb +106 -33
  122. data/lib/aspera/exec_spec.rb +9 -5
  123. data/lib/aspera/faspex_gw.rb +105 -35
  124. data/lib/aspera/faspex_postproc.rb +193 -47
  125. data/lib/aspera/formatter_interface.rb +4 -2
  126. data/lib/aspera/graphql.rb +5 -1
  127. data/lib/aspera/hash_ext.rb +3 -0
  128. data/lib/aspera/id_generator.rb +6 -3
  129. data/lib/aspera/json_rpc/client.rb +55 -35
  130. data/lib/aspera/json_rpc/version.rb +4 -0
  131. data/lib/aspera/line_logger.rb +4 -1
  132. data/lib/aspera/link_header.rb +4 -1
  133. data/lib/aspera/log.rb +20 -10
  134. data/lib/aspera/markdown.rb +155 -115
  135. data/lib/aspera/mime.rb +9 -0
  136. data/lib/aspera/nagios.rb +9 -5
  137. data/lib/aspera/node_emulator.rb +111 -112
  138. data/lib/aspera/oauth/client/base.rb +163 -0
  139. data/lib/aspera/oauth/{boot.rb → client/boot.rb} +8 -4
  140. data/lib/aspera/oauth/{factory.rb → client/factory.rb} +13 -3
  141. data/lib/aspera/oauth/{generic.rb → client/generic.rb} +5 -1
  142. data/lib/aspera/oauth/{json_credentials.rb → client/json_credentials.rb} +4 -1
  143. data/lib/aspera/oauth/{jwt.rb → client/jwt.rb} +6 -3
  144. data/lib/aspera/oauth/client/shares_web.rb +85 -0
  145. data/lib/aspera/oauth/{url_json.rb → client/url_json.rb} +4 -1
  146. data/lib/aspera/oauth/client/web.rb +84 -0
  147. data/lib/aspera/oauth/server/authorize.html.erb +34 -0
  148. data/lib/aspera/oauth/server/pkce.rb +427 -0
  149. data/lib/aspera/orchestrator_workflow_checker.rb +679 -0
  150. data/lib/aspera/persistency_action_once.rb +5 -3
  151. data/lib/aspera/persistency_folder.rb +6 -3
  152. data/lib/aspera/preview/file_types.rb +6 -3
  153. data/lib/aspera/preview/generator.rb +9 -5
  154. data/lib/aspera/preview/options.schema.yaml +3 -3
  155. data/lib/aspera/preview/terminal.rb +11 -6
  156. data/lib/aspera/preview/utils.rb +6 -4
  157. data/lib/aspera/products/connect.rb +5 -2
  158. data/lib/aspera/products/desktop.rb +4 -1
  159. data/lib/aspera/products/other.rb +4 -2
  160. data/lib/aspera/products/transferd.rb +6 -2
  161. data/lib/aspera/products/transferd_service.rb +610 -0
  162. data/lib/aspera/proxy_auto_config.js +2 -2
  163. data/lib/aspera/proxy_auto_config.rb +5 -2
  164. data/lib/aspera/rainbow.rb +30 -1
  165. data/lib/aspera/rest/aspera_errors.rb +55 -60
  166. data/lib/aspera/rest/call_error.rb +3 -0
  167. data/lib/aspera/rest/client.rb +42 -42
  168. data/lib/aspera/rest/error_analyzer.rb +14 -2
  169. data/lib/aspera/rest/list.rb +14 -10
  170. data/lib/aspera/rest/parameters.rb +3 -0
  171. data/lib/aspera/rest/util.rb +13 -4
  172. data/lib/aspera/rest.rb +9 -7
  173. data/lib/aspera/schema/IBM Aspera Faspex API-5.0-enhanced.yaml +9 -11
  174. data/lib/aspera/schema/IBM Aspera Orchestrator API-v1-enhanced.yaml +4089 -0
  175. data/lib/aspera/schema/IBM Aspera faspio Gateway API-1.0.0-enhanced.yaml +1097 -0
  176. data/lib/aspera/schema/IBM Aspera on Cloud API-0.2.6-enhanced.yaml +11 -11
  177. data/lib/aspera/schema/IBM Aspera on Cloud Automation API-1.0.5-enhanced.yaml +2437 -1437
  178. data/lib/aspera/schema/IBM_Aspera_Shares.yaml +819 -7
  179. data/lib/aspera/schema/async_tables.yaml +11 -10
  180. data/lib/aspera/schema/documentation.rb +56 -78
  181. data/lib/aspera/schema/reader.rb +46 -11
  182. data/lib/aspera/schema/registry.rb +45 -24
  183. data/lib/aspera/schema/transferd-config.schema.json +333 -0
  184. data/lib/aspera/schema/validator.rb +4 -1
  185. data/lib/aspera/sealed_hash.rb +166 -0
  186. data/lib/aspera/secret/hider.rb +201 -0
  187. data/lib/aspera/secret/reference.rb +150 -0
  188. data/lib/aspera/secret/resolver.rb +212 -0
  189. data/lib/aspera/secret/store/base.rb +153 -0
  190. data/lib/aspera/secret/store/encrypted_hash.rb +329 -0
  191. data/lib/aspera/secret/store/factory.rb +103 -0
  192. data/lib/aspera/secret/store/hashicorp_vault.rb +390 -0
  193. data/lib/aspera/secret/store/keeper.rb +141 -0
  194. data/lib/aspera/secret/store/macos_security.rb +284 -0
  195. data/lib/aspera/secret/store/one_password_api.rb +99 -0
  196. data/lib/aspera/secret/store/one_password_base.rb +42 -0
  197. data/lib/aspera/secret/store/one_password_cli.rb +110 -0
  198. data/lib/aspera/secret/store/secret_service.rb +125 -0
  199. data/lib/aspera/secret/strength.rb +119 -0
  200. data/lib/aspera/servlet_helpers.rb +114 -0
  201. data/lib/aspera/ssh.rb +10 -7
  202. data/lib/aspera/ssl.rb +5 -2
  203. data/lib/aspera/string_ext.rb +3 -0
  204. data/lib/aspera/sync/args.schema.yaml +6 -1
  205. data/lib/aspera/sync/conf.schema.yaml +25 -10
  206. data/lib/aspera/sync/database.rb +3 -0
  207. data/lib/aspera/sync/operations.rb +34 -12
  208. data/lib/aspera/temp_file_manager.rb +85 -22
  209. data/lib/aspera/timer_limiter.rb +3 -0
  210. data/lib/aspera/transfer/error.rb +4 -1
  211. data/lib/aspera/transfer/faux_file.rb +4 -1
  212. data/lib/aspera/transfer/parameters.rb +22 -14
  213. data/lib/aspera/transfer/result.rb +3 -0
  214. data/lib/aspera/transfer/resumer.rb +6 -4
  215. data/lib/aspera/transfer/spec.rb +45 -18
  216. data/lib/aspera/transfer/spec.schema.yaml +8 -5
  217. data/lib/aspera/transfer/units.rb +75 -0
  218. data/lib/aspera/uri_reader.rb +57 -7
  219. data/lib/aspera/web_auth/index.html.erb +20 -0
  220. data/lib/aspera/web_auth/paste.rb +109 -0
  221. data/lib/aspera/web_auth/receiver.rb +50 -0
  222. data/lib/aspera/web_auth/relay.rb +76 -0
  223. data/lib/aspera/web_auth/reply.html.erb +150 -0
  224. data/lib/aspera/web_auth/server.rb +59 -14
  225. data/lib/aspera/web_page.html.erb +262 -0
  226. data/lib/aspera/web_page.rb +66 -0
  227. data/lib/aspera/web_server_simple.rb +82 -13
  228. data/lib/aspera/yaml.rb +5 -1
  229. data/llms.txt +81 -0
  230. data/skills/ascli/SKILL.md +88 -0
  231. data.tar.gz.sig +0 -0
  232. metadata +116 -48
  233. metadata.gz.sig +0 -0
  234. data/lib/aspera/cli/mcp_tool.rb +0 -189
  235. data/lib/aspera/keychain/base.rb +0 -25
  236. data/lib/aspera/keychain/encrypted_hash.rb +0 -188
  237. data/lib/aspera/keychain/factory.rb +0 -59
  238. data/lib/aspera/keychain/hashicorp_vault.rb +0 -74
  239. data/lib/aspera/keychain/macos_security.rb +0 -171
  240. data/lib/aspera/keychain/one_password_api.rb +0 -86
  241. data/lib/aspera/keychain/one_password_base.rb +0 -34
  242. data/lib/aspera/keychain/one_password_cli.rb +0 -98
  243. data/lib/aspera/oauth/base.rb +0 -141
  244. data/lib/aspera/oauth/web.rb +0 -57
  245. data/lib/aspera/oauth.rb +0 -9
  246. data/lib/aspera/schema/IBM Aspera Orchestrator API-v1.yaml +0 -1784
  247. data/lib/aspera/schema/IBM Aspera faspio Gateway API-1.0.0.yaml +0 -249
  248. data/lib/aspera/secret_hider.rb +0 -117
  249. data/lib/aspera/web_auth/index.html +0 -147
@@ -0,0 +1,594 @@
1
+ # frozen_string_literal: true
2
+
3
+ # SPDX-FileCopyrightText: IBM Corp.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ require_relative 'info'
7
+ require_relative 'parser'
8
+ require_relative 'plugins/factory'
9
+ require_relative 'preset_manager'
10
+ require_relative 'special_values'
11
+ require_relative '../environment'
12
+ require_relative '../schema/documentation'
13
+ require_relative '../schema/registry'
14
+
15
+ module Aspera
16
+ module Cli
17
+ # Mixin for Config plugin: shell completion scripts, and the words they propose
18
+ module CompletionActions
19
+ # Shells with a completion script in COMPLETION_FOLDER: shell => extension of script
20
+ COMPLETION_SHELLS = {bash: 'bash', zsh: 'zsh', fish: 'fish', powershell: 'ps1'}.freeze
21
+ COMPLETION_FOLDER = File.expand_path('completion', __dir__)
22
+ # Completion of the word at cursor
23
+ # @!attribute candidates [Array<Array(String, String)>] words, with their description (or `nil`)
24
+ # @!attribute hint [String, nil] displayed when a value is expected, but cannot be proposed (e.g. `<String>`)
25
+ # @!attribute files [Symbol, nil] local paths are completed: `:file` (files and folders) or `:folder`
26
+ # @!attribute files_prefix [String, nil] beginning of the word at cursor that is not part of the path (e.g. `@file:`)
27
+ Completion = Struct.new(:candidates, :hint, :files, :files_prefix, keyword_init: true) do
28
+ # Completion of a value that follows the given text in the word at cursor
29
+ # @param prefix [String] beginning of the word at cursor
30
+ # @return [self]
31
+ def prefixed(prefix)
32
+ self.candidates = candidates.map { |word, description| ["#{prefix}#{word}", description] }
33
+ self.files_prefix = "#{prefix}#{files_prefix}"
34
+ self
35
+ end
36
+ end
37
+ # Structure built with `@:` (see `Parser#args_as_extended`) being typed
38
+ # @!attribute marker [String] end marker
39
+ # @!attribute assigned [Array<String>] paths assigned
40
+ # @!attribute option [Option, nil] option token whose value is built, `nil` for a positional argument
41
+ Collecting = Struct.new(:marker, :assigned, :option, keyword_init: true)
42
+ # Command reached by the positional words
43
+ # @!attribute registry [CommandRegistry, nil] registry of plugin, `nil` at root
44
+ # @!attribute path [Array<Symbol>, nil] command path, `nil` if words are not a command
45
+ # @!attribute arguments [Array<String>] arguments given to the command
46
+ Position = Struct.new(:registry, :path, :arguments, keyword_init: true) do
47
+ # @return [CommandSpec, nil] command reached
48
+ def spec = path && registry[path]
49
+ end
50
+ # Value starting a structure built with `@:`: the optional text after `:` is the end marker
51
+ REGEX_EXTEND_ARGS = /\A@:(.*)\z/
52
+ # Extended value modifier at the beginning of a value, e.g. `@file:`
53
+ REGEX_MODIFIER = /\A@([a-z0-9_]*):/
54
+ # Beginning of extended value
55
+ MARKER_MODIFIER = '@'
56
+ # Modifiers whose value is usually given by another modifier, e.g. `@json:@file:`
57
+ MODIFIERS_DECODING = %i[base64 csvt json lines list re ruby s yaml zlib].freeze
58
+ # Modifiers whose value is not evaluated
59
+ MODIFIERS_LITERAL = %i[val extend].freeze
60
+ # Modes of `@stdin:`
61
+ STDIN_MODES = ['', 'bin', 'chomp'].freeze
62
+ # End of sentence in a description: a period, not of `e.g.` or `i.e.`, followed by a word not in lower case
63
+ REGEX_SENTENCE_END = /(?<!\be\.g|\bi\.e)\.\s+(?=[^a-z])/
64
+ # Maximum length of a hint listing the keys of a structure
65
+ HINT_MAX_LENGTH = 72
66
+ 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
68
+
69
+ # List words that can follow the given words, one per line.
70
+ # When a value is expected but cannot be proposed, its type is listed (e.g. `<String>`), or `<file>` (or `<folder>`) for a local path.
71
+ # @param words [Array<String>, nil] words typed before the cursor, after the command name
72
+ def action_completion_words(words: nil, **)
73
+ completion = completion(Array(words), '')
74
+ completion.candidates.each { |candidate| puts candidate.first }
75
+ puts completion.hint unless completion.hint.nil?
76
+ puts "<#{completion.files}>" unless completion.files.nil?
77
+ ::Process.exit(0)
78
+ end
79
+
80
+ # Complete the word at cursor, for completion scripts: candidates, one per line: `word`, or `word<TAB>description`,
81
+ # not filtered by the word at cursor. Then a directive for the shell: `:files` or `:folders` (complete local paths),
82
+ # followed by a space and the beginning of the word at cursor that is not part of the path, if any (e.g. `--key=@file:`),
83
+ # `:hint <text>` (display text, nothing to insert), or `:`.
84
+ # @param words [Array<String>, nil] words typed before the cursor, after the command name, then the word at cursor
85
+ def action_completion_candidates(words: nil, **)
86
+ words = Array(words)
87
+ completion = completion(words[0..-2], words.last.to_s)
88
+ completion.candidates.each { |word, description| puts description.nil? ? word : "#{word}\t#{description}" }
89
+ directive =
90
+ if completion.files then [completion.files.eql?(:folder) ? 'folders' : 'files', completion.files_prefix].reject { |w| w.to_s.empty? }.join(' ')
91
+ elsif completion.hint then "hint #{completion.hint}"
92
+ end
93
+ puts ":#{directive}"
94
+ ::Process.exit(0)
95
+ end
96
+
97
+ private
98
+
99
+ # @param words [Array<String>] words typed before the cursor, after the command name
100
+ # @param current [String] word at cursor, up to the cursor
101
+ # @return [Completion]
102
+ def completion(words, current)
103
+ words = completion_join_bash_split(words)
104
+ # `--opt=value` or `-Ovalue`: complete the value of the option, with this prefix
105
+ prefix = completion_inline_prefix(current)
106
+ words += [prefix] unless prefix.empty?
107
+ plugin_class, positional, waiting, collecting = completion_context(words)
108
+ return Completion.new(candidates: []) if positional.nil?
109
+ position = completion_position(plugin_class, positional)
110
+ value = current[prefix.length..]
111
+ result =
112
+ if prefix.empty? && (keys = completion_option_keys(current, position))
113
+ keys
114
+ elsif prefix.empty? && current.start_with?('-')
115
+ Completion.new(candidates: completion_options(options.declared_options.keys))
116
+ elsif !waiting.nil?
117
+ completion_option_values(waiting, value, position)
118
+ elsif !collecting.nil?
119
+ completion_collecting(collecting, value, plugin_class, positional, position)
120
+ elsif plugin_class.nil?
121
+ # Level 0: plugin names and global options
122
+ Completion.new(candidates: Plugins::Factory.instance.plugin_list.map { |p| [p.to_s, completion_plugin_description(p)] } + completion_options(options.declared_options.keys))
123
+ else
124
+ completion_command(plugin_class, positional[1..], value, position)
125
+ end
126
+ result.prefixed(prefix)
127
+ end
128
+
129
+ # @param current [String] word at cursor
130
+ # @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
+ 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]))
135
+ short.nil? || short.flag? ? '' : current[0, 2]
136
+ end
137
+
138
+ # @param words [Array<String>] words typed before the cursor
139
+ # @return [Array(Class, Array<String>, Option, Collecting)] plugin class (`nil` at root), and result of `completion_split`;
140
+ # `[]` if the first positional word is not a plugin
141
+ def completion_context(words)
142
+ positional, waiting, collecting = completion_split(words)
143
+ return [nil, positional, waiting, collecting] if positional.empty?
144
+ plugin_sym = completion_plugin(positional.first)
145
+ return [] if plugin_sym.nil?
146
+ begin
147
+ plugin_class = Plugins::Factory.instance.plugin_class(plugin_sym)
148
+ rescue StandardError
149
+ return []
150
+ end
151
+ plugin_class.declare_options(options)
152
+ # Options of the plugin may take a value: split again
153
+ [plugin_class, *completion_split(words)]
154
+ end
155
+
156
+ # @param plugin_class [Class, nil] plugin
157
+ # @param positional [Array<String>] positional words, the plugin name first
158
+ # @return [Position] command reached by the positional words
159
+ def completion_position(plugin_class, positional)
160
+ return Position.new(arguments: []) if plugin_class.nil?
161
+ registry = plugin_class.command_registry
162
+ path, given = registry.command_position(positional[1..].map(&:to_sym))
163
+ Position.new(registry: registry, path: path, arguments: path.nil? || given.zero? ? [] : positional.last(given))
164
+ end
165
+
166
+ # As the runner: an exact name, else the unique plugin name starting with word
167
+ # @param word [String] first positional word
168
+ # @return [Symbol, nil] plugin designated by word
169
+ def completion_plugin(word)
170
+ plugins = Plugins::Factory.instance.plugin_list
171
+ return word.to_sym if plugins.include?(word.to_sym)
172
+ matching = plugins.select { |p| p.to_s.start_with?(word) }
173
+ matching.first if matching.length.eql?(1)
174
+ end
175
+
176
+ # @param plugin_class [Class] plugin
177
+ # @param words [Array<String>] positional words after the plugin name
178
+ # @param value [String] word at cursor
179
+ # @param position [Position] command reached
180
+ # @return [Completion] sub-commands, or next argument
181
+ def completion_command(plugin_class, words, value, position)
182
+ registry = plugin_class.command_registry
183
+ path = position.path
184
+ return Completion.new(candidates: []) if path.nil?
185
+ children = registry.children_of(path)
186
+ next_argument = completion_next_argument(registry, path, position.arguments.length)
187
+ return completion_argument(next_argument, value, position) unless next_argument.nil?
188
+ # Source files of an upload follow the declared arguments
189
+ return Completion.new(candidates: [], files: :file) if children.empty? && registry[path]&.transfer_paths.eql?(:send)
190
+ # Commands, each followed by its aliases, with the same description
191
+ candidates = children.flat_map do |id, spec|
192
+ description = completion_description(spec.description)
193
+ [id, *Array(spec.aliases)].map { |name| [name.to_s, description] }
194
+ end
195
+ # Options of plugin only right after the plugin name
196
+ candidates.concat(completion_options(plugin_class.option_sources.each_key.flat_map { |src| src.option_specs.keys }.uniq)) if words.empty?
197
+ Completion.new(candidates: candidates)
198
+ end
199
+
200
+ # @param registry [CommandRegistry] registry of plugin
201
+ # @param path [Array<Symbol>] command path
202
+ # @param given [Integer] number of arguments given to the command
203
+ # @return [ArgumentSpec, nil] argument expected after the given ones
204
+ def completion_next_argument(registry, path, given)
205
+ arguments = registry.arguments_at(path)
206
+ return arguments[given] if given < arguments.length
207
+ arguments.last if registry.children_of(path).empty? && arguments.last&.multiple
208
+ end
209
+
210
+ # In a structure built with `@:`: the keys of its schema, and its end marker once an assignment is given, or the value of a key
211
+ # @param collecting [Collecting] structure being typed
212
+ # @param value [String] word at cursor: `path`, or `path=value`
213
+ # @param plugin_class [Class, nil] plugin
214
+ # @param positional [Array<String>] positional words, the plugin name first
215
+ # @param position [Position] command reached
216
+ # @return [Completion]
217
+ def completion_collecting(collecting, value, plugin_class, positional, position)
218
+ schema =
219
+ if collecting.option
220
+ option = completion_option(collecting.option)
221
+ completion_option_schema(option, position) unless option.nil?
222
+ elsif plugin_class
223
+ # The positional argument built is the last positional word: `@:`
224
+ registry = plugin_class.command_registry
225
+ path, given = registry.command_position(positional[1..-2].map(&:to_sym))
226
+ completion_next_argument(registry, path, given)&.schema unless path.nil?
227
+ end
228
+ if (index = value.index(Option::VALUE_SEP))
229
+ return completion_key_value(schema, value[0...index].split(DotContainer::SEPARATOR), value[(index + 1)..], position).prefixed(value[0..index])
230
+ end
231
+ end_marker = collecting.assigned.empty? ? [] : [[collecting.marker, 'End of structure built with @:']]
232
+ # The value of an option may be partial (completed by other sources): required keys apply to an argument only
233
+ keys = completion_schema_keys(completion_schema_rows(schema), value, assigned: collecting.assigned, required: collecting.option.nil?)
234
+ return Completion.new(candidates: [], hint: completion_hint('path=value', nil)) if end_marker.empty? && keys.empty?
235
+ Completion.new(candidates: end_marker + keys)
236
+ end
237
+
238
+ # Bash splits `--opt=value` in words `--opt`, `=` and `value`: join them back.
239
+ # @param words [Array<String>] words typed before the cursor
240
+ # @return [Array<String>] words, with options and their value joined
241
+ def completion_join_bash_split(words)
242
+ result = []
243
+ join_next = false
244
+ words.each do |word|
245
+ if join_next
246
+ result[-1] += word
247
+ join_next = false
248
+ elsif word.eql?(Option::VALUE_SEP) && result.last&.start_with?(Option::PREFIX) && !result.last.include?(Option::VALUE_SEP)
249
+ result[-1] += word
250
+ join_next = true
251
+ else
252
+ result.push(word)
253
+ end
254
+ end
255
+ result
256
+ end
257
+
258
+ # Split words as the command line parser does: an option without inline value takes the next word as value,
259
+ # unless it is a flag. An option not declared yet (e.g. of a plugin) takes a value.
260
+ # A value `@:` (of option, or of positional argument) collects the next positional words, up to its end marker.
261
+ # @param words [Array<String>] words typed before the cursor
262
+ # @return [Array(Array<String>, Option, Collecting)] positional words, the last option if it is waiting for its value,
263
+ # and the structure built with `@:` if its end marker is not given
264
+ def completion_split(words)
265
+ positional = []
266
+ waiting = nil
267
+ collecting = nil
268
+ stop = false
269
+ words.each do |word|
270
+ if !stop && word.eql?(Option::STOP)
271
+ stop = true
272
+ waiting = nil
273
+ elsif !stop && Option.option?(word)
274
+ tok = Option.parse(word)
275
+ # `--opt=` at end of line (from bash split): value is being typed
276
+ waiting = (tok.inline? && !tok.inline_value.empty?) || completion_option(tok)&.flag? ? nil : tok
277
+ collecting = completion_collecting_start(tok.inline_value, tok) || collecting
278
+ elsif waiting
279
+ collecting = completion_collecting_start(word, waiting) || collecting
280
+ waiting = nil
281
+ elsif collecting
282
+ # Assignment, or end marker
283
+ if word.eql?(collecting.marker)
284
+ collecting = nil
285
+ else
286
+ collecting.assigned.push(word.split(Option::VALUE_SEP, 2).first)
287
+ end
288
+ else
289
+ positional.push(word)
290
+ collecting = completion_collecting_start(word, nil)
291
+ end
292
+ end
293
+ [positional, waiting, collecting]
294
+ end
295
+
296
+ # @param value [String, nil] value of option or argument
297
+ # @param option [Option, nil] option token, `nil` for a positional argument
298
+ # @return [Collecting, nil] structure started by the value, if it is `@:`
299
+ def completion_collecting_start(value, option)
300
+ match = REGEX_EXTEND_ARGS.match(value.to_s)
301
+ return if match.nil?
302
+ Collecting.new(marker: match[1].empty? ? SpecialValues::EOA : match[1], assigned: [], option: option)
303
+ end
304
+
305
+ # @param tok [Option] option token
306
+ # @return [OptionValue, nil] declared option designated by the token
307
+ def completion_option(tok)
308
+ return options.declared_options.values.find { |o| o.short.eql?(tok.short_char) } if tok.short_char
309
+ options.declared_options[tok.name.to_sym]
310
+ end
311
+
312
+ # @param option [OptionValue] declared option
313
+ # @param position [Position] command reached
314
+ # @return [String, nil] schema of the value of option: the one of option `query` depends on the command
315
+ def completion_option_schema(option, position)
316
+ return option.schema unless option.schema.nil? && option.option.eql?(:query)
317
+ position.spec&.query_schema
318
+ end
319
+
320
+ # @param names [Array<Symbol>] names of declared options
321
+ # @return [Array<Array(String, String)>] command line names of options, except deprecated ones, and their description
322
+ def completion_options(names)
323
+ names.filter_map do |name|
324
+ option = options.declared_options[name]
325
+ next if option.nil? || option.deprecation
326
+ [Parser.option_name_to_line(name), completion_description(option.description)]
327
+ end
328
+ end
329
+
330
+ # @param tok [Option] option token waiting for its value
331
+ # @param value [String] value typed
332
+ # @param position [Position] command reached
333
+ # @return [Completion] allowed values of the option, or its type as hint
334
+ def completion_option_values(tok, value, position)
335
+ option = completion_option(tok)
336
+ # Option not declared yet (e.g. of a plugin): its value may still be an extended value
337
+ return completion_value(value, position, hint: nil) if option.nil?
338
+ schema = completion_option_schema(option, position)
339
+ return completion_key_value(schema, tok.dot_path, value, position) unless tok.dot_path.nil?
340
+ allowed = option.values&.map(&:to_s)&.uniq
341
+ complete = option.complete
342
+ # A String value is the value of a key of the structure
343
+ allowed, complete = completion_shorthand(schema, option.shorthand) if allowed.nil? && complete.nil? && option.shorthand
344
+ types = option.types&.reject { |t| t.eql?(NilClass) }
345
+ hint = completion_hint(types&.any? ? types.map(&:name).join('|') : option.allowed_info || 'String', schema)
346
+ completion_value(value, position, hint: hint, allowed: allowed, complete: complete)
347
+ end
348
+
349
+ # @param schema [String, nil] schema of structure
350
+ # @param key [String] key of a `String` value
351
+ # @return [Array(Array<String>, Symbol)] allowed values of the key, from its schema or the discriminator of its variants, and kind of value
352
+ 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
+ node = Schema::Registry.instance.reader(schema).current
356
+ [(node.dig('discriminator', 'mapping')&.keys if node.dig('discriminator', 'propertyName').eql?(key)), nil]
357
+ rescue StandardError
358
+ [nil, nil]
359
+ end
360
+
361
+ # Keys of an option with dotted notation, from its schema, e.g. `--ts.ta` gives `--ts.target_rate_kbps=`
362
+ # @param current [String] word at cursor
363
+ # @param position [Position] command reached
364
+ # @return [Completion, nil] keys at the level of the word, `nil` if the word is not a dotted option
365
+ def completion_option_keys(current, position)
366
+ match = current.match(/\A--([^=.]+)\.([^=]*)\z/)
367
+ return if match.nil?
368
+ option = options.declared_options[Parser.option_line_to_name(match[1]).to_sym]
369
+ return Completion.new(candidates: []) if option.nil?
370
+ 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
+ end
373
+
374
+ # 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.
375
+ # @param rows [Array<Hash>] fields of schema
376
+ # @param typed [String] path typed: dot-separated keys, the last one being typed
377
+ # @param assigned [Array<String>] paths already assigned, not proposed again
378
+ # @param required [Boolean] required keys are marked, and listed first
379
+ # @return [Array<Array(String, String)>] path of key, and its description
380
+ def completion_schema_keys(rows, typed, assigned: [], required: false)
381
+ # Keys of parents, as typed, e.g. `recipients.0.`
382
+ parents = typed[0, (typed.rindex(DotContainer::SEPARATOR) || -1) + 1]
383
+ parent_path = completion_row_path(parents.split(DotContainer::SEPARATOR))
384
+ names = rows.map { |r| r['name'] }
385
+ keys = rows.filter_map do |row|
386
+ path = row['name'].split(DotContainer::SEPARATOR)
387
+ next unless path[0..-2].eql?(parent_path)
388
+ suffix =
389
+ if names.any? { |n| n.start_with?("#{row['name']}#{DotContainer::SEPARATOR}") } then DotContainer::SEPARATOR
390
+ elsif names.any? { |n| n.start_with?("#{row['name']}[]#{DotContainer::SEPARATOR}") } then "#{DotContainer::SEPARATOR}0#{DotContainer::SEPARATOR}"
391
+ else Option::VALUE_SEP
392
+ end
393
+ key = "#{parents}#{path.last}"
394
+ next if suffix.eql?(Option::VALUE_SEP) && assigned.include?(key)
395
+ description = completion_description(row['description']) || completion_type(row['type'])
396
+ description = [description, '(required)'].compact.join(' ') if required && row['required']
397
+ ["#{key}#{suffix}", description, required && row['required']]
398
+ end
399
+ keys.partition(&:last).flatten(1).map { |key, description, _| [key, description] }
400
+ end
401
+
402
+ # @param keys [Array<String>] keys of a path, as typed, e.g. `recipients`, `0`, `name`
403
+ # @return [Array<String>] keys of the path, as in schema rows, e.g. `recipients[]`, `name`
404
+ def completion_row_path(keys)
405
+ keys.each_with_object([]) do |key, path|
406
+ if !path.empty? && key.match?(/\A\d+\z/)
407
+ path[-1] = "#{path.last}[]"
408
+ else
409
+ path.push(key)
410
+ end
411
+ end
412
+ end
413
+
414
+ # @param schema [String, nil] schema of structure
415
+ # @param keys [Array<String>] path of key in structure, as typed
416
+ # @return [Hash, nil] field of the schema at path
417
+ def completion_schema_row(schema, keys)
418
+ name = completion_row_path(keys).join(DotContainer::SEPARATOR)
419
+ completion_schema_rows(schema).find { |r| r['name'].eql?(name) }
420
+ end
421
+
422
+ # @param row [Hash] field of schema
423
+ # @return [Array<String>, nil] allowed values of the field
424
+ def completion_row_values(row)
425
+ return row['enum'].compact.map(&:to_s) if row['enum']
426
+ %w[true false] if row['type'].eql?('boolean')
427
+ end
428
+
429
+ # @param schema [String, nil] schema of structure
430
+ # @param keys [Array<String>] path of key in structure, as typed
431
+ # @param value [String] value typed
432
+ # @param position [Position] command reached
433
+ # @return [Completion] allowed values of the key, or its type as hint
434
+ def completion_key_value(schema, keys, value, position)
435
+ row = completion_schema_row(schema, keys)
436
+ return completion_value(value, position, hint: nil) if row.nil?
437
+ type = completion_type(row['type'])
438
+ hint = ["<#{type.empty? ? 'value' : type}>", completion_description(row['description'])].compact.join(' ')
439
+ completion_value(value, position, hint: hint, allowed: completion_row_values(row), complete: row['complete']&.to_sym)
440
+ end
441
+
442
+ # @param value [String] value typed
443
+ # @param position [Position] command reached
444
+ # @param hint [String, nil] hint, when nothing can be proposed
445
+ # @param allowed [Array<String>, nil] allowed values
446
+ # @param complete [Symbol, nil] kind of value, one of `Complete::KINDS`
447
+ # @param extended [Boolean] the value is evaluated as extended value
448
+ # @return [Completion] values: extended value modifiers, allowed values, local values, or hint
449
+ def completion_value(value, position, hint:, allowed: nil, complete: nil, extended: true)
450
+ return completion_extended(value, position, complete) if extended && value.start_with?(MARKER_MODIFIER)
451
+ return Completion.new(candidates: allowed.map { |v| [v, nil] }) unless allowed.nil? || allowed.empty?
452
+ (completion_kind(complete, value, position) unless complete.nil?) || Completion.new(candidates: [], hint: hint)
453
+ end
454
+
455
+ # @param kind [Symbol] kind of value, one of `Complete::KINDS`
456
+ # @param value [String] value typed
457
+ # @param position [Position] command reached
458
+ # @return [Completion, nil] values of this kind, `nil` if none applies
459
+ def completion_kind(kind, value, position)
460
+ case kind
461
+ when :file, :folder then Completion.new(candidates: [], files: kind)
462
+ when :destination_folder then Completion.new(candidates: [], files: :folder) unless position.spec&.transfer_paths.eql?(:send)
463
+ when :preset then Completion.new(candidates: completion_preset_names(value))
464
+ when :preset_parameter then Completion.new(candidates: completion_preset_parameters(position.arguments.first))
465
+ when :transfer_job then Completion.new(candidates: async_transfer_store.list.map { |job| [job['job_id'].to_s, job['status']] })
466
+ else Aspera.error_unexpected_value(kind) { 'complete' }
467
+ end
468
+ end
469
+
470
+ # Value starting with `@`: modifiers, or the value of the last modifier, e.g. a local file for `@file:`
471
+ # @param value [String] value typed, starting with `@`
472
+ # @param position [Position] command reached
473
+ # @param complete [Symbol, nil] kind of value, one of `Complete::KINDS`
474
+ # @return [Completion]
475
+ def completion_extended(value, position, complete)
476
+ modifiers = ExtendedValue.instance.modifiers
477
+ last = nil
478
+ rest = value
479
+ while !MODIFIERS_LITERAL.include?(last) && (match = REGEX_MODIFIER.match(rest)) && modifiers.include?(match[1].to_sym)
480
+ last = match[1].to_sym
481
+ rest = match.post_match
482
+ end
483
+ prefix = value[0, value.length - rest.length]
484
+ propose_modifiers = rest.start_with?(MARKER_MODIFIER) ? !MODIFIERS_LITERAL.include?(last) : rest.empty? && MODIFIERS_DECODING.include?(last)
485
+ completion =
486
+ if propose_modifiers then Completion.new(candidates: modifiers.map { |m| ["#{MARKER_MODIFIER}#{m}:", ExtendedValue.instance.description(m)] })
487
+ else
488
+ case last
489
+ when :file, :path then Completion.new(candidates: [], files: complete.eql?(:folder) ? :folder : :file)
490
+ when :preset then Completion.new(candidates: completion_preset_names(rest))
491
+ 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 *MODIFIERS_DECODING then Completion.new(candidates: [])
494
+ else Completion.new(candidates: [], hint: ExtendedValue.instance.description(last))
495
+ end
496
+ end
497
+ completion.prefixed(prefix)
498
+ end
499
+
500
+ # Names of presets (with their comment as description), and parameters of the preset typed (`@preset:` takes a dot path)
501
+ # @param value [String] value typed
502
+ # @return [Array<Array(String, String)>]
503
+ def completion_preset_names(value)
504
+ presets.config_presets.flat_map do |name, preset|
505
+ parameters = value.start_with?("#{name}#{DotContainer::SEPARATOR}") ? completion_preset_parameters(name) : []
506
+ comment = completion_description(preset[PresetManager::Key::COMMENT]) if preset.is_a?(Hash)
507
+ [[name, comment]] + parameters.map { |parameter, _| ["#{name}#{DotContainer::SEPARATOR}#{parameter}", nil] }
508
+ end
509
+ end
510
+
511
+ # @param name [String, nil] name of preset
512
+ # @return [Array<Array(String, nil)>] parameters of the preset, empty if it is not a preset
513
+ def completion_preset_parameters(name)
514
+ preset = presets.config_presets[name]
515
+ return [] unless preset.is_a?(Hash)
516
+ preset.keys.map(&:to_s).reject { |k| k.start_with?(PresetManager::Key::META_PREFIX) }.map { |k| [k, nil] }
517
+ end
518
+
519
+ # @param type [String] expected type, e.g. `Hash`
520
+ # @param schema [String, nil] schema of value
521
+ # @return [String] type, followed by the top level keys of the schema, if any: required ones first, followed by `*`
522
+ def completion_hint(type, schema)
523
+ hint = "<#{type}>"
524
+ top = completion_schema_rows(schema).reject { |r| r['name'].match?(/[.\[]/) }
525
+ required, optional = top.partition { |r| r['required'] }
526
+ names = required.map { |r| "#{r['name']}*" } + optional.map { |r| r['name'] }
527
+ names.each_with_index do |name, index|
528
+ separator = index.zero? ? ' ' : ', '
529
+ # stdout is read by the shell, not a terminal, but the hint is displayed on the terminal: check the locale only
530
+ return "#{hint}#{separator}#{Environment.char('…', unicode: Environment.unicode_environment?)}" if hint.length + separator.length + name.length > HINT_MAX_LENGTH
531
+ hint = "#{hint}#{separator}#{name}"
532
+ end
533
+ hint
534
+ end
535
+
536
+ # @param schema [String, nil] name of schema in registry
537
+ # @return [Array<Hash>] fields of the schema (see `Schema::Reader#to_rows`), empty if none
538
+ def completion_schema_rows(schema)
539
+ return [] if schema.nil?
540
+ Schema::Registry.instance.reader(schema).to_rows
541
+ rescue StandardError
542
+ []
543
+ end
544
+
545
+ # @param type [String] JSON type(s) of a schema field, e.g. `integer` or `string, null`
546
+ # @return [String] type, as displayed in help, e.g. `Integer`
547
+ def completion_type(type)
548
+ type.to_s.split(', ').reject { |t| t.eql?('null') }.map { |t| Schema::Documentation::JSON_TYPE_TO_DOC.fetch(t, t) }.join('|')
549
+ end
550
+
551
+ # @param arg_spec [ArgumentSpec] expected argument
552
+ # @param value [String] value typed
553
+ # @param position [Position] command reached
554
+ # @return [Completion] allowed values of the argument, or its type (and keys of its schema) as hint
555
+ def completion_argument(arg_spec, value, position)
556
+ type_str =
557
+ case arg_spec.type
558
+ when :identifier then 'identifier'
559
+ when Array then arg_spec.type.map(&:name).join('|')
560
+ when Class then arg_spec.type.name
561
+ when nil then 'String'
562
+ else arg_spec.type.to_s
563
+ end
564
+ hint = completion_hint(type_str, arg_spec.schema)
565
+ # Percent selector: lookup of the identifier by a field
566
+ hint = "#{hint} or %<field>:<value>" if arg_spec.type.eql?(:identifier) && !arg_spec.lookup.nil?
567
+ completion_value(value, position, hint: hint, allowed: arg_spec.allowed&.map(&:to_s), complete: arg_spec.complete, extended: !arg_spec.evaluate.eql?(:none))
568
+ end
569
+
570
+ # @param plugin_sym [Symbol] plugin name
571
+ # @return [String, nil] name of the application of the plugin
572
+ def completion_plugin_description(plugin_sym)
573
+ Plugins::Factory.instance.plugin_class(plugin_sym).application_name
574
+ rescue StandardError
575
+ nil
576
+ end
577
+
578
+ # @param text [String, nil] description
579
+ # @return [String, nil] first sentence of first line, without final period, as displayed by the shell
580
+ def completion_description(text)
581
+ line = text.to_s.lines.first.to_s.strip.tr("\t", ' ').split(REGEX_SENTENCE_END).first.to_s.delete_suffix('.')
582
+ line.empty? ? nil : line
583
+ end
584
+
585
+ # Display the completion script for the given shell.
586
+ # Raw output, not formatted, so that it can be evaluated by the shell.
587
+ # @param shell [Symbol] One of `COMPLETION_SHELLS`
588
+ def completion_script(shell)
589
+ $stdout.write(File.read(File.join(COMPLETION_FOLDER, "#{Info::CMD_NAME}.#{COMPLETION_SHELLS[shell]}")))
590
+ ::Process.exit(0)
591
+ end
592
+ end
593
+ end
594
+ end
@@ -1,8 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'aspera/assert'
4
- require 'aspera/cli/mailer'
5
- require 'aspera/cli/secret_finder'
3
+ # SPDX-FileCopyrightText: IBM Corp.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ require_relative '../assert'
7
+ require_relative 'mailer'
8
+ require_relative 'secret_finder'
6
9
 
7
10
  module Aspera
8
11
  module Cli
@@ -10,7 +13,7 @@ module Aspera
10
13
  class Context
11
14
  # @type [Array<Symbol>]
12
15
  # Members that must be non-nil after bootstrap (validated in #validate)
13
- MEMBERS = %i[options transfer config formatter persistency man_header presets http_config main_folder mailer secret_finder].freeze
16
+ MEMBERS = %i[options transfer config formatter persistency man_header presets vault http_config main_folder mailer secret_finder].freeze
14
17
  # @!attribute [rw] options
15
18
  # @return [Parser] the command line options manager
16
19
  # @!attribute [rw] transfer
@@ -25,6 +28,8 @@ module Aspera
25
28
  # @return [Boolean] whether to display the manual header in plugin help
26
29
  # @!attribute [rw] presets
27
30
  # @return [PresetManager] manages the YAML config file and preset resolution
31
+ # @!attribute [rw] vault
32
+ # @return [VaultManager] secrets of the vault: `@vault:`, `config vault`, presets
28
33
  # @!attribute [rw] http_config
29
34
  # @return [Http] manages HTTP/S and TLS runtime options
30
35
  # @!attribute [rw] mailer
@@ -1,7 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'aspera/cli/version'
4
- require 'aspera/assert'
3
+ # SPDX-FileCopyrightText: IBM Corp.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ require_relative 'version'
7
+ require_relative '../assert'
5
8
 
6
9
  module Aspera
7
10
  module Cli