Class: Toodledo::CommandLine::Client
- Inherits:
-
Object
- Object
- Toodledo::CommandLine::Client
- Includes:
- ParserHelper
- Defined in:
- lib/toodledo/command_line/client.rb
Overview
The toodledo client. This provides a command line based client to the user and gives a good overview of the capabilities of the API as well.
- Author
-
Will Sargent ([email protected])
- Copyright
-
Copyright © 2008 Will Sargent
- License
-
GLPL v3
Constant Summary collapse
- HOME =
ENV["HOME"] || ENV["HOMEPATH"] || File::("~")
- TOODLEDO_D =
File::join(HOME, ".toodledo")
- CONFIG_F =
File::join(TOODLEDO_D, "user-config.yml")
- CONFIG =
We must use __FILE__ instead of DATA because this is now a library and DATA is relative to $0, not __FILE__.
File.read(__FILE__).split(/__END__/).last.gsub(/#\{(.*)\}/) { eval $1 }
Constants included from ParserHelper
ParserHelper::CONTEXT_REGEXP, ParserHelper::DATE_REGEXP, ParserHelper::FOLDER_REGEXP, ParserHelper::GOAL_REGEXP, ParserHelper::LEVEL_REGEXP, ParserHelper::PRIORITY_REGEXP, ParserHelper::REGEXP_LIST, ParserHelper::STAR_REGEXP, ParserHelper::TAGS_REGEXP
Instance Method Summary collapse
-
#add_context(session, input) ⇒ Object
Adds context.
- #add_folder(session, input) ⇒ Object
-
#add_goal(session, input) ⇒ Object
Adds goal.
-
#add_task(session, line) ⇒ Object
Adds a single task, using toodledo symbols.
-
#archive_folder(session, line) ⇒ Object
Archives a folder.
- #archive_goal(session, line) ⇒ Object
- #clean(regexp, input) ⇒ Object
-
#complete_task(session, line) ⇒ Object
Masks the task as completed.
-
#debug=(is_debug) ⇒ Object
Sets the debugging on or off.
-
#debug? ⇒ Boolean
Returns debugging status.
-
#delete_context(session, line) ⇒ Object
Deletes context.
-
#delete_folder(session, line) ⇒ Object
Deletes folder.
-
#delete_goal(session, line) ⇒ Object
Deletes goal.
-
#delete_task(session, line) ⇒ Object
Deletes a task, using the task id.
-
#edit_task(session, input) ⇒ Object
Edits a single task.
- #execute_command(session, input) ⇒ Object
-
#help ⇒ Object
Displays the help message.
-
#hotlist(session, input) ⇒ Object
Displays the ‘hotlist’ of tasks.
-
#initialize(userconfig = CONFIG_F, opts = {}) ⇒ Client
constructor
Creates the client object.
-
#list_contexts(session, input) ⇒ Object
Lists the contexts.
-
#list_filters ⇒ Object
Shows all the filters.
-
#list_folders(session, input) ⇒ Object
Lists the folders.
-
#list_goals(session, input) ⇒ Object
Lists the goals.
-
#list_overdue_tasks(session, line) ⇒ Object
Print overdue tasks.
-
#list_tasks(session, input) ⇒ Object
Lists tasks (subject to any filters that may be present).
-
#list_tasks_by_beforeafter(session, before, after) ⇒ Object
Print all tasks with the due date in the given time range.
-
#list_tasks_by_context(session, line) ⇒ Object
Prints all active tasks nested by context.
-
#list_today_tasks(session, line) ⇒ Object
Print tasks for today.
-
#list_tomorrow_tasks(session, line) ⇒ Object
Print tasks for tomorrow.
-
#logger ⇒ Object
Returns the logger.
-
#main ⇒ Object
Runs the client main command.
-
#print(line = nil) ⇒ Object
Prints out a single line.
-
#set_filter(session, input) ⇒ Object
Sets the context filter.
-
#setup ⇒ Object
Invites the user to setup the YAML file.
-
#show_config(session) ⇒ Object
Displays the configuration information that the session is currently using.
-
#unfilter ⇒ Object
Clears all the filters.
Methods included from ParserHelper
#parse_context, #parse_date, #parse_folder, #parse_goal, #parse_level, #parse_priority, #parse_remainder, #parse_star, #parse_tag, #strip_brackets
Constructor Details
#initialize(userconfig = CONFIG_F, opts = {}) ⇒ Client
Creates the client object.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/toodledo/command_line/client.rb', line 67 def initialize(userconfig=CONFIG_F, opts={}) @filters = {} @debug = false @logger = Logger.new(STDOUT) @logger.level = Logger::FATAL @userconfig = test(?e, userconfig) ? IO::read(userconfig) : CONFIG @userconfig = YAML.load(@userconfig).merge(opts) @formatters = { :task => TaskFormatter.new, :goal => GoalFormatter.new, :context => ContextFormatter.new, :folder => FolderFormatter.new } end |
Instance Method Details
#add_context(session, input) ⇒ Object
Adds context.
521 522 523 524 525 526 527 528 |
# File 'lib/toodledo/command_line/client.rb', line 521 def add_context(session, input) title = input.strip context_id = session.add_context(title) print "Context #{context_id} added." end |
#add_folder(session, input) ⇒ Object
551 552 553 554 555 556 557 558 |
# File 'lib/toodledo/command_line/client.rb', line 551 def add_folder(session, input) title = input.strip folder_id = session.add_folder(title) print "Folder #{folder_id} added." end |
#add_goal(session, input) ⇒ Object
Adds goal.
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/toodledo/command_line/client.rb', line 533 def add_goal(session, input) input.strip! # Assume that a goal is short, medium or life, and # don't stick a symbol on it. level = parse_level(input) if (level == nil) level = Toodledo::Goal::SHORT_LEVEL else input = clean(LEVEL_REGEXP, input) input.strip! end goal_id = session.add_goal(input, level) print "Goal #{goal_id} added." end |
#add_task(session, line) ⇒ Object
Adds a single task, using toodledo symbols. This is the most general way to add a task right now. If you have symbols which have spaces, then you must encase them in square brackets.
The order of symbols does not matter, but the title must be the last thing on the line.
add @[Deep Space] !top *Action ^[For Great Justice] Take off every Zig
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/toodledo/command_line/client.rb', line 468 def add_task(session, line) # TODO Yet again, essentially the same code as list and hotlist; Refactor context = parse_context(line) star = parse_star(line) # ctanis folder = parse_folder(line) goal = parse_goal(line) priority = parse_priority(line) date = parse_date(line) tag = parse_tag(line) title = parse_remainder(line) params = {} if (priority != nil) params.merge!({ :priority => priority }) end if (folder != nil) params.merge!({ :folder => folder }) end if (context != nil) params.merge!({ :context => context }) end if (goal != nil) params.merge!({ :goal => goal }) end if (date != nil) params.merge!({ :duedate => date }) end if (tag != nil) params.merge!({ :tag => tag }) end if (star) # boolean params.merge!({ :star => true }) end # If we got nothing but 'add' then ask for it explicitly. if (title == nil) title = ask("Task name: ") { |q| q.readline = true } end task_id = session.add_task(title, params) print "Task #{task_id} added." end |
#archive_folder(session, line) ⇒ Object
Archives a folder.
563 564 565 566 567 568 569 570 571 572 |
# File 'lib/toodledo/command_line/client.rb', line 563 def archive_folder(session, line) line.strip! folder_id = line params = { :archived => 1 } session.edit_folder(folder_id, params) print "Folder #{folder_id} archived." end |
#archive_goal(session, line) ⇒ Object
574 575 576 |
# File 'lib/toodledo/command_line/client.rb', line 574 def archive_goal(session, line) # Not implemented! No way to edit a goal. end |
#clean(regexp, input) ⇒ Object
768 769 770 |
# File 'lib/toodledo/command_line/client.rb', line 768 def clean(regexp, input) return input.sub(regexp, '') end |
#complete_task(session, line) ⇒ Object
Masks the task as completed. Uses a task id as argument.
complete 123
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
# File 'lib/toodledo/command_line/client.rb', line 638 def complete_task(session, line) task_id = line if (task_id == nil) task_id = ask("Task ID?: ") { |q| q.readline = true } end task_id.strip! params = { :completed => 1 } if (session.edit_task(task_id, params)) print "Task #{task_id} completed." else print "Task #{task_id} could not be completed!" end end |
#debug=(is_debug) ⇒ Object
Sets the debugging on or off.
93 94 95 96 97 98 99 100 |
# File 'lib/toodledo/command_line/client.rb', line 93 def debug=(is_debug) @debug = is_debug if (@debug == true) @logger.level = Logger::DEBUG else @logger.level = Logger::FATAL end end |
#debug? ⇒ Boolean
Returns debugging status.
86 87 88 |
# File 'lib/toodledo/command_line/client.rb', line 86 def debug? return @debug end |
#delete_context(session, line) ⇒ Object
Deletes context.
680 681 682 683 684 685 686 687 688 689 690 691 692 |
# File 'lib/toodledo/command_line/client.rb', line 680 def delete_context(session, line) logger.debug("delete_context #{line.inspect}") id = line id.strip! if (session.delete_context(id)) print "Context #{id} deleted." else print "Context #{id} could not be deleted!" end end |
#delete_folder(session, line) ⇒ Object
Deletes folder
712 713 714 715 716 717 718 719 720 721 722 |
# File 'lib/toodledo/command_line/client.rb', line 712 def delete_folder(session, line) id = line id.strip! if (session.delete_folder(id)) print "Folder #{id} deleted." else print "Folder #{id} could not be deleted!" end end |
#delete_goal(session, line) ⇒ Object
Deletes goal.
697 698 699 700 701 702 703 704 705 706 707 |
# File 'lib/toodledo/command_line/client.rb', line 697 def delete_goal(session, line) id = line id.strip! if (session.delete_goal(id)) print "Goal #{id} deleted." else print "Goal #{id} could not be deleted!" end end |
#delete_task(session, line) ⇒ Object
Deletes a task, using the task id.
delete 123
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 |
# File 'lib/toodledo/command_line/client.rb', line 660 def delete_task(session, line) logger.debug("delete_task: #{line.inspect}") task_id = line if (task_id == nil) task_id = ask("Task ID?: ") { |q| q.readline = true } end task_id.strip! if (session.delete_task(task_id)) print "Task #{task_id} deleted." else print "Task #{task_id} could not be deleted!" end end |
#edit_task(session, input) ⇒ Object
Edits a single task. This method allows you to change the symbols on a task. Note that you must specify the ID here.
edit *Action !top 12345
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 |
# File 'lib/toodledo/command_line/client.rb', line 583 def edit_task(session, input) logger.debug("edit_task: #{input.inspect}") # TODO And again... Refactor context = parse_context(input) folder = parse_folder(input) goal = parse_goal(input) priority = parse_priority(input) date = parse_date(input) tag = parse_tag(input) task_id = parse_remainder(input) logger.debug("edit_task: task_id = #{task_id}") if (task_id == nil) task_id = ask("Task ID?: ") { |q| q.readline = true } end task_id.strip! params = { } if (folder != nil) params.merge!({ :folder => folder }) end if (context != nil) params.merge!({ :context => context }) end if (goal != nil) params.merge!({ :goal => goal }) end if (priority != nil) params.merge!({ :priority => priority }) end if (date != nil) params.merge!({ :duedate => date }) end if (tag != nil) params.merge!({ :tag => tag }) end session.edit_task(task_id, params) print "Task #{task_id} edited." end |
#execute_command(session, input) ⇒ Object
772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 |
# File 'lib/toodledo/command_line/client.rb', line 772 def execute_command(session, input) case input when /^help/, /^\s*\?/ help() when /^add/ line = clean(/^add/, input) line.strip! case line when /folder/ add_folder(session, clean(/folder/, line)) when /context/ add_context(session, clean(/context/, line)) when /goal/ add_goal(session, clean(/goal/, line)) else add_task(session, line) end when /^edit/ line = clean(/^edit/, input) edit_task(session, line) when /^delete/ line = clean(/^delete/, input) line.strip! case line when /folder/ delete_folder(session, clean(/folder/, line)) when /context/ delete_context(session, clean(/context/, line)) when /goal/ delete_goal(session, clean(/goal/, line)) else delete_task(session, line) end when /^archive/ archive_folder(session, clean(/^archive/, input)) when /^hotlist/ line = clean(/^hotlist/, input) hotlist(session, line) when /^complete/ line = clean(/^complete/, input) complete_task(session, line) when /^tasks/ line = clean(/^(tasks)/, input) list_tasks(session, line) when /^today/ line = clean(/^(today)/, input) list_today_tasks(session, line) when /^tomorrow/ line = clean(/^(tomorrow)/, input) list_tomorrow_tasks(session, line) when /^overdue/ line = clean(/^(overdue)/, input) list_overdue_tasks(session, line) when /^folders/ line = clean(/^folders/, input) list_folders(session,line) when /^goals/ line = clean(/^goals/, input) list_goals(session,line) when /^contexts/ line = clean(/^contexts/, input) list_contexts(session,line) when /^filters/ list_filters() when /^filter/ line = clean(/^filter/, input) set_filter(session, line) when /^config/ show_config(session) when /^unfilter/ unfilter() when /debug/ self.debug = ! self.debug? when /^quit/, /^exit/ exit 0 else print "'#{input}' is not a command: type help for a list" end end |
#help ⇒ Object
Displays the help message.
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
# File 'lib/toodledo/command_line/client.rb', line 738 def help() print "hotlist Shows the hotlist" print "folders Shows all folders" print "goals Shows all goals" print "contexts Shows all contexts" print "tasks Shows tasks ('tasks *Action @Home')" print "today Shows tasks for today" print "tomorrow Shows tasks for tomorrow" print "overdue Shows overdue tasks" print print "add Adds task ('add *Action @Home Eat breakfast')" print " folder Adds a folder ('add folder MyFolder')" print " context Adds a context ('add context MyContext')" print " goal Adds a goal ('add goal MyGoal')" print "edit Edits a task ('edit *Action 1134')" print "complete Completes a task ('complete 1234')" print "delete Deletes a task ('delete 1134')" print " folder Deletes a folder ('delete folder 1')" print " context Deletes a context ('delete context 2')" print " goal Deletes a goal ('delete goal 3')" print print "archive Archives a folder ('archive 1234')" print "filter Defines filters ('filter *Action @Someday')" print "unfilter Removes all filters" print "filters Displays the list of filters" print print "help or ? Displays this help message" print "quit or exit Leaves the application" end |
#hotlist(session, input) ⇒ Object
Displays the ‘hotlist’ of tasks. This shows all the uncompleted items with priority set to 3 or 2. There’s no facility in the API for this, so we have to cheat a bit.
It may be worthwhile to allow the ability to tweak what constitutes a ‘hotlist’ but that’ll come by demand. Or patches. Fully documented patches, mmmm.
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/toodledo/command_line/client.rb', line 228 def hotlist(session, input) logger.debug("hotlist: #{input}") # See if there's input following the command. context = parse_context(input) folder = parse_folder(input) goal = parse_goal(input) priority = parse_priority(input) date = parse_date(input) tag = parse_tag(input) params = { :notcomp => true } # If there are, they override what we have set. if (folder != nil) params.merge!({ :folder => folder }) end if (context != nil) params.merge!({ :context => context }) end if (goal != nil) params.merge!({ :goal => goal }) end if (priority != nil) params.merge!({ :priority => priority }) end if (date != nil) params.merge!({ :duedate => date }) end if (tag != nil) params.merge!({ :tag => tag }) end tasks = session.get_tasks(params) # Highest priority first tasks.sort! do |a, b| b.priority <=> a.priority end # filter on our end. # Surprisingly, we can't search for "greater than 0 priority" with the API. not_important = Priority::MEDIUM for task in tasks if (task.priority > not_important) print @formatters[:task].format(task) end end end |
#list_contexts(session, input) ⇒ Object
Lists the contexts.
438 439 440 441 442 443 444 445 |
# File 'lib/toodledo/command_line/client.rb', line 438 def list_contexts(session, input) contexts = session.get_contexts() for context in contexts print @formatters[:context].format(context) end end |
#list_filters ⇒ Object
Shows all the filters.
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/toodledo/command_line/client.rb', line 196 def list_filters() if (@filters == nil || @filters.empty?) print "No filters." return end @filters.each do |k, v| if (v.respond_to? :name) name = v.name else name = v end print "#{k}: #{name}\n" end end |
#list_folders(session, input) ⇒ Object
Lists the folders.
450 451 452 453 454 455 456 457 |
# File 'lib/toodledo/command_line/client.rb', line 450 def list_folders(session, input) folders = session.get_folders() for folder in folders print @formatters[:folder].format(folder) end end |
#list_goals(session, input) ⇒ Object
Lists the goals. Takes an optional argument of ‘short’, ‘medium’ or ‘life’.
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/toodledo/command_line/client.rb', line 406 def list_goals(session, input) input.strip! input.downcase! goals = session.get_goals() goals.sort! do |a, b| a.level <=> b.level end level_filter = nil case input when 'short' level_filter = Goal::SHORT_LEVEL when 'medium' level_filter = Goal::MEDIUM_LEVEL when 'life' level_filter = Goal::LIFE_LEVEL end for goal in goals if (level_filter != nil && goal.level != level_filter) next # skip this goal if it doesn't meet the filter end print @formatters[:goal].format(goal) end end |
#list_overdue_tasks(session, line) ⇒ Object
Print overdue tasks
382 383 384 385 386 |
# File 'lib/toodledo/command_line/client.rb', line 382 def list_overdue_tasks(session, line) today = Date.today # show us everything before today. list_tasks_by_beforeafter(session, today, nil) end |
#list_tasks(session, input) ⇒ Object
Lists tasks (subject to any filters that may be present).
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/toodledo/command_line/client.rb', line 287 def list_tasks(session, input) logger.debug("list_tasks(#{input})") params = { :notcomp => true } params.merge!(@filters) # See if there's input following the 'tasks' command. # TODO This is the same code as in hotlist. It's also repetitive. Refactor me! context = parse_context(input) folder = parse_folder(input) goal = parse_goal(input) priority = parse_priority(input) date = parse_date(input) tag = parse_tag(input) # If there are, they override what we have set. if (folder != nil) params.merge!({ :folder => folder }) end if (context != nil) params.merge!({ :context => context }) end if (goal != nil) params.merge!({ :goal => goal }) end if (priority != nil) params.merge!({ :priority => priority }) end if (date != nil) params.merge!({ :duedate => date }) end if (tag != nil) params.merge!({ :tag => tag }) end tasks = session.get_tasks(params) # Highest priority first tasks.sort! do |a, b| b.priority <=> a.priority end for task in tasks print @formatters[:task].format(task) end end |
#list_tasks_by_beforeafter(session, before, after) ⇒ Object
Print all tasks with the due date in the given time range
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/toodledo/command_line/client.rb', line 343 def list_tasks_by_beforeafter(session, before, after) params = { :notcomp => true } if (before) params.merge!({ :before => before.strftime("%Y-%m-%d") }) end if (after) params.merge!({ :after => after.strftime("%Y-%m-%d") }) end tasks = session.get_tasks(params) for task in tasks print @formatters[:task].format(task) end end |
#list_tasks_by_context(session, line) ⇒ Object
Prints all active tasks nested by context.
391 392 393 394 395 396 397 398 399 400 |
# File 'lib/toodledo/command_line/client.rb', line 391 def list_tasks_by_context(session, line) folder = parse_folder(line) session.get_contexts().each do |context| criteria = { :folder => folder, :context => context, :notcomp => true } tasks = session.get_tasks(criteria) print "#{context.name}" if (! tasks.empty?) tasks.each { |task| print " " + @formatters[:task].format(task) } end end |
#list_today_tasks(session, line) ⇒ Object
Print tasks for today
362 363 364 365 366 367 |
# File 'lib/toodledo/command_line/client.rb', line 362 def list_today_tasks(session, line) tomorrow = Date.today + 1 yesterday = Date.today - 1 # show us everything before tomorrow, but after yesterday. list_tasks_by_beforeafter(session, tomorrow, yesterday) end |
#list_tomorrow_tasks(session, line) ⇒ Object
Print tasks for tomorrow
372 373 374 375 376 377 |
# File 'lib/toodledo/command_line/client.rb', line 372 def list_tomorrow_tasks(session, line) today = Date.today twodaysfromnow = today + 2 # show us tasks before two days from now, but after today. list_tasks_by_beforeafter(session, twodaysfromnow, today) end |
#logger ⇒ Object
Returns the logger.
105 106 107 |
# File 'lib/toodledo/command_line/client.rb', line 105 def logger return @logger end |
#main ⇒ Object
Runs the client main command. This is what gets run from ‘toodledo’. Ironically doesn’t do much except for set up the commands and parse arguments from the command line. The MainCommand class does the actual command loop.
877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 |
# File 'lib/toodledo/command_line/client.rb', line 877 def main() # Set the configuration from the YAML file. Toodledo.set_config(@userconfig) # Set up the command parser. graceful_exception = true partial_cmd_matching = true cmd = CmdParse::CommandParser.new(graceful_exception, partial_cmd_matching) cmd.program_name = "toodledo" cmd.program_version = Toodledo::VERSION # Options (must be before help and version are added) cmd. = CmdParse::OptionParserWrapper.new do |opt| opt.separator "Global options:" opt.on("--debug", "Print debugging information") {|t| self.debug = true } end # this is the default command if we don't receive any options. cmd.add_command(InteractiveCommand.new(self), true) cmd.add_command(StdinCommand.new(self)) cmd.add_command(AddTaskCommand.new(self)) cmd.add_command(ListTasksCommand.new(self)) cmd.add_command(ListTodayCommand.new(self)) cmd.add_command(ListTomorrowCommand.new(self)) cmd.add_command(ListOverdueCommand.new(self)) cmd.add_command(ListFoldersCommand.new(self)) cmd.add_command(ListGoalsCommand.new(self)) cmd.add_command(ListContextsCommand.new(self)) cmd.add_command(EditCommand.new(self)) cmd.add_command(CompleteCommand.new(self)) cmd.add_command(DeleteTaskCommand.new(self)) cmd.add_command(HotlistCommand.new(self)) cmd.add_command(SetupCommand.new(self)) cmd.add_command(CmdParse::HelpCommand.new) cmd.add_command(CmdParse::VersionCommand.new) cmd.parse # Return a good exit status. return 0 rescue InvalidConfigurationError => e logger.debug(e) print "The client is missing (or cannot use) the user id or password it needs to connect." print "Run 'toodledo setup' and save the file to fix this." return -1 rescue ServerError => e print "The server returned a fatal error: #{e.}" return -1 end |
#print(line = nil) ⇒ Object
Prints out a single line.
727 728 729 730 731 732 733 |
# File 'lib/toodledo/command_line/client.rb', line 727 def print(line = nil) if (line == nil) puts else puts line end end |
#set_filter(session, input) ⇒ Object
Sets the context filter. Subsequent calls to show tasks will only show tasks that have this context.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/toodledo/command_line/client.rb', line 139 def set_filter(session, input) logger.debug("set_filter(#{input})") input.strip! context = parse_context(input) if (context != nil) c = session.get_context_by_name(context) if (c == nil) print "No such context: #{context}" return end @filters[:context] = c end goal = parse_goal(input) if (goal != nil) g = session.get_goal_by_name(goal) if (g == nil) print "No such goal: #{goal}" return end @filters[:goal] = g end folder = parse_folder(input) if (folder != nil) f = session.get_folder_by_name(folder) if (f == nil) print "No such folder: #{folder}" end @filters[:folder] = f end priority = parse_priority(input) if (priority != nil) @filters[:priority] = priority end date = parse_date(input) if (priority != nil) @filters[:duedate] = date end tag = parse_tag(input) if (priority != nil) @filters[:tag] = tag end if (logger) logger.debug("@filters = #{@filters.inspect}") end end |
#setup ⇒ Object
Invites the user to setup the YAML file.
112 113 114 115 116 117 118 119 120 |
# File 'lib/toodledo/command_line/client.rb', line 112 def setup FileUtils::mkdir_p TOODLEDO_D, :mode => 0700 unless test ?d, TOODLEDO_D test ?e, CONFIG_F and FileUtils::mv CONFIG_F, "#{CONFIG_F}.bak" config = CONFIG[/\A.*(?=^\# AUTOCONFIG)/m] open(CONFIG_F, "w") { |f| f.write config } edit = (ENV["EDITOR"] || ENV["EDIT"] || "vi") + " '#{CONFIG_F}'" system edit or puts "edit '#{CONFIG_F}'" end |
#show_config(session) ⇒ Object
Displays the configuration information that the session is currently using.
126 127 128 129 130 131 132 133 134 |
# File 'lib/toodledo/command_line/client.rb', line 126 def show_config(session) base_url = session.base_url user_id = session.user_id proxy = session.proxy print "base_url = #{base_url}" print "user_id = #{user_id}" print "proxy = #{proxy.inspect}" end |
#unfilter ⇒ Object
Clears all the filters.
215 216 217 218 |
# File 'lib/toodledo/command_line/client.rb', line 215 def unfilter() @filters = {} print "Filters cleared.\n" end |