Sha256: 67344fe3793f7a54e1b5f7b14ad7573eb3b4ae040e274250d4cdfba994a14f1d

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

#!/usr/bin/env ruby
require 'fileutils'
require 'commander/import'

program :name, 'dayone'
program :version, File.read(File.join(File.dirname(__FILE__),'../version.txt'))
program :description, "Command line interface for the rb-dayone gem"

dayone_folder = File.join(ENV['HOME'], '.rb-dayone')
dayone_location_file = File.join(dayone_folder, 'location')

command :set do |c|
  c.syntax = "set [key value]"
  c.description = "Show or set program settings."
  c.summary = "If sent without arguments, this will show all program settings. If sent with two arguments, this will set <key> to <value>"
  
  c.action do |args|
    case args.size
    when 0
      puts "location: #{File.read(dayone_location_file)}"
    when 2
      key, val = *args
      case key
      when 'location'
        new_dayone_location = File.expand_path(val)
        File.open(dayone_location_file,'w'){ |io| io << new_dayone_location }
        puts "#{key}: #{new_dayone_location}"
      else
        puts "Key #{key} not recognised"
        exit 1
      end
    else
      puts c.syntax
      puts c.summary
      exit 1
    end
  end
end

command :add do |c|
  c.syntax = "add [--text=\"Entry text\"] [--starred]"
  c.description = "Add an entry to your DayOne journal."
  c.summary = <<-end
Add an entry to your DayOne journal. By default will add an unstarred entry - use the --starred flag to change this.

If you don't specify the --text tag, it will read text from STDIN and use this as the journal entry.
  end
  
  c.option "--text STRING", String, "Specify the journal entry text. If not specified, will read from STDIN"
  c.option "--starred", "Mark the entry starrd"

  c.action do |args, opts|
    require 'rb-dayone'
    entry_text = opts.text || $stdin.read.strip
    starred = opts.starred
    
    entry = DayOne::Entry.new entry_text, starred:starred
    entry.create!
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rb-dayone-0.1.7 bin/dayone