bin/septober in ric-0.11.13 vs bin/septober in ric-0.11.14
- old
+ new
@@ -9,28 +9,33 @@
@maturity: development
@language: Ruby
@tags: development, rcarlesso
@synopsis: This connects to septober websites. For more info, look here
@description:
- septober.heroku.com client to add and list todos!
+ septober.heroku.com client to add and list todos!
- TODO
- - add --context|-x : to change context (--local => --context 'local' , default: "septober" )
+ TODO
+ - add --context|-x : to change context (--local => --context 'local' , default: "septober" )
- API: add actions (done, toggle, ..., due <today|tomorrow|monday> )
-
+ API: add actions (done, toggle, ..., due <today|tomorrow|monday> )
+ ###########################################################
+=end
+
+ $PROG_VER = '0.9.8'
+
+=begin
@history:
+ 0.9.8 2011-02-10 Added timeout (works) and a broken prototype for :edit
0.9.7 2011-02-09 mini banner WITH version (not to get nuts again thru versions!). --conf now works!
0.9.6 2011-02-09 CLI supports --conf now. Tags working!
0.9.5 2011-02-08 more concise 'add'
0.9.4 2011-02-04 added 'done' action (and 'delete' ?)
0.9.3 2011-02-04 better 'list'
0.9.2 2011-02-04 'add' operation succefully added!
0.9.1 2011-01-18 First version
- ############################################################
=end
- $PROG_VER = '0.9.7'
+
require 'optparse'
require 'rubygems'
require 'ric'
require 'active_resource'
@@ -44,53 +49,68 @@
:app_name => 'septober client',
:hello => 'Welcome to this terrific application',
:septober_url => 'http://septober.heroku.com/' ,
:dflt_config_file => '~/.septober.yml' ,
:local => false ,
+ :timeout => 7 ,
}
def init
$opts[:config_file] = $opts[:dflt_config_file]
- #$colors_active = true
$optparse = OptionParser.new do |opts|
opts.on( '-c', '--config <FILE>', 'uses a different configfile from: '+$opts[:dflt_config_file] ) {|arg_file|
puts "Importing file different from default: #{yellow arg_file}"
$opts[:config_file] = arg_file
}
- opts.on( '-d', '--debug', 'enables debug (DFLT=false)' ) { $opts[:debug] = true ; $debug = true ; debug_on('Debug enabled from ARGV')}
- opts.on( '-h', '--help', 'Display this screen' ) { puts(opts); exit 1 }
+ opts.on( '-d', '--debug', 'enables debug (DFLT=false)' ) { $opts[:debug] = true ; $debug = true ; debug_on('Debug enabled from ARGV')}
+ opts.on( '-h', '--help', 'Display this screen' ) { puts(opts); exit 1 }
opts.on( '-n', '--no-colors', 'Deactives colors (onta e disonore!)' ) { $colors_active = false }
- opts.on( '-l', '--local', 'uses local instead' ) { $opts[:local] = true }
- opts.on( '-v', '--verbose', 'Output more information' ) { $opts[:verbose] = true}
+ opts.on( '-l', '--local', 'uses local instead' ) { $opts[:local] = true }
+ opts.on( '-t', '--timeout TIMEOUT', "Sets timeout (default =#{$opts[:timeout]}s)" ) {|new_timeout|
+ $opts[:timeout] = new_timeout.to_i rescue 5
+ RemoteTodo.timeout = new_timeout.to_i rescue 5
+ }
+ opts.on( '-v', '--verbose', 'Output more information' ) { $opts[:verbose] = true}
opts.banner = <<-API_OPTIONS
#{$0} v.#{$PROG_VER}
Usage: #{File.basename $0} [options] [add|list|done|del] [args]
API Actions (T stands for ToBeDoneYet ):
add <FREE TEXT> # adds new task in free text with some magic..
delete <ID> # T delete ticket.ID (DONT USE IF U CAN!)
done <ID> # T posts ticket.ID :done (resolved)
+ edit <ID> [ACTION1:ARG1] [ACT2:ARG2]# T posts generic action for ticket.ID /edit.xml?due=tomorrow&ACT2=ARG2
list # shows a list of your todos yet to complete
mail <ID> # T mail to yourself ticket.ID !!!
show <ID> # shows details about todo with id=ID
procrastinate <ID> <NDAYS> # T mail to yourself ticket.ID !!!
sleep <ID> <NDAYS> # T mail to yourself ticket.ID !!!
-
+
+ Examples:
+ septober --local edit 110 due:tomorrow
+ septober list
+ septober show 1
+ septober add 'This is a ticket with priority 4 and a simple @example tag!'
+
Options:
API_OPTIONS
end
$optparse.parse!
RemoteTodo.import_config()
end
#################################################################################################################################################
class RemoteTodo < ActiveResource::Base
- self.site = "http://septober.example.com/" # uninitialized
+ # With a singleton u can define the accessors of the class (attr accessor for self!)
+ #class << self
+ # attr_accessor :description # = '-'
+ #end
+ self.site = "http://septober.example.com/" # uninitialized
self.element_name = 'todo'
- self.timeout = 5
- #self.proxy = nil
+ self.timeout = $opts[:timeout] rescue 6
+
@@sample_yml_config = <<-SAMPLE_YML_CONFIG
riccardo heroku: &DEVEL_LOCAL
# YAML file with septober configuration. For more info: http://septober.heroku.com/
site: "http://localhost:3000/api/" # or http://septober.heroku.com/api/
user: guest
@@ -134,10 +154,11 @@
puts "Possible sub_confs: #{yellow whole_hash.keys.join(', ')}"
conf_hash = whole_hash[sub_conf] rescue nil
self.site = conf_hash['site']
self.user = conf_hash['user']
self.password = conf_hash['password']
+ self.description = conf_hash['description'] rescue '-'
deb "Conf imported successuflly: #{blue self.user}@#{self.site}"
else
pred "Missing file: #{file} !!! Try to do the following:"
puts "cat > #{file}\n#{@@sample_yml_config rescue "Err#{$!}" }"
exit 79
@@ -146,10 +167,18 @@
def to_s
self.name
end
+ def self.description
+ @@description ||= '-'
+ end
+
+ def self.description=(desc)
+ @@description = desc
+ end
+
def colored_project_name()
colora(project.color || :grey ,project.name)
end
# TODO put this into todo.rb model and add it to the controller like "cli_colored_string" and "cli_neutral_string"
@@ -211,12 +240,14 @@
#################################################################################################################################################
#############################
# Program start..
+ # header
def bannerino(desc)
- "#septober v#{$PROG_VER} #{white desc.to_s} (#{green RemoteTodo.user} @ #{cyan RemoteTodo.site.to_s.split('/')[2] })"
+ "#septober v#{$PROG_VER} #{white desc.to_s} (#{green RemoteTodo.user} @ #{cyan RemoteTodo.site.to_s.split('/')[2] }, timeout=#{RemoteTodo.timeout})" +
+ (RemoteTodo.description.length > 2 ? " # #{gray RemoteTodo.description}" : '')
end
def todo_list(opts={})
show_only_active = opts.fetch :only_active, true
puts bannerino( "Index" )
@@ -230,11 +261,11 @@
=begin
Adds a todo with just the subject, the server takes it and parses and does the magic
to assing the correct ptoject and stuff..
=end
def todo_add(words_from_argv)
- puts bannerino( "Add(#{words_from_argv})" )
+ puts bannerino( "Add('#{words_from_argv}')" )
# TODO put this into begin/end/catch !!!
t = RemoteTodo.create(
:name => words_from_argv,
:description => "sent by CLI #{$0} v.#{$PROG_VER}, due tomorrow by test",
#:due => Date.tomorrow,
@@ -275,10 +306,11 @@
puts "Todo.#{id} ok #{green action}: #{yellow( todo.to_s )}"
put_options = {
:my_action => action,
:from_cli_in_test_ric => Socket.gethostname
}.merge( opts.fetch( :additional_args, {:nis => :bah } ) ) # if there are ,m good. Otherwise, "nisba" :)
+ deb "todo_generic_put(id=#{id},#{purple action}, #{gray opts.inspect})"
todo.put(action, put_options ) # test stuff
#todo.put(action, :my_action => action, :from_cli_in_test_ric => Socket.gethostname , additional_args) # test stuff
rescue ActiveResource::ResourceNotFound
puts "Sorry ResourceNotFound: #{red $!}"
exit 11
@@ -306,18 +338,20 @@
init()
# Maybe you may want to check on ARGV
#unless ARGV.size > 0
# usage "Give me at least 1 argument" # Maybe default to list?!?
#end
- all_args = ARGV[1..-1].join(' ')
+ all_args = ARGV[1..-1].join(' ') rescue ''
case ARGV[0].to_s
when 'list' ; todo_list()
when 'show' ; todo_show(ARGV[1])
when 'done' ; todo_done(ARGV[1],true)
when 'add' ; todo_add(all_args) # all except last one
when 'toggle'; todo_toggle(ARGV[1]) # all except last one
- when 'delete'; todo_generic_put(ARGV[1], :delete , :additional_args => {:test_foo => 'test deletion string, please removeme' }) # all except last one
- #when 'del'; copy
+ when 'delete'; todo_generic_put(ARGV[1], :delete , :additional_args => {:test_foo => 'test deletion string, with whole DELETE' })
+ when 'del'; todo_generic_put(ARGV[1], :delete , :additional_args => {:test_foo => 'test deletion string, with just DEL' })
+ when 'edit'; todo_generic_put(ARGV[1], :edit, :additional_args => ARGV.map{|arg| k,v=arg.split(':') } )
+ # TODO transform [ [act1, arg1], [act2,arg2]] into {:act1 => arg1, :act2 => arg2 }
when 'tag' ; todo_generic_put(ARGV[1], :additional_args => {:tag_with => all_args.join(',') }) # all except last one
when 'help' ; usage 'Explicitly called help..'
when '' ; todo_list()
else
usage "Unrecognized command: '#{ARGV[0]}'"
\ No newline at end of file