-
-
Save adam12/b37484e342e14b7c4d2ba25c36577955 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Author
adam12
commented
Jul 14, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment