Class: LlmLabelLauncher
- Inherits:
-
Object
- Object
- LlmLabelLauncher
- Defined in:
- lib/llm_label_launcher.rb
Constant Summary collapse
- CONFIG_PATH =
File.("~/.label_launcher.config")
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#labels ⇒ Object
Returns the value of attribute labels.
-
#list ⇒ Object
Returns the value of attribute list.
-
#to_open ⇒ Object
Returns the value of attribute to_open.
Instance Method Summary collapse
- #command(args) ⇒ Object
-
#initialize ⇒ LlmLabelLauncher
constructor
A new instance of LlmLabelLauncher.
- #run ⇒ Object
Constructor Details
#initialize ⇒ LlmLabelLauncher
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/llm_label_launcher.rb', line 10 def initialize if !File.exists?(CONFIG_PATH) File.open(CONFIG_PATH, 'w') { |f| f.write(%| # 注释代码 # 格式为:[名称] [路径/参数] [启动器] # 例:百度 https://www.baidu.com/ google-chrome |.strip) } end config_text = File.open(CONFIG_PATH, 'r') { |f| f.read } self.labels = parse_labels(config_text) end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/llm_label_launcher.rb', line 6 def config @config end |
#labels ⇒ Object
Returns the value of attribute labels.
5 6 7 |
# File 'lib/llm_label_launcher.rb', line 5 def labels @labels end |
#list ⇒ Object
Returns the value of attribute list.
6 7 8 |
# File 'lib/llm_label_launcher.rb', line 6 def list @list end |
#to_open ⇒ Object
Returns the value of attribute to_open.
6 7 8 |
# File 'lib/llm_label_launcher.rb', line 6 def to_open @to_open end |
Instance Method Details
#command(args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/llm_label_launcher.rb', line 36 def command(args) OptionParser.new do |parser| parser. = "用法: llm_label_launcher [options]" parser.separator "" parser.separator "指定选项:" # 配置 parser.on('-c', '--config', %|查看配置文件路径|) do |config| self.config = config end # 查找 parser.on('-l', "--list", '列出标签') do self.list = true end # 打开标签 parser.on('-o TEXT', '--open TEXT', '打开标签,默认第一个匹配项') do |text| self.to_open = text end parser.separator "" parser.separator "通用选项:" parser.on_tail("-h", "--help", "帮助信息") do puts parser exit end parser.on_tail("--version", "版本信息") do puts '0.0.1' exit end end.parse!(args) run end |
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/llm_label_launcher.rb', line 22 def run if config return CONFIG_PATH end return to_text(labels) if File.exists?(CONFIG_PATH) if list if to_open label = to_open.to_i.to_s == to_open ? labels[to_open.to_i] : labels.select { |l| l[0].include?(to_open) }.first return "not found label on #{to_open}" if label.nil? `#{label[-1]} #{label[-2]}` end end |