Sha256: d0300bc92c72d332115b4efd9151851af19dd0c943d91634be875933c10d822e

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require "thor"

module Museo
  class CLI < Thor
    desc "list [MATCHER]", "List snapshots that match MATCHER"
    def list(matcher = nil)
      directory = find_directory(matcher)

      if File.directory?(directory)
        puts "Directory: #{directory}\n\n"
        list_files(directory)
      else
        puts "No directory found: #{directory}"
      end
    end

    desc "clear [MATCHER]", "Clear snapshots that match MATCHER"
    def clear(matcher = nil)
      list(matcher)

      puts "Removing snapshots"
      Museo.clear!(matcher)
    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.3.0 lib/museo/cli.rb