fcl: Get config from config.bash (kludge du jour)

This commit is contained in:
2024-05-19 23:51:27 +10:00
parent 69ab075c80
commit f939bf25b9

15
fcl
View File

@ -15,8 +15,11 @@
# [ ] Make a way to turn off the pretty, in case it's getting in the way # [ ] Make a way to turn off the pretty, in case it's getting in the way
# #
DEFAULT_ORG = "buildkite"
REPO_BASE = "#{ENV['HOME']}/src" ConfigPath = File.join(File.expand_path(File.dirname(__FILE__)), 'config.bash')
ConfigValues = `env -i bash --noprofile --norc -c 'source #{ConfigPath}; env'`.lines.map(&:chomp)
ConfigPairs = ConfigValues.map {|v| v.split('=',2) }.to_h
Config = ConfigPairs.reject {|k,v| ['_','SHLVL','PWD'].include?(k) }
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]
@ -48,9 +51,9 @@ def repo_url(repo_str)
# Just a user/org name and repo name. Assume it's on GitHub and make an HTTPS URL. # Just a user/org name and repo name. Assume it's on GitHub and make an HTTPS URL.
when /^[\w\-_]+\/[\w\-_\.]+$/ when /^[\w\-_]+\/[\w\-_\.]+$/
"https://github.com/#{repo_str}.git" "https://github.com/#{repo_str}.git"
# Just a repo name. Assume it's a DEFAULT_ORG repo on GitHub and make an HTTPS URL. # Just a repo name. Assume it's a FCL_DEFAULT_ORG repo on GitHub and make an HTTPS URL.
when /^[\w\-_\.]+$/ when /^[\w\-_\.]+$/
"https://github.com/#{DEFAULT_ORG}/#{repo_str}.git" "https://github.com/#{Config['FCL_DEFAULT_ORG']}/#{repo_str}.git"
else else
raise "I can't make a repo URL out of '#{repo_str}'." raise "I can't make a repo URL out of '#{repo_str}'."
end end
@ -60,7 +63,7 @@ def destination_path(repo_str)
repo_elms = repo_str.split('/') repo_elms = repo_str.split('/')
repo = repo_elms.pop.sub(/\.git$/, '') repo = repo_elms.pop.sub(/\.git$/, '')
org = repo_elms.pop || DEFAULT_ORG org = repo_elms.pop || Config['FCL_DEFAULT_ORG']
forge = repo_elms.pop || 'github.com' forge = repo_elms.pop || 'github.com'
File.join(forge, org, repo) File.join(forge, org, repo)
@ -69,7 +72,7 @@ end
repo_str = ARGV.empty? ? `gum input --header="Enter a repo name" --placeholder=""`.chomp : ARGV[0] repo_str = ARGV.empty? ? `gum input --header="Enter a repo name" --placeholder=""`.chomp : ARGV[0]
destination = ARGV[1] || destination_path(repo_str) destination = ARGV[1] || destination_path(repo_str)
full_dest = File.join(REPO_BASE, destination) full_dest = File.join(Config['REPOSITORY_BASE'], destination)
clone_url = repo_url(repo_str) clone_url = repo_url(repo_str)