Module: NoWhen::Command
- Defined in:
- lib/nowhen/command.rb
Class Method Summary collapse
Class Method Details
.now(argv) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nowhen/command.rb', line 17 def self.now(argv) parser = ArgsParser.parse argv do arg :log, 'save log' arg :db_upgrade, 'upgrade database' arg :version, 'show version', :alias => :v arg :help, 'show help', :alias => :h end if parser.has_option? :help show_help parser elsif parser.has_option? :version STDERR.puts "nowhen version #{NoWhen::VERSION}" elsif parser.has_option? :db_upgrade NoWhen::Model.upgrade elsif parser[:log] log = parser.has_param?(:log) ? parser[:log] : parser.argv.join(' ') log = NoWhen::Model::Log.new(:log => log) log.save puts log.log elsif !parser.argv.empty? what = parser.argv[0].strip tag = NoWhen::Model::Tag.new(:what => what) tag.save puts tag else show_help parser end end |
.show_help(parser) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/nowhen/command.rb', line 6 def self.show_help(parser) STDERR.puts "nowhen - Tagger for LifeLog v#{NoWhen::VERSION}" STDERR.puts " https://github.com/shokai/nowhen" STDERR.puts parser.help STDERR.puts STDERR.puts "e.g." STDERR.puts " % now yummy" STDERR.puts " % now -log http://example.com/delicious_food_recipe" STDERR.puts " % when yummy" end |
.when(argv) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/nowhen/command.rb', line 45 def self.when(argv) parser = ArgsParser.parse argv do arg :limit, 'tags count', :default => 40 arg :all, 'disable tag count limit' arg :version, 'show version', :alias => :v arg :help, 'show help', :alias => :h end if parser.has_option? :help show_help parser elsif parser.has_option? :version STDERR.puts "nowhen version #{NoWhen::VERSION}" else query = {} query[:what] = parser.argv[0].strip unless parser.argv.empty? query[:limit] = parser[:limit] unless parser.has_option? :all = NoWhen::Model::Tag.find query .each do |tag| puts tag tag.logs.each do |log| puts " - #{log.log}" end end end end |