# File 'lib/thor/runner.rb', line 41definstall(name)# rubocop:disable MethodLength
initialize_thorfiles# If a directory name is provided as the argument, look for a 'main.thor'
# command in said directory.
beginifFile.directory?(File.expand_path(name))base,package=File.join(name,"main.thor"),:directorycontents=open(base){|input|input.read}elsebase,package=name,:filecontents=open(name){|input|input.read}endrescueOpenURI::HTTPErrorraiseError,"Error opening URI '#{name}'"rescueErrno::ENOENTfailError,"Error opening file '#{name}'"endsay"Your Thorfile contains:"saycontentsunlessoptions["force"]returnfalseifno?("Do you wish to continue [y/N]?")endas=options["as"]||beginfirst_line=contents.split("\n")[0](match=first_line.match(/\s*#\s*module:\s*([^\n]*)/))?match[1].strip:nilendunlessasbasename=File.basename(name)as=ask("Please specify a name for #{name} in the system repository [#{basename}]:")as=basenameifas.empty?endlocation=ifoptions[:relative]||name=~%r{^https?://}nameelseFile.expand_path(name)endthor_yaml[as]={:filename=>Digest::MD5.hexdigest(name+as),:location=>location,:namespaces=>Thor::Util.namespaces_in_content(contents,base)}save_yaml(thor_yaml)say"Storing thor file in your system repository"destination=File.join(thor_root,thor_yaml[as][:filename])ifpackage==:fileFile.open(destination,"w"){|f|f.putscontents}elseFileUtils.cp_r(name,destination)endthor_yaml[as][:filename]# Indicate success
end