Skip to content

Instantly share code, notes, and snippets.

@adam12
Created July 14, 2023 22:44
Show Gist options
  • Save adam12/b37484e342e14b7c4d2ba25c36577955 to your computer and use it in GitHub Desktop.
Save adam12/b37484e342e14b7c4d2ba25c36577955 to your computer and use it in GitHub Desktop.
require "yaml/store"
class CLI
def initialize(argv, store = YAML::Store.new("tags.store"))
@argv = argv.dup
@store = store
end
def run
case @argv.shift
when "add"
file = @argv.shift
tags = @argv
@store.transaction do
@store[file] ||= []
@store[file].concat(tags)
end
puts "Tags added"
exit
when "list"
@store.transaction do
pp(@store.keys.flat_map do |key|
@store[key]
end)
end
else
abort <<~EOM
Unknown command
Usage: #{$0} [cmd]
add [file] [tags]
list
EOM
end
end
end
if $0 == __FILE__
CLI.new(ARGV).run
end
@adam12
Copy link
Author

adam12 commented Jul 14, 2023

$ cat tags.store
---
foobar:
- baz
- bar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment