Sha256: 307cb37c991d5818529dbfa305e5ee5fb1d9ca8c590398b683a09a4e66713afa
Contents?: true
Size: 1.64 KB
Versions: 11
Compression:
Stored size: 1.64 KB
Contents
#!/usr/bin/env ruby $LOAD_PATH.unshift File.join(__dir__, '..', 'lib') require 'journal-cli' require 'optparse' trap('SIGINT') { exit! } module Journal class << self def usage puts 'Usage: journal [type] [date]' puts puts 'Available journal types:' list_journals end def list_journals config = Journal.config puts config['journals'].keys end def run(args) if args.count.zero? puts "No journal specified" usage Process.exit 1 end journal = args.shift date = if args.length.positive? Chronic.parse(args.join(' '), future: false) else Time.now end Journal.date = date if Journal.config['journals'].key?(journal) checkin = Journal::Checkin.new(journal) checkin.go else puts "Journal #{journal} not found" usage Process.exit 1 end end end end optparse = OptionParser.new do |opts| opts.banner = 'Usage: journal JOURNAL_KEY [NATURAL LANGUAGE DATE]' opts.on('-v', '--version', 'Display version') do puts "journal v#{Journal::VERSION}" Process.exit 0 end opts.on('-l', '--list', 'List available journals') do Journal.list_journals Process.exit 0 end Color.coloring = $stdout.isatty opts.on('--[no-]color', 'Colorize output') do |c| Color.coloring = c end opts.on('-h', '--help', 'Display help') do puts opts puts puts 'Available journal types:' config = Journal.config puts(config['journals'].keys.map { |k| "- #{k}" }) Process.exit 0 end end optparse.parse! Journal.run(ARGV)
Version data entries
11 entries across 11 versions & 1 rubygems