fcl: Prompt for input if missing

This commit is contained in:
Lucas Wilson-Richter
2024-05-17 19:35:21 +10:00
parent a537f4d311
commit ca3d5ca55b

10
fcl
View File

@ -16,7 +16,7 @@
# #
DEFAULT_ORG = "buildkite" DEFAULT_ORG = "buildkite"
REPO_BASE = "#{ENV['HOME']}/repos" REPO_BASE = "#{ENV['HOME']}/src"
def clone(repo_url, destination) def clone(repo_url, destination)
spinner_command = %Q[gum spin --show-output --spinner dot] spinner_command = %Q[gum spin --show-output --spinner dot]
@ -24,7 +24,7 @@ def clone(repo_url, destination)
system("#{spinner_command} -- #{git_command}") system("#{spinner_command} -- #{git_command}")
end end
def print_error(message) def log_error(message)
system(%Q[gum style --bold --border=double --padding='0 1' --foreground 212 "#{message}"]) system(%Q[gum style --bold --border=double --padding='0 1' --foreground 212 "#{message}"])
end end
@ -66,10 +66,12 @@ def destination_path(repo_str)
File.join(forge, org, repo) File.join(forge, org, repo)
end end
destination = ARGV[1] || destination_path(ARGV[0]) repo_str = ARGV.empty? ? `gum input --header="Enter a repo name" --placeholder=""`.chomp : ARGV[0]
destination = ARGV[1] || destination_path(repo_str)
full_dest = File.join(REPO_BASE, destination) full_dest = File.join(REPO_BASE, destination)
clone_url = repo_url(ARGV[0]) clone_url = repo_url(repo_str)
if Dir.exist?(full_dest) if Dir.exist?(full_dest)
log_error "#{destination} already exists. Doing nothing." log_error "#{destination} already exists. Doing nothing."