Sha256: 423bc68d30e85290b8c7c885f8c19d1c7a79687b51bc6667e35b3ee4c6da674a

Contents?: true

Size: 1.98 KB

Versions: 10

Compression:

Stored size: 1.98 KB

Contents

#!/usr/bin/env ruby

require 'treet'
require "thor"

class TreetCommand < Thor
  desc "export ROOTDIR", "convert a collection of repositories to a single JSON blob"
  method_option :xref, :desc => "optional fieldname to be added under `xref` with basename of repository"
  def export(path)
    # if !File.directory?(path)
    #   raise "treet export: could not find #{path}"
    # end

    farm = Treet::Farm.new(:root => path, :xref => options[:xref])
    jj farm.export
  end


  desc "create JSONFILE", "build a single repository from a JSON file"
  method_option :root, :required => true
  def create(jsonfile)
    hash = Treet::Hash.new(jsonfile)
    hash.to_repo(options[:root])
    $stderr.puts "Wrote repository to #{options[:root]}"
  end


  desc "show DIRECTORY", "convert a single repository to a JSON blob"
  def show(path)
    repo = Treet::Repo.new(path)
    jj repo.to_hash
  end


  desc "explode JSONFILE", "Build a collection of repositories from a JSON file"
  method_option :root, :required => true, :desc => "where to create repositories (will be created if does not exist)"
  def explode(jsonfile)
    if !File.directory?(options[:root])
      Dir.mkdir(options[:root])
    end

    farm = Treet::Farm.plant(:json => jsonfile, :root => options[:root])
    filecount = Dir.glob("#{farm.root}/*").count
    $stderr.puts "Wrote #{filecount} files to #{farm.root}"
  end


  desc "patch JSONFILE", "Apply patches from file to specified repository tree"
  method_option :root, :required => true, :desc => "where to find repositories to patch"
  method_option :xref, :required => true, :desc => "fieldname under `xref` to use for repository identification"
  def patch(patchfile)
    patches = JSON.load(File.open(patchfile))
    farm = Treet::Farm.new(:root => options[:root], :xref => options[:xref])
    results = farm.patch(patches)
    $stderr.puts "Patched #{results.count} records."
  end

  desc "version", "show Treet version"
  def version
    puts "Treet #{Treet::VERSION}"
  end
end

TreetCommand.start

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
treet-0.18.0 bin/treet
treet-0.17.1 bin/treet
treet-0.15.0 bin/treet
treet-0.14.1 bin/treet
treet-0.14.0 bin/treet
treet-0.13.1 bin/treet
treet-0.11.0 bin/treet
treet-0.10.3 bin/treet
treet-0.10.2 bin/treet
treet-0.8.2 bin/treet