lib/dotter/cli.rb in dotter_dotfiles-0.1.0 vs lib/dotter/cli.rb in dotter_dotfiles-0.2.0
- old
+ new
@@ -22,22 +22,17 @@
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
desc "list", "List all packages present in ~/dotfiles"
def list
puts "List of packages in ~/dotfiles"
- directory_name = dotfiles_path
- directory = Pathname.new(directory_name)
- directories = directory.children.select { |c| c.directory? }
- package_names = []
- directories.each do |directory|
- package_names.push(directory.basename)
- end
- package_names.each do |package|
+ all_package_names.each do |package|
puts package
end
end
desc "stow PACKAGE", "Stow the given package name."
def stow(package)
@@ -112,15 +107,25 @@
package.update
end
desc "update_all", "Updates all stowed packages."
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 { |package| package.stowed? }
+ stowed_packages.each do |package|
+ puts "Updating #{package}"
+ package.update
+ end
end
desc "import PATH PACKAGE", "Imports a file or directory into the specified package"
def import(path, package)
- puts "Importing #{path} into package {package}"
+ puts "Importing #{path} into package #{package}"
filepath = Pathname.new(File.expand_path(path))
packagepath = package_path(package)
+ if not Dir.exist?(packagepath.to_s) then FileUtils.mkpath(packagepath.to_s) end
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."