Permalink
Browse files

fixed issues #64 and #65

  • Loading branch information...
1 parent b459783 commit db752e36f5719fe1ca05e4c393e6df8d4da57cc7 @stepler stepler committed Jul 10, 2012
Showing with 53 additions and 42 deletions.
  1. +36 −29 argparser.py
  2. +12 −4 unit/argparserTest.py
  3. +1 −5 unit/editorTest.py
  4. +4 −4 unit/geeknoteTest.py
View
@@ -33,54 +33,54 @@
"create": {
"help": "Create note in evernote.",
"arguments": {
- "--title": {"help": "The note title.", "required": True},
- "--content": {"help": "The note content.", "required": True},
- "--tags": {"help": "One tag or the list of tags which will be added to the note."},
- "--notebook": {"help": "Set the notebook where to save note."}
+ "--title": {"altName": "-t", "help": "The note title.", "required": True},
+ "--content": {"altName": "-c", "help": "The note content.", "required": True},
+ "--tags": {"altName": "-tg","help": "One tag or the list of tags which will be added to the note."},
+ "--notebook": {"altName": "-nb", "help": "Set the notebook where to save note."}
}
},
"edit": {
"help": "Edit note in Evernote.",
"firstArg": "--note",
"arguments": {
- "--note": {"help": "The name or ID from the previous search of a note to edit."},
- "--title": {"help": "Set new title of the note."},
- "--content": {"help": "Set new content of the note."},
- "--tags": {"help": "Set new list o tags for the note."},
- "--notebook": {"help": "Assign new notebook for the note."}
+ "--note": {"altName": "-n", "help": "The name or ID from the previous search of a note to edit."},
+ "--title": {"altName": "-t", "help": "Set new title of the note."},
+ "--content": {"altName": "-c", "help": "Set new content of the note."},
+ "--tags": {"altName": "-tg", "help": "Set new list o tags for the note."},
+ "--notebook": {"altName": "-nb", "help": "Assign new notebook for the note."}
}
},
"remove": {
"help": "Remove note from Evernote.",
"firstArg": "--note",
"arguments": {
- "--note": {"help": "The name or ID from the previous search of a note to remove."},
+ "--note": {"altName": "-n", "help": "The name or ID from the previous search of a note to remove."},
},
"flags": {
- "--force": {"help": "Don't ask about removing.", "value": True, "default": False},
+ "--force": {"altName": "-f", "help": "Don't ask about removing.", "value": True, "default": False},
}
},
"show": {
"help": "Output note in the terminal.",
"firstArg": "--note",
"arguments": {
- "--note": {"help": "The name or ID from the previous search of a note to show."},
+ "--note": {"altName": "-n", "help": "The name or ID from the previous search of a note to show."},
}
},
"find": {
"help": "Search notes in Evernote.",
"firstArg": "--search",
"arguments": {
- "--search": {"help": "Text to search.", "emptyValue": "*"},
- "--tags": {"help": "Notes with which tag/tags to search."},
- "--notebooks": {"help": "In which notebook search the note."},
- "--date": {"help": "Set date in format dd.mm.yyyy or date range dd.mm.yyyy-dd.mm.yyyy."},
- "--count": {"help": "How many notes show in the result list.", "type": int},
+ "--search": {"altName": "-s", "help": "Text to search.", "emptyValue": "*"},
+ "--tags": {"altName": "-tg", "help": "Notes with which tag/tags to search."},
+ "--notebooks": {"altName": "-nb", "help": "In which notebook search the note."},
+ "--date": {"altName": "-d", "help": "Set date in format dd.mm.yyyy or date range dd.mm.yyyy-dd.mm.yyyy."},
+ "--count": {"altName": "-cn", "help": "How many notes show in the result list.", "type": int},
},
"flags": {
- "--with-url": {"help": "Add direct url of each note in results to Evernote web-version.", "value": True, "default": False},
- "--exact-entry": {"help": "Search for exact entry of the request.", "value": True, "default": False},
- "--content-search": {"help": "Search by content, not by title.", "value": True, "default": False},
+ "--with-url": {"altName": "-wu", "help": "Add direct url of each note in results to Evernote web-version.", "value": True, "default": False},
+ "--exact-entry": {"altName": "-ee", "help": "Search for exact entry of the request.", "value": True, "default": False},
+ "--content-search": {"altName": "-cs", "help": "Search by content, not by title.", "value": True, "default": False},
}
},
@@ -91,15 +91,15 @@
"notebook-create": {
"help": "Create new notebook.",
"arguments": {
- "--title": {"help": "Set the title of new notebook."},
+ "--title": {"altName": "-t", "help": "Set the title of new notebook."},
}
},
"notebook-edit": {
"help": "Edit/rename notebook.",
"firstArg": "--notebook",
"arguments": {
- "--notebook": {"help": "The name of a notebook to rename."},
- "--title": {"help": "Set the new name of notebook."},
+ "--notebook": {"altName": "-nb", "help": "The name of a notebook to rename."},
+ "--title": {"altName": "-t", "help": "Set the new name of notebook."},
}
},
@@ -110,15 +110,15 @@
"tag-create": {
"help": "Create new tag.",
"arguments": {
- "--title": {"help": "Set the title of new tag."},
+ "--title": {"altName": "-t", "help": "Set the title of new tag."},
}
},
"tag-edit": {
"help": "Edit/rename tag.",
"firstArg": "--tagname",
"arguments": {
- "--tagname": {"help": "The name of a tag to rename."},
- "--title": {"help": "Set the new name of tag."},
+ "--tagname": {"altName": "-tgn", "help": "The name of a tag to rename."},
+ "--title": {"altName": "-t", "help": "Set the new name of tag."},
}
},
}
@@ -198,12 +198,16 @@ def parse(self):
self.printHelp()
return False
- # подготовка к парсингу
+ # Подготовка данных
for arg, params in (self.CMD_ARGS.items() + self.CMD_FLAGS.items()):
# установка значений по умолчаеию
if params.has_key('default'):
self.INP_DATA[arg] = params['default']
+ # замена altName во входящих аргументах на полные
+ if params.has_key('altName') and params['altName'] in self.INP:
+ self.INP[self.INP.index(params['altName'])] = arg
+
activeArg = None
ACTIVE_CMD = None
# проверяем и подставляем первый адгумент по умолчанию
@@ -353,9 +357,12 @@ def printHelp(self):
out.printLine("Options for: %s" % self.CMD)
out.printLine("Available arguments:")
for arg in self.CMD_ARGS:
- out.printLine("%s : %s" % (arg.rjust(tab, " "), self.CMD_ARGS[arg]['help']))
+ out.printLine("%s : %s%s" % (
+ arg.rjust(tab, " "),
+ '[default] ' if self.COMMANDS[self.CMD].has_key('firstArg') and self.COMMANDS[self.CMD]['firstArg'] == arg else '',
+ self.CMD_ARGS[arg]['help']))
if self.CMD_FLAGS:
out.printLine("Available flags:")
for flag in self.CMD_FLAGS:
- out.printLine("%s : %s" % (flag.rjust(tab, " "), self.CMD_FLAGS[flag]['help']))
+ out.printLine("%s : %s" % (flag.rjust(tab, " "), self.CMD_FLAGS[flag]['help']))
View
@@ -11,12 +11,12 @@ def setUp(self):
"help": "Create note",
"firstArg": "--test_req_arg",
"arguments": {
- "--test_req_arg": {"help": "Set note title", "required": True},
- "--test_arg": {"help": "Add tag to note", "emptyValue": None},
- "--test_arg2": {"help": "Add tag to note",},
+ "--test_req_arg": {"altName": "-tra", "help": "Set note title", "required": True},
+ "--test_arg": {"altName": "-ta", "help": "Add tag to note", "emptyValue": None},
+ "--test_arg2": {"altName": "-ta2", "help": "Add tag to note",},
},
"flags": {
- "--test_flag": {"help": "Add tag to note", "value": True, "default": False},
+ "--test_flag": {"altName": "-tf", "help": "Add tag to note", "value": True, "default": False},
}
}
@@ -68,6 +68,14 @@ def testSuccessCommand5(self):
parser = argparser(["testing", "test_def_val", "--test_arg", "--test_arg2", "test_arg2_val"])
self.assertEqual(parser.parse(), {"test_req_arg": "test_def_val", "test_arg": None, "test_arg2": "test_arg2_val", "test_flag": False})
+ def testSuccessShortAttr(self):
+ parser = argparser(["testing", "test_def_val", "-ta", "-ta2", "test_arg2_val"])
+ self.assertEqual(parser.parse(), {"test_req_arg": "test_def_val", "test_arg": None, "test_arg2": "test_arg2_val", "test_flag": False})
+
+ def testSuccessShortAttr2(self):
+ parser = argparser(["testing", "-tra", "test_def_val", "-tf"])
+ self.assertEqual(parser.parse(), {"test_req_arg": "test_def_val", "test_flag": True})
+
def suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(testArgparser))
View
@@ -13,11 +13,7 @@ def setUp(self):
*Line 2*
**Line 3**"""
self.HTML_TEXT = \
-"""<h1>Header 1</h1>
-<h2>Header 2</h2>
-<p>Line 1<br />
-<em>Line 2</em><br />
-<strong>Line 3</strong></p>"""
+"""<h1>Header 1</h1><h2>Header 2</h2><p>Line 1<br /><em>Line 2</em><br /><strong>Line 3</strong></p>"""
def testTextToENML(self):
self.assertEqual(textToENML(self.MD_TEXT), wrapENML(self.HTML_TEXT))
View
@@ -35,7 +35,7 @@ def test_parceInput1(self):
self.assertEqual(testData["tags"], ["tag1", ])
def test_parceInput2(self):
- testData = self.notes._parceInput("title", "WRITE_IN_EDITOR", "tag1, tag2", None, self.testNote)
+ testData = self.notes._parceInput("title", "WRITE", "tag1, tag2", None, self.testNote)
self.assertIsInstance(testData, dict)
if not isinstance(testData, dict): return
@@ -45,13 +45,13 @@ def test_parceInput2(self):
def test_createSearchRequest1(self):
testRequest = self.notes._createSearchRequest(search="test text", tags="tag1",
- notebooks="test notebook", date="31.12.1999", exact_entry=True, content_search=True)
- self.assertEqual(testRequest, 'any:"test text" tag:"tag1" created:"19991231" -created:"20000101" notebook:"test notebook" ')
+ notebooks="test notebook", date="01.01.2000", exact_entry=True, content_search=True)
+ self.assertEqual(testRequest, 'notebook:"test notebook" tag:"tag1" created:19991231 -created:20000101 "test text"')
def test_createSearchRequest2(self):
testRequest = self.notes._createSearchRequest(search="test text", tags="tag1, tag2",
notebooks="notebook1, notebook2", date="31.12.1999-31.12.2000", exact_entry=False, content_search=False)
- self.assertEqual(testRequest, 'intitle:test text tag:"tag1" tag:"tag2" created:"19991231" -created:"20001231" notebook:"notebook1" notebook:"notebook2" ')
+ self.assertEqual(testRequest, 'notebook:"notebook1" notebook:"notebook2" tag:"tag1" tag:"tag2" created:19991231 -created:20001231 intitle:test text')
def testError_createSearchRequest1(self):
testRequest = self.notes._createSearchRequest(search="test text", date="12.31.1999")

0 comments on commit db752e3

Please sign in to comment.