Files
ubicloud/cli-commands/vm/post/scp.rb
Jeremy Evans 9fc326c965 Minor CLI help improvements
* Spaces around `|` between name and id.

* `Get program help` -> `Get command help`

* `private-subnet-id` -> `ps-id`
2025-03-13 09:20:15 -07:00

33 lines
1.0 KiB
Ruby

# frozen_string_literal: true
UbiCli.on("vm").run_on("scp") do
desc "Copy files to or from virtual machine using `scp`"
skip_option_parsing("ubi vm (location/vm-name | vm-id) [options] scp [scp-options] (local-path :remote-path | :remote-path local-path)")
args(2..., invalid_args_message: "must provide 2 paths: either 'local-path :remote-path' or ':remote-path local-path'")
run do |(*argv, path1, path2), opts|
remote_path1 = path1[0] == ":"
remote_path2 = path2[0] == ":"
if remote_path1 ^ remote_path2
handle_ssh(opts) do |user:, address:|
address = "[#{address}]" if address.include?(":")
remote = "#{user}@#{address}"
if remote_path1
path1 = "#{remote}#{path1}"
else
path2 = "#{remote}#{path2}"
end
["scp", *argv, "--", path1, path2]
end
else
error = "! Only one path should be remote (start with ':')\n"
[400, {"content-type" => "text/plain", "content-length" => error.bytesize.to_s}, [error]]
end
end
end