Sha256: 956f358950dba1dbbc490ffae1b92cec273a242edc8c646f248c037250ea3402
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
# -*- ruby -*- # # * datafileを読み、引数とマッチするものをリストする # 引数はARGVに入っている # require 'json' require 're_expand' class HelpLine def generate(query,debug=nil) data = JSON.parse(File.read(datafile)) # # 関数定義などをeval # data['codes'].each { |code| eval code } g = ExpandRuby::Generator.new # re_expandのジェネレータ # # HelpLineエントリ # logfile = (debug ? "/tmp/helpline-defs" : "/dev/null") File.open(logfile,"w"){ |f| # ログを残す場合 entries = [] data['defs'].each { |line| if line =~ /^[\$\?]\s*(.*)$/ # $.... entries << $1 elsif line =~ /^\%\s*(.*)$/ # %.... cmd = $1 entries.each { |l| desc = eval('"' + l + '"') f.puts "desc: #{desc}" g.add desc.force_encoding('utf-8'), cmd.force_encoding('utf-8') } f.puts "cmd: #{cmd}" entries = [] end } } res = g.generate query File.open("/tmp/helpline.cmd","w"){ |f| f.puts ARGV.join(' ') } if res[0].length == 0 puts "ヘルプがみつかりません" exit end git_repository = File.exist?(".git") listed = {} list = res[0].find_all { |a| # 0 ambig # a = ["現在の状況を表示する {56}", "git status {56}"], etc. if a[0] =~ /voidvoidvoid/ false elsif a[0] =~ /^git:/ && !git_repository false else if listed[a[1]] false else listed[a[1]] = true end end } list end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
helpline-0.2.1 | lib/helpline/generate.rb |