Fix several rubocop issues with "rubocop -a"
This commit is contained in:
@@ -31,22 +31,22 @@ class Homesick < Thor
|
||||
destination = nil
|
||||
if File.exist?(uri)
|
||||
uri = Pathname.new(uri).expand_path
|
||||
raise "Castle already cloned to #{uri}" if uri.to_s.start_with?(repos_dir.to_s)
|
||||
fail "Castle already cloned to #{uri}" if uri.to_s.start_with?(repos_dir.to_s)
|
||||
|
||||
destination = uri.basename
|
||||
|
||||
ln_s uri, destination
|
||||
elsif uri =~ GITHUB_NAME_REPO_PATTERN
|
||||
destination = Pathname.new(uri).basename
|
||||
git_clone "https://github.com/#{$1}.git", :destination => destination
|
||||
git_clone "https://github.com/#{Regexp.last_match[1]}.git", destination: destination
|
||||
elsif uri =~ /%r([^%r]*?)(\.git)?\Z/
|
||||
destination = Pathname.new($1)
|
||||
destination = Pathname.new(Regexp.last_match[1])
|
||||
git_clone uri
|
||||
elsif uri =~ /[^:]+:([^:]+)(\.git)?\Z/
|
||||
destination = Pathname.new($1)
|
||||
destination = Pathname.new(Regexp.last_match[1])
|
||||
git_clone uri
|
||||
else
|
||||
raise "Unknown URI format: #{uri}"
|
||||
fail "Unknown URI format: #{uri}"
|
||||
end
|
||||
|
||||
if destination.join('.gitmodules').exist?
|
||||
@@ -80,7 +80,7 @@ class Homesick < Thor
|
||||
end
|
||||
|
||||
desc 'pull CASTLE', 'Update the specified castle'
|
||||
method_option :all, :type => :boolean, :default => false, :required => false, :desc => 'Update all cloned castles'
|
||||
method_option :all, type: :boolean, default: false, required: false, desc: 'Update all cloned castles'
|
||||
def pull(name = DEFAULT_CASTLE_NAME)
|
||||
if options[:all]
|
||||
inside_each_castle do |castle|
|
||||
@@ -90,13 +90,11 @@ class Homesick < Thor
|
||||
else
|
||||
update_castle name
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
desc 'commit CASTLE MESSAGE', "Commit the specified castle's changes"
|
||||
def commit(name = DEFAULT_CASTLE_NAME, message = nil)
|
||||
commit_castle name, message
|
||||
|
||||
end
|
||||
|
||||
desc 'push CASTLE', 'Push the specified castle'
|
||||
@@ -122,7 +120,7 @@ class Homesick < Thor
|
||||
end
|
||||
|
||||
desc 'symlink CASTLE', 'Symlinks all dotfiles from the specified castle'
|
||||
method_option :force, :default => false, :desc => 'Overwrite existing conflicting symlinks without prompting.'
|
||||
method_option :force, default: false, desc: 'Overwrite existing conflicting symlinks without prompting.'
|
||||
def symlink(name = DEFAULT_CASTLE_NAME)
|
||||
check_castle_existance(name, 'symlink')
|
||||
|
||||
@@ -231,20 +229,19 @@ class Homesick < Thor
|
||||
end
|
||||
end
|
||||
|
||||
desc "destroy CASTLE", "Delete all symlinks and remove the cloned repository"
|
||||
desc 'destroy CASTLE', 'Delete all symlinks and remove the cloned repository'
|
||||
def destroy(name)
|
||||
check_castle_existance name, "destroy"
|
||||
check_castle_existance name, 'destroy'
|
||||
|
||||
if shell.yes?("This will destroy your castle irreversible! Are you sure?")
|
||||
if shell.yes?('This will destroy your castle irreversible! Are you sure?')
|
||||
unlink(name)
|
||||
rm_rf repos_dir.join(name)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
desc "cd CASTLE", "Open a new shell in the root of the given castle"
|
||||
desc 'cd CASTLE', 'Open a new shell in the root of the given castle'
|
||||
def cd(castle = DEFAULT_CASTLE_NAME)
|
||||
check_castle_existance castle, "cd"
|
||||
check_castle_existance castle, 'cd'
|
||||
castle_dir = repos_dir.join(castle)
|
||||
say_status "cd #{castle_dir.realpath}", "Opening a new shell in castle '#{castle}'. To return to the original one exit from the new shell.", :green
|
||||
inside castle_dir do
|
||||
@@ -252,14 +249,14 @@ class Homesick < Thor
|
||||
end
|
||||
end
|
||||
|
||||
desc "open CASTLE", "Open your default editor in the root of the given castle"
|
||||
desc 'open CASTLE', 'Open your default editor in the root of the given castle'
|
||||
def open(castle = DEFAULT_CASTLE_NAME)
|
||||
if ! ENV['EDITOR']
|
||||
say_status :error,"The $EDITOR environment variable must be set to use this command", :red
|
||||
if !ENV['EDITOR']
|
||||
say_status :error, 'The $EDITOR environment variable must be set to use this command', :red
|
||||
|
||||
exit(1)
|
||||
end
|
||||
check_castle_existance castle, "open"
|
||||
check_castle_existance castle, 'open'
|
||||
castle_dir = repos_dir.join(castle)
|
||||
say_status "#{ENV['EDITOR']} #{castle_dir.realpath}", "Opening the root directory of castle '#{castle}' in editor '#{ENV['EDITOR']}'.", :green
|
||||
inside castle_dir do
|
||||
@@ -297,7 +294,7 @@ class Homesick < Thor
|
||||
def all_castles
|
||||
dirs = Pathname.glob("#{repos_dir}/**/.git", File::FNM_DOTMATCH)
|
||||
# reject paths that lie inside another castle, like git submodules
|
||||
return dirs.reject do |dir|
|
||||
dirs.reject do |dir|
|
||||
dirs.any? do |other|
|
||||
dir != other && dir.fnmatch(other.parent.join('*').to_s)
|
||||
end
|
||||
@@ -325,7 +322,7 @@ class Homesick < Thor
|
||||
def commit_castle(castle, message)
|
||||
check_castle_existance(castle, 'commit')
|
||||
inside repos_dir.join(castle) do
|
||||
git_commit_all :message => message
|
||||
git_commit_all message: message
|
||||
end
|
||||
end
|
||||
|
||||
@@ -402,7 +399,7 @@ class Homesick < Thor
|
||||
def each_file(castle, basedir, subdirs)
|
||||
absolute_basedir = Pathname.new(basedir).expand_path
|
||||
inside basedir do
|
||||
files = Pathname.glob('{.*,*}').reject{ |a| ['.', '..'].include?(a.to_s) }
|
||||
files = Pathname.glob('{.*,*}').reject { |a| ['.', '..'].include?(a.to_s) }
|
||||
files.each do |path|
|
||||
absolute_path = path.expand_path
|
||||
castle_home = castle_dir(castle)
|
||||
|
||||
@@ -9,7 +9,7 @@ class Homesick
|
||||
destination = Pathname.new(destination) unless destination.kind_of?(Pathname)
|
||||
FileUtils.mkdir_p destination.dirname
|
||||
|
||||
if ! destination.directory?
|
||||
if !destination.directory?
|
||||
say_status 'git clone', "#{repo} to #{destination.expand_path}", :green unless options[:quiet]
|
||||
system "git clone -q --config push.default=upstream --recursive #{repo} #{destination}" unless options[:pretend]
|
||||
else
|
||||
@@ -78,12 +78,12 @@ class Homesick
|
||||
|
||||
def git_status(config = {})
|
||||
say_status 'git status', '', :green unless options[:quiet]
|
||||
system "git status" unless options[:pretend]
|
||||
system 'git status' unless options[:pretend]
|
||||
end
|
||||
|
||||
def git_diff(config = {})
|
||||
say_status 'git diff', '', :green unless options[:quiet]
|
||||
system "git diff" unless options[:pretend]
|
||||
system 'git diff' unless options[:pretend]
|
||||
end
|
||||
|
||||
def mv(source, destination, config = {})
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class Homesick
|
||||
# Hack in support for diffing symlinks
|
||||
class Shell < Thor::Shell::Color
|
||||
|
||||
def show_diff(destination, content)
|
||||
destination = Pathname.new(destination)
|
||||
|
||||
@@ -12,6 +11,5 @@ class Homesick
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user