Sha256: 3bd4980e99908883240be9d81a8fbdc6528b16ca1c4f5bc55ac4adda58f0c668
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
#!/usr/bin/env ruby require 'rubygems' require 'optparse' require 'pp' $:.unshift File.join(File.dirname(__FILE__), '..', 'lib') require 'cheeba' module CheebaOpt DESC = Cheeba::Defaults.descriptions def self.command hsh = {} hsh[:opt] = {} ops = nil OptionParser.new do |opts| opts.banner = "Cheeba #{Cheeba::VERSION}" opts.on("-r", "--read FILENAME", String, String, ".cash file to Ruby Hash or Array") do |x| hsh[:cmd] = 1 hsh[:arg] = [x] end opts.on("-w", "--write FILENAME,FILENAME", Array, "Hash or Array => .cash file") do |x| hsh[:cmd] = 2 hsh[:arg] = x end opts.on("-d", "--dotfile [HOME]", String, "Create .cheeba dotfile") do |x| x.nil? ? (y = Cheeba.dotfile) : (y = Cheeba.dotfile(x)) z = "#{File.dirname(y).chomp("/")}/.cheeba" puts "existed: #{z}, moved to: #{y}" if File.basename(y) != ".cheeba" puts "created: #{z}" return end opts.on("-v", "--version", "Display verison number") do STDOUT.write("Cheeba #{Cheeba::VERSION}\n\r") return end opts.on("-h", "--help", "Show this message") do puts opts return end Cheeba::Defaults.constants.sort.each do |x| next if x == "DOTFILE" opts.on("--[no-]#{x.downcase}", DESC[x.downcase]) do |y| hsh[:opt]["#{x.downcase}".to_sym] = y puts "use options with --read or --write" && return if hsh[:cmd].nil? end end ops = opts end.parse! puts ops unless hsh.has_key?(:cmd) return unless hsh.has_key?(:cmd) self.run(hsh[:cmd], hsh[:arg], hsh[:opt]) end def self.run(cmd, arg, opt) x = Cheeba.read(arg[0], opt) case cmd when 1: pp x when 2: Cheeba.write(arg[0], arg[1], opt) end end end CheebaOpt.command
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cheeba-1.1.0 | bin/cheeba |