bin/things2thl in zzamboni-things2thl-0.3.0 vs bin/things2thl in zzamboni-things2thl-0.4.0
- old
+ new
@@ -3,20 +3,11 @@
require File.join(File.dirname(__FILE__), *%w".. lib Things2THL")
require "optparse"
require "ostruct"
-# Command line options and defaults
-options=OpenStruct.new
-options.completed = false
-options.database = nil
-options.structure = :projects_as_lists
-options.areas = true
-options.quiet = false
-options.archivecompleted = true
-options.projectsfolder = nil
-options.contexttagsregex = '^@'
+options=Things2THL.default_options
opts = OptionParser.new do |opts|
opts.separator ''
opts.separator 'Options:'
opts.banner = "Usage: things2thl [options]"
@@ -24,13 +15,13 @@
def opts.show_usage
puts self
exit
end
- opts.on("--projects-as-lists", "Convert projects in Things to lists in THL (default)") { options.structure = :projects_as_lists }
- opts.on("--projects-as-tasks", "Convert projects in Things to tasks in THL") { options.structure = :projects_as_tasks }
- opts.on("--no-areas", "Ignore areas in Things") { options.areas = false }
+ opts.on("--projects-as-lists", "Convert projects in Things to lists in THL" + ((options.structure == :projects_as_lists) ? " (default)" : "") ) { options.structure = :projects_as_lists }
+ opts.on("--projects-as-tasks", "Convert projects in Things to tasks in THL" + ((options.structure == :projects_as_tasks) ? " (default)" : "") ) { options.structure = :projects_as_tasks }
+ opts.on("--[no-]areas", "Transfer areas from Things (default: #{options.areas ? 'yes' : 'no'})") { |v| options.areas = v }
opts.on('-C REGEX', '--context-tags-regex REGEX', 'Regular expression to identify tags that should be interpreted as contexts.',
" (default: #{options.contexttagsregex})") do |regex|
options.contexttagsregex = regex
end
@@ -43,12 +34,12 @@
" If --projects-as-tasks is used, a 'Projects' list is always created, but this option",
" can be used to specify its name.") do |projfolder|
options.projectsfolder = projfolder
end
- opts.on("-c", "--completed", 'Transfer also completed/canceled tasks and projects (default: no)') { options.completed = true }
- opts.on("--no-archive-completed", 'If transferring completed/canceled tasks, also mark them as archived (default: yes)') {options.archivecompleted = false }
+ opts.on("-c", "--completed", "Transfer also completed/canceled tasks and projects (default: #{options.completed ? 'yes' : 'no'})") { options.completed = true }
+ opts.on("--[no-]archive-completed", "If transferring completed/canceled tasks, also mark them as archived (default: #{options.archivecompleted ? 'yes' : 'no'})") {|v| options.archivecompleted = v }
opts.on("-q", "--quiet", "Do not print items as they are processed") { options.quiet = true }
# opts.on("-n", "--dry-run", "Do not create anything in THL, just print the items that would be created") { options.dryrun = true }
# opts.on("-n", "--notes", "Shows only tasks with notes") { options[:tasks] = { :onlynotes => true } }
# opts.on("-a", "--all", 'Shows all tasks in the focus') { |f| options[:tasks] = { :children => false } }
@@ -82,25 +73,42 @@
# Create top-level containers if needed
# First, traverse all areas
if options.areas
+ puts "Processing Areas of Responsibility" unless options.quiet
things.areas.get.each do |area|
converter.process(Things2THL::ThingsNode.new(area))
end
end
# Next, traverse all projects, putting each one inside its corresponding area
-things.projects.get.each do |project|
+puts "Processing Projects" unless options.quiet
+if options.completed
+ puts " (fetching all projects - this may take a while)" unless options.quiet
+ projlist=things.projects.get
+else
+ puts " (fetching only open projects - this may take a while)" unless options.quiet
+ projlist=things.projects[its.status.eq(:open)].get
+end
+projlist.each do |project|
converter.process(Things2THL::ThingsNode.new(project))
end
# Now do the tasks
# This is more complicated because:
# - to_dos returns not only tasks, also projects (not areas)
# - to-dos returns tasks from all the views: Inbox, Today, Scheduled, Someday, and Next, so we have
# to separate them and create the appropriate containers as needed
-things.to_dos.get.each do |t|
+puts "Processing tasks" unless options.quiet
+if options.completed
+ puts " (fetching all tasks - this may take a while)" unless options.quiet
+ tasklist=things.to_dos.get
+else
+ puts " (fetching only open tasks - this may take a while)" unless options.quiet
+ tasklist=things.to_dos[its.status.eq(:open)].get
+end
+tasklist.each do |t|
task=Things2THL::ThingsNode.new(t)
next if task.type != :selected_to_do
converter.process(task)
end