bin/git-meta in git-meta-1.0.0 vs bin/git-meta in git-meta-2.0.0
- old
+ new
@@ -1,22 +1,20 @@
#!/usr/bin/env ruby
require 'optparse'
-options = {:all => false, :sha => ARGV.shift}
+$:.unshift File.expand_path("#{File.dirname(__FILE__)}/../lib")
+require 'git_meta'
+options = {:command => ARGV.shift || "get", :sha => ARGV.shift, :key => nil}
+
optparser = OptionParser.new do |parser|
- parser.banner = "Usage: git-meta [sha|ref] [ --get | --get-all ]"
-
- parser.on('-a', '--get-all',
- "Retrieves all the keys as YAML data.") do |all|
- options[:all] = all
- end
+ parser.banner = "Usage: git-meta get [ sha | ref ] [ --get KEY ]"
parser.on('-g', '--get KEY',
"Retrives a certain KEY from the git commit object") do |key|
- options[:keys] = key.split(".")
+ options[:key] = key
end
parser.on('-h', '--help',
"Returns Usage Notes") do
puts parser
@@ -30,22 +28,7 @@
exit
end
optparser.parse(ARGV)
-git_commit_info, data, output = nil, nil, nil
-
-IO.popen("git-cat-file -p #{options[:sha]}", 'r') do |git_cat_file|
- git_commit_info = git_cat_file.read
-end
-
-if git_commit_info =~ /^(---git-meta---\s*\n)(.*\n)(^---git-meta---.*\n)/m
- if options[:keys]
- data = YAML.load($2)
- options[:keys].each do |key|
- data = data.fetch(key, Hash.new(""))
- end
- puts data.to_yaml.gsub(/^--- \n?/, '')
- elsif options[:all]
- puts $2
- end
-end
+@getter = GitMeta::Get.new(options[:sha], options[:key])
+puts @getter