Class: Aka::Store
- Inherits:
-
Object
- Object
- Aka::Store
- Includes:
- Methadone::CLILogging
- Defined in:
- lib/aka/store.rb
Instance Method Summary collapse
- #add(options) ⇒ Object
- #edit(options) ⇒ Object
- #generate(options) ⇒ Object
- #help(command, options) ⇒ Object
- #link(options) ⇒ Object
- #list(options) ⇒ Object
- #remove(options) ⇒ Object
- #show(options) ⇒ Object
- #sync(match) ⇒ Object
- #unlink(key) ⇒ Object
- #upgrade(options) ⇒ Object
Instance Method Details
#add(options) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/aka/store.rb', line 39 def add() found = configuration.shortcuts.find() if found.length > 0 unless [:force] abort %{Shortcut "#{[:shortcut]}" exists. Pass --force to overwrite. Or provide a new --tag.} else found.each do |n, row| configuration.shortcuts.replace(n, Configuration::Shortcut.parse()) end configuration.save puts "Overwrote shortcut." end else configuration.shortcuts.append(Configuration::Shortcut.parse()) configuration.save puts "Created shortcut." end end |
#edit(options) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/aka/store.rb', line 125 def edit() result = nil found = configuration.shortcuts.find() index, row = found.first unless row abort "Shortcut not found." end if [:input] result = File.read([:input]) else file = Tempfile.new('shortcut') begin file.open if row.tag = %{ #{row.tag.join(', ')}} else = '' end file.write(<<-EOS.gsub(/^ /, '') Shortcut: #{row.shortcut} Description: #{row.description} Function (y/n): #{row.function ? 'y' : 'n'} Tags:#{} Command: #{row.command} EOS ) file.close editor = ENV['EDITOR'] || 'vim' system(%[#{editor} #{file.path}]) debug("Editing exited with code: #{$?.exitstatus}.") if $?.exitstatus == 0 file.open file.rewind result = file.read.strip end ensure file.unlink end end if result parse_row_txt(row, result) configuration.shortcuts.replace(index, row) configuration.save puts "Saved shortcut." else end end |
#generate(options) ⇒ Object
99 100 101 102 103 |
# File 'lib/aka/store.rb', line 99 def generate() excluded = configuration.shortcuts.generate() excluded_output(excluded) end |
#help(command, options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/aka/store.rb', line 10 def help(command, ) case command when nil then command = "aka.7" else command = "aka-#{command}.1" end manpages = %w( aka-add.1 aka-edit.1 aka-generate.1 aka-list.1 aka-remove.1 aka-show.1 aka-link.1 aka-sync.1 aka-upgrade.1 aka.7) exit unless manpages.include?(command) root = File.("../man", __FILE__) if !ENV['NO_MAN'] && Aka::App.which("man") && root !~ %r{^file:/.+!/META-INF/jruby.home/.+} Kernel.exec "man #{root}/#{command}" else puts File.read("#{root}/#{command}.txt") end end |
#link(options) ⇒ Object
105 106 107 108 109 |
# File 'lib/aka/store.rb', line 105 def link() configuration.links.add() configuration.save puts "Saved link." end |
#list(options) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/aka/store.rb', line 59 def list() excluded = configuration.shortcuts.match_by_tag([:tag] || []) do |tag, rows| puts %{##{tag}} puts ''.ljust(tag.length + 1, '=') rows.each do |row| list_output(row) end puts end if configuration.links.any? puts "=====" puts "Links" puts "=====" puts configuration.links.each do |index, link| puts "[#{index}] #{link.output}: #{link.tag.map { |tag| "##{tag}" }.join(', ')}" end end excluded_output(excluded) end |
#remove(options) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/aka/store.rb', line 83 def remove() found = configuration.shortcuts.find() if found.length > 0 found.each do |n, row| configuration.shortcuts.delete(n) end configuration.save puts "Removed shortcut." else abort %{No shortcut "#{[:shortcut]}". Aborting.} end end |
#show(options) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/aka/store.rb', line 180 def show() found = configuration.shortcuts.find() _, row = found.first if row puts show_output(row) else abort "Shortcut not found." end end |
#sync(match) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/aka/store.rb', line 117 def sync(match) configuration.links.each do |index, config| next if match && match != index excluded = configuration.shortcuts.generate(config.marshal_dump) excluded_output(excluded) end end |
#unlink(key) ⇒ Object
111 112 113 114 115 |
# File 'lib/aka/store.rb', line 111 def unlink(key) configuration.links.delete(key) configuration.save puts "Deleted link." end |
#upgrade(options) ⇒ Object
192 193 194 |
# File 'lib/aka/store.rb', line 192 def upgrade() configuration.upgrade end |