Skip to content

Instantly share code, notes, and snippets.

@aliou
Created December 9, 2012 16:20
Show Gist options
  • Save aliou/4245875 to your computer and use it in GitHub Desktop.
Save aliou/4245875 to your computer and use it in GitHub Desktop.
Cheddar command line interface.

Quick command line interface for Cheddar. Uses the vermonster gem, install with:

gem install vermonster

The config file is located at ~/.config/cheddar/config is formated like a regular yaml file:

client_id: xxxxxxx
client_secret: xxxxxxx
user_token: xxxxxxx
#!/usr/bin/env ruby
require 'time'
require 'json'
require 'vermonster'
require 'yaml'
config = YAML.load_file("#{ENV['HOME']}/.config/cheddar/config")
client_id = config["client_id"]
client_secret = config["client_secret"]
user_token = config["user_token"]
@list = 0
@cheddar = Vermonster::Client.new(:id => client_id, :secret => client_secret)
@cheddar.use_token!(user_token)
def show_list
@cheddar.lists.find(@list).tasks.each do |task|
puts "[#{task["id"]}]: #{task["display_text"]}"
end
end
def add(text)
if !text.nil?
@cheddar.tasks.create(@list, :text => text)
puts "Task \"#{ARGV[1]}\" created."
else
puts "Please specify task to create."
end
end
def archive(id)
if !id.nil?
task = @cheddar.tasks.find(id.to_i)
if task["id"].nil?
puts "Invalid task ID."
else
task.update(:archived_at => Time.now.utc.iso8601.to_s)
puts "Task #{id.to_i} archived."
end
else
puts "Please specify task to archive."
end
end
def edit(id, text)
if !id.nil?
task = @cheddar.tasks.find(id.to_i)
if task["id"].nil?
puts "Invalid task ID."
else
if !text.nil?
task.update(:text => text)
puts "Task #{id.to_i} updated to \"#{text}\"."
else
puts "Please specify the updated text."
end
end
else
puts "Please specify task to update."
end
end
def tag(tagname)
if !tagname.nil?
@cheddar.lists.find(@list).tasks.each do |task|
tmp = task["tags"]
tmp.each do |tag|
if tag["name"] == tagname
puts "[#{task["id"]}]: #{task["display_text"]}"
end
end
end
else
puts "Please specify a tag."
end
end
if ARGV[0].nil?
show_list
else
if ARGV[0] == "archive"
archive(ARGV[1])
elsif ARGV[0] == "add"
add(ARGV[1])
elsif ARGV[0] == "edit"
edit(ARGV[1], ARGV[2])
elsif ARGV[0] == "tag"
tag(ARGV[1])
else
puts "Command supported: tag, add, edit, archive."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment