Files
ubicloud/cli-commands/vm/post/scp.rb
Jeremy Evans c723771550 Remove custom invalid args messages from CLI
These were not used consistently, only for some vm and pg commands.
They made sense to have before we started including help output
with errors.  However, now that we show help output with errors,
it's easy to see the usage to determine what args are expected.
2025-03-19 14:08:49 -07:00

33 lines
934 B
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...)
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