Class: Reposh
- Inherits:
-
Object
- Object
- Reposh
- Defined in:
- lib/reposh.rb
Defined Under Namespace
Classes: Commands
Constant Summary collapse
- VERSION =
File.read(Pathname(__FILE__).dirname + "../VERSION").chomp
- 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
113 114 115 |
# File 'lib/reposh.rb', line 113 def get_conf(system, prop) (@conf["system"][system] and @conf["system"][system][prop]) or @conf["system"]["default"][prop] end |
#guess_system ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/reposh.rb', line 91 def guess_system base = Pathname(Dir.pwd) loop do case when (base + ".git").directory? return "git" when (base + ".hg").directory? return "hg" when (base + "_darcs").directory? return "darcs" when (base + ".svn").directory? return "svn" end if base.root? return "svk" else base = base.parent end end end |
#load_config(path) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/reposh.rb', line 81 def load_config(path) if File.exist?(path) config_hash = YAML.load(File.read(path)) puts "loaded config file: #{path}" CONF_DEFAULT.recursive_merge(config_hash) else CONF_DEFAULT end end |
#parse_option(args) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/reposh.rb', line 57 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/reposh.rb', line 39 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
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/reposh.rb', line 117 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 |