Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

command line improvements #6

Merged
merged 2 commits into from

2 participants

@ctanis

some minor improvements to the command line processing for adding tasks. a * followed by whitespace now indicates that we want to star the message and you can use numbers (-1, 0, 1, 2, 3) with the ! for specifying priority.

@wsargent
Owner

Can you write some unit tests to verify the parsing works correctly, and add some text to the README?

@ctanis

done..

ideally these modifications would work for the other commands in addition to 'add', but perhaps that can be saved for the refactoring you mentioned.

@wsargent
Owner

Thanks -- should be free to merge it on Friday.

@wsargent wsargent merged commit 16faa79 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
7 README.md
@@ -59,6 +59,13 @@ for the client is as follows:
#DueDate
%Tags
+Additionally, a * _not_ followed immediately by a folder name
+indicates that the task should be starred.
+
+For adding tasks, you may specify Priority as either a word:
+top,high,medium,low,negative or as a number: -1,0,1,2,3
+
+
You can encase the symbol with square brackets if there is a space involved:
*[Blue Sky]
View
7 lib/toodledo/command_line/client.rb
@@ -419,13 +419,14 @@ def list_folders(session, input)
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 })
@@ -450,6 +451,10 @@ def add_task(session, line)
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)
View
29 lib/toodledo/command_line/parser_helper.rb
@@ -16,18 +16,21 @@ module ParserHelper
CONTEXT_REGEXP = /\@((\w+)|\[(.*?)\])/
- PRIORITY_REGEXP = /!(top|high|medium|low|negative)/
+ PRIORITY_REGEXP = /!(top|high|medium|low|negative|-1|0|1|2|3)/
DATE_REGEXP = /\#(([^\[]\S*)|\[(.*?)\])/
TAGS_REGEXP = /\%((\w+)|\[(.*?)\])/
+ STAR_REGEXP = /\*\s+|\*$/
+
# Note that level must exist at the beginning of the line
LEVEL_REGEXP = /^(life|medium|short)/
# Don't include level regexp
REGEXP_LIST = [
FOLDER_REGEXP,
+ STAR_REGEXP,
GOAL_REGEXP,
CONTEXT_REGEXP,
PRIORITY_REGEXP,
@@ -92,6 +95,17 @@ def parse_priority(input)
return Toodledo::Priority::LOW
when 'negative'
return Toodledo::Priority::NEGATIVE
+ when '-1'
+ return Toodledo::Priority::NEGATIVE
+ when '0'
+ return Toodledo::Priority::LOW
+ when '1'
+ return Toodledo::Priority::MEDIUM
+ when '2'
+ return Toodledo::Priority::HIGH
+ when '3'
+ return Toodledo::Priority::TOP
+
else
return nil
end
@@ -116,7 +130,17 @@ def parse_level(input)
end
end
- # Returns the bit after we've looked for *Folder, @Context & ^Goal
+ def parse_star(input)
+ match_data = STAR_REGEXP.match(input)
+ if (match_data == nil)
+ return false
+ else
+ return true
+ end
+ end
+
+
+ # Returns the bit after we've looked for *Folder, @Context & ^Goal & star
def parse_remainder(line)
input = line
@@ -129,6 +153,7 @@ def parse_remainder(line)
return input
end
+
# Strips a string of [ and ] characters
def strip_brackets(inword)
View
78 test/parser_helper_test.rb
@@ -158,4 +158,80 @@ def test_find_level_with_short()
assert_equal(Goal::SHORT_LEVEL, level, 'level not found')
end
-end
+ def test_find_star()
+ input = '* this is a starred task'
+ star = parse_star(input)
+ folder = parse_folder(input)
+ assert_equal(star, true)
+ assert_equal(folder, nil)
+ end
+
+ def test_find_star2()
+ input = 'this is also a starred task *'
+ star = parse_star(input)
+ folder = parse_folder(input)
+ assert_equal(star, true)
+ assert_equal(folder, nil)
+ end
+
+ def test_find_star3()
+ input = 'this is not a starred task *foo'
+ star = parse_star(input)
+ folder = parse_folder(input)
+ assert_equal(star, false)
+ assert_equal(folder, "foo")
+ end
+
+ def test_find_star4()
+ input = '* but this is not a starred task *foo'
+ star = parse_star(input)
+ folder = parse_folder(input)
+ assert_equal(star, true)
+ assert_equal(folder, "foo")
+ end
+
+ def test_find_priority_with_numbers1
+ input = "!3 I AM VERY IMPORTANT!"
+
+ priority = parse_priority(input)
+
+ assert(priority == Priority::TOP, "Value not found")
+ end
+
+ def test_find_priority_with_numbers2
+ input = "I AM QUITE IMPORTANT! !2"
+
+ priority = parse_priority(input)
+
+ assert(priority == Priority::HIGH, "Value not found")
+ end
+
+ def test_find_priority_with_numbers3
+ input = "!1 I AM KINDA IMPORTANT!"
+
+ priority = parse_priority(input)
+
+ assert(priority == Priority::MEDIUM, "Value not found")
+ end
+
+
+ def test_find_priority_with_numbers4
+ input = "!0 I AM NOT VERY IMPORTANT!"
+
+ priority = parse_priority(input)
+
+ assert(priority == Priority::LOW, "Value not found")
+ end
+
+
+ def test_find_priority_with_numbers5
+ input = "!-1 I AM MAXIMALLY UNIMPORTANT!"
+
+ priority = parse_priority(input)
+
+ assert(priority == Priority::NEGATIVE, "Value not found")
+ end
+
+
+
+end
Something went wrong with that request. Please try again.