Class: Reposh
- Inherits:
-
Object
- Object
- Reposh
- Defined in:
- lib/reposh.rb
Defined Under Namespace
Classes: Commands
Constant Summary collapse
- VERSION =
"0.1.6"
- CONF_DEFAULT =
{ "global" => { "editing_mode" => nil, "custom_commands" => [], "pathext" => [], }, "system" => { "default" => { "binpath" => nil, "prompt" => "> ", "default_cmd" => "status", }, "darcs" => { "default_cmd" => "whatsnew --summary", } } }
Instance Method Summary collapse
- #get_conf(system, prop) ⇒ Object
- #guess_system ⇒ Object
- #load_config(path) ⇒ Object
- #parse_option(args) ⇒ Object
- #run ⇒ Object
- #run_loop ⇒ Object
Instance Method Details
#get_conf(system, prop) ⇒ Object
102 103 104 |
# File 'lib/reposh.rb', line 102 def get_conf(system, prop) (@conf["system"][system] and @conf["system"][system][prop]) or @conf["system"]["default"][prop] end |
#guess_system ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/reposh.rb', line 89 def guess_system case when File.directory?(".hg") "hg" when File.directory?("_darcs") "darcs" when File.directory?(".svn") "svn" else "svk" end end |
#load_config(path) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/reposh.rb', line 80 def load_config(path) if File.exist?(path) config_hash = YAML.load(File.read(path)) CONF_DEFAULT.recursive_merge(config_hash) else CONF_DEFAULT end end |
#parse_option(args) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/reposh.rb', line 56 def parse_option(args) o = OptionParser.new{|opt| opt.on("-c confpath", "path to .reposh.yaml"){|path| @confpath = path } opt.on("-s system", "vcs command name (eg. svn, svk, hg)"){|sys| @system_name = sys } opt.on("-h", "--help", "show this message"){ puts opt exit } opt.on("-v", "--version", "show version information"){ puts VERSION exit } } o.parse(args) end |
#run ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/reposh.rb', line 38 def run parse_option(ARGV) @conf_path ||= File.join(ENV["HOME"], ".reposh.yaml") @system_name ||= guess_system @conf = load_config(@conf_path) @editing_mode = @conf["global"]["editing_mode"] pathext = @conf["global"]["pathext"] @prompt = get_conf(@system_name, "prompt") binpath = get_conf(@system_name, "binpath") || @system_name default_cmd = get_conf(@system_name, "default_cmd") @commands = Commands.new(binpath, default_cmd, pathext) @commands.register_custom_commands(@conf["global"]["custom_commands"]) run_loop end |
#run_loop ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/reposh.rb', line 106 def run_loop if @editing_mode == "vi" Readline.vi_editing_mode end puts "Welcome to reposh #{VERSION} (mode: #{@system_name})" loop do cmd = Readline.readline(@prompt, true) @commands.dispatch(cmd, @system_name) end end |