Created
December 17, 2011 20:32
-
-
Save itguy51/1491285 to your computer and use it in GitHub Desktop.
Git-Based file management written in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'grit' | |
include Grit | |
#Assume that the repo exists in some way or another, if not, create it. | |
if(FileTest.exists?('repo.git')) | |
repo = Repo.new('repo.git') | |
else | |
repo = Repo.init_bare('repo.git') | |
end | |
if(ARGV[0] == 'file') | |
index = Index.new(repo) | |
if(ARGV[2] == 'stdin') | |
index.add(ARGV[1], STDIN.read) | |
else | |
index.add(ARGV[1], ARGV[2]) | |
end | |
index.commit('Added File via RGitCLI') | |
puts "Filed." | |
elsif(ARGV[0] == 'seek') | |
unless repo.tree/ARGV[1].nil? | |
puts (repo.tree / ARGV[1]).data | |
end | |
else | |
puts 'Syntax: filer <FUNCTION> <FILE> <CONTENT>' | |
puts '<FUCNTION>: One of (file, seek)' | |
puts '-File stores <CONTENT> into <FILE>' | |
puts '-Seek gets content from <FILE>. Arg <CONTENT> is not used here.' | |
puts '<FILE>: The name of the file to store to' | |
puts '<CONTENT>: One of (*String, stdin)' | |
puts '-stdin gets <CONTENT> from Standard Input' | |
puts '-*String is any string in double quotes.' | |
exit | |
end | |
#Alright. Now, Re-run with ARGV[0] as seek insetad of file. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment