#!/usr/bin/env ruby require "noter" require "optparse" class NoteRunner def initialize @options = {:paging => true} end def run(args) run_parser run_command end def run_command case @command when :show_file_from_index Noter::Viewer.new(@options).show_file_from_index(@index) when :show_first_lines Noter::Viewer.new(@options).show_first_lines(:with_filename => @show_names) when :show_files Noter::Viewer.new(@options).show_files when :create_from_string Noter::FileMaker.new(@message).save_file when :make_from_file Noter::FileMaker.new.make_from_file(@filename) when :create_with_vim maker = Noter::FileMaker.new filename = maker.create_empty_file system "vim #{filename}" else Noter::Viewer.new(@options).show_first_lines(:with_filename => @show_names) end end def run_parser parser = OptionParser.new do |opts| opts.on("-c", "--create", "Create a note using vim") do @command = :create_with_vim end opts.on("-f", "--file FILE", "Create a note using the given file") do |filename| @command = :make_from_file @filename = filename end opts.on("-g", "--grep STRING", "Only show files that contain a specific string") do |grep_string| @options[:grep_string] = grep_string end opts.on("-l", "--one-line", "Show first line of each note file") do @command = :show_first_lines end opts.on("-m", "--message MESSAGE", "Create a note using the given string") do |message| @command = :create_from_string @message = message end opts.on("-n", "--name", "Include names when showing files") do @command = :show_first_lines @show_names = true end opts.on("--no-color", "Don't colorize output") do @options[:colorize] = false end opts.on("-s", "--search STRING", "Show a file with the given index") do |grep_string| @options[:tail_count] = 100 unless @options[:tail_count] @options[:grep_string] = grep_string @command = :show_files end opts.on("-t", "--tail COUNT", "Show the last n files") do |count| @command = :show_files @options[:tail_count] = count end opts.on("-u", "--unpaged", "Don't page the output") do @options[:paging] = false end opts.on("-v", "--view INDEX", "View a file with the given index") do |index| @command = :show_file_from_index @index = index end end parser.parse! end end runner = NoteRunner.new runner.run(ARGV)