ubicloud/cli-commands/vm/post/scp.rb
Jeremy Evans cbf2d95cbb Revert the backout of the CLI support
This reverts commit b741fe9005.

This was backed out as problems started occuring shortly after
a large CLI pull request was merged.  However, log analysis
shows that the CLI was unrelated to the problems.
2025-02-11 16:09:46 -08:00

30 lines
756 B
Ruby

# frozen_string_literal: true
UbiRodish.on("vm").run_on("scp") do
skip_option_parsing
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 ':')"
[400, {"content-type" => "text/plain", "content-length" => error.bytesize.to_s}, [error]]
end
end
end