class Dotter::CLI
Public Instance Methods
add(package, file)
click to toggle source
# File lib/dotter/cli.rb, line 177 def add(package, file) package = Package.new(package) if package.untracked? error "Package #{package} is not tracked by Git." exit 1 end puts "Marking #{file} to be committed for package #{package}" repo = package.repo repo.add(file) end
clone(repo_url)
click to toggle source
# File lib/dotter/cli.rb, line 155 def clone(repo_url) puts "Cloning repository #{repo_url} directly into ~/dotfiles" repo = Git.clone(repo_url, @@dotfiles_path.to_s) puts "Due to implementation difficulties, all the the commit history and state information will be lost." go_to_dotfiles `rm -rf .git` `rm -rf dotter/*` `touch dotter/Dotfile` end
commit(package)
click to toggle source
# File lib/dotter/cli.rb, line 86 def commit(package) package = Package.new(package) if package.untracked? error "Package #{package} is not tracked by Git." exit 1 end puts "Committing the changes to package #{package} with commit message #{options.commit_message}." commit_message = options.commit_message repo = package.repo if options.all repo.commit_all(commit_message) else repo.commit(commit_message) end end
import(path, package)
click to toggle source
# File lib/dotter/cli.rb, line 132 def import(path, package) puts "Importing #{path} into package #{package}" filepath = Pathname.new(File.expand_path(path)) packagepath = package_path(package) FileUtils.mkpath(packagepath.to_s) unless Dir.exist?(packagepath.to_s) homepath = Pathname.new(File.expand_path('~')) relative_filepath = filepath.relative_path_from(homepath) complete_path = packagepath + relative_filepath FileUtils.copy(File.expand_path(path), complete_path.to_s) puts 'File imported successfully. Update the package to make the symlink.' end
import_repo(repo_url, package)
click to toggle source
# File lib/dotter/cli.rb, line 144 def import_repo(repo_url, package) puts "Cloning repository #{repo_url} into package #{package}" ForeignGitRepo.new(package, true, repo_url) puts "Repository #{repo_url} successfully cloned into #{package}." # We need to manually set the package as tracked to avoid calling init() again. config = Configuration.new config.track(package) config.set_type(package, 'git_repo') config.set_url(package, repo_url) end
init()
click to toggle source
# File lib/dotter/cli.rb, line 19 def init puts 'Initialising ~/dotfiles' puts 'Creating the dotfiles directory.' FileUtils.mkpath(dotfiles_path) go_to_dotfiles puts 'Creating the directory for the combined public dotfiles.' FileUtils.mkpath('public') puts 'Creating an initial package for dotter.' FileUtils.mkpath('dotter/.dotter/gitrepos') FileUtils.mkpath('dotter/.dotter/indexes/') # If we don't do this now, we'll get a nasty exception if we ever access the configuration. FileUtils.touch('dotter/.dotter/Dotfile') end
list()
click to toggle source
# File lib/dotter/cli.rb, line 33 def list puts 'List of packages in ~/dotfiles' all_package_names.each do |package| puts package end end
log(package)
click to toggle source
# File lib/dotter/cli.rb, line 199 def log(package) package = Package.new(package) if package.untracked? error "Package #{package} is not tracked by Git." exit 1 end puts "Obtaining the log of package #{package}" repo = package.repo repo.log.each do |commit| puts "[#{commit.date}] #{commit.message} (#{commit.author.name})" end end
publish(package)
click to toggle source
# File lib/dotter/cli.rb, line 72 def publish(package) puts "Making package #{package} public" public_repo = PublicGitRepo.new puts public_repo.add_package(package) end
reset(package)
click to toggle source
# File lib/dotter/cli.rb, line 188 def reset(package) package = Package.new(package) if package.untracked? error "Package #{package} is not tracked by Git." exit 1 end puts "Resetting what will be committed to package #{package}" repo = package.repo repo.reset end
status(package)
click to toggle source
# File lib/dotter/cli.rb, line 165 def status(package) package = Package.new(package) if package.untracked? error "Package #{package} is not tracked by Git." exit 1 end metadata_path = repo_path(package.to_s) metadata_indexes_path = index_path(package.to_s) # Punt because it does this better than ruby-git. system({ 'GIT_DIR' => metadata_path.to_s, 'GIT_INDEX_FILE' => metadata_indexes_path.to_s }, 'git status') end
stow(package)
click to toggle source
# File lib/dotter/cli.rb, line 40 def stow(package) package = Package.new(package) if package.stowed? error "Package #{package} is already stowed." exit(1) end puts "Stowing package #{package}" puts package.stow end
track(package)
click to toggle source
# File lib/dotter/cli.rb, line 60 def track(package) puts "Initialising Git repository for package #{package}" package = Package.new(package) package.track puts "Repository for package #{package} initialised. Git's metadata is stored in #{package.repo.metadata_path}" puts 'Creating an initial snapshot to serve as a starting point.' repo = package.repo repo.add('.') repo.commit_all("Initial snapshot of the package's contents") puts 'Initial snapshot created.' end
unpublish(package)
click to toggle source
# File lib/dotter/cli.rb, line 78 def unpublish(package) puts "Making package #{package} private again" public_repo = PublicGitRepo.new public_repo.remove_package(package) end
unstow(package)
click to toggle source
# File lib/dotter/cli.rb, line 50 def unstow(package) package = Package.new(package) if package.unstowed? error "Package #{package} is not stowed." exit(1) end puts "Unstowing package #{package}" puts package.unstow end
update(package)
click to toggle source
# File lib/dotter/cli.rb, line 102 def update(package) puts "Updating the contents / symlinks for package #{package}" package = Package.new(package) if package.unstowed? error "Package #{package} is not stowed and therefore cannot be updated." exit 1 end package.update end
update_all()
click to toggle source
# File lib/dotter/cli.rb, line 112 def update_all puts 'Updating all stowed packages' all_packages = [] all_package_names.each do |package| all_packages.push(Package.new(package.to_s)) end stowed_packages = all_packages.select(&:stowed?) stowed_packages.each do |package| puts "Updating #{package}" package.update end end
update_public()
click to toggle source
# File lib/dotter/cli.rb, line 125 def update_public puts "Updating the public repository." public_repo = PublicGitRepo.new puts public_repo.update public_repo.push end
version()
click to toggle source
# File lib/dotter/cli.rb, line 15 def version puts "This is dotter #{Dotter::VERSION}" end