Sha256: a41329ee741edbc855f775c62160cac1dd995772ba740e11e1caa042fb881a6d
Contents?: true
Size: 1.42 KB
Versions: 1
Compression:
Stored size: 1.42 KB
Contents
module Museo class CLI def initialize(command = nil, *argv) case command.to_s.strip.downcase when "clear" clear(argv.first) when "list" list(argv.first) when "" puts "Please add a command" else puts "Don't know how to do command: #{command}" end end def list(matcher) directory = find_directory(matcher) if File.directory?(directory) puts "Directory: #{directory}\n\n" list_files(directory) else puts "No directory found: #{directory}" end end def clear(matcher) list(matcher) directory_to_clear = find_directory(matcher) return unless File.directory?(directory_to_clear) puts "Removing snapshots" FileUtils.remove_dir(directory_to_clear) end private def find_directory(matcher_or_pathname) return matcher_or_pathname if matcher_or_pathname.is_a?(Pathname) Museo.pathname(matcher_or_pathname) end def files(matcher) directory = find_directory(matcher) return [] unless directory Dir[directory.join("**", "*.snapshot")].map do |snapshot| Pathname.new(snapshot) end end def list_files(directory) files = files(directory) if files.any? files.each do |path| puts path.relative_path_from(directory) end else puts "No files" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
museo-0.1.0 | lib/museo/cli.rb |