fcl: Get config from config.bash (kludge du jour)
This commit is contained in:
15
fcl
15
fcl
@ -15,8 +15,11 @@
|
||||
# [ ] 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)
|
||||
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.
|
||||
when /^[\w\-_]+\/[\w\-_\.]+$/
|
||||
"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\-_\.]+$/
|
||||
"https://github.com/#{DEFAULT_ORG}/#{repo_str}.git"
|
||||
"https://github.com/#{Config['FCL_DEFAULT_ORG']}/#{repo_str}.git"
|
||||
else
|
||||
raise "I can't make a repo URL out of '#{repo_str}'."
|
||||
end
|
||||
@ -60,7 +63,7 @@ def destination_path(repo_str)
|
||||
repo_elms = repo_str.split('/')
|
||||
|
||||
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'
|
||||
|
||||
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]
|
||||
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user