Sander Smits avatar Sander Smits committed a65ab46

implemented search command

Comments (0)

Files changed (2)

                                       for)
   bbi open (o) <nr>                   (re)open issue <nr>
   bbi remove (rm) <nr>                remove issue <nr>
+  bbi search (s) <term>               search for <term>
   bbi -r <user>/<repo>                specify a repository (can be used for
                                       all commands)
   bbi -r <repo>                       specify a repository (gets user from

src/bbi/commands.py

         response = self.__submit(number, method='DELETE')
         if response == 'deleted':
             print 'deleted issue %s' % number
-            
+
+
+    def search(self, search_term=None, verbose=False, **kwargs):
+        if not search_term:
+            example = "%s search experimental" % get_prog()
+            msg = "error: search term required\nexample: %s" % example
+            print msg
+            sys.exit(1)
+        search_term_quoted = urllib.quote_plus(search_term)
+        search_term_quoted = search_term_quoted.replace(".", "%2E")
+        result = self.__submit('?search=%s' % search_term)
+        issues = get_key(result, 'issues')
+        header = "# searching for '%s' returned %s issues" % (search_term,
+            result['count'])
+        printer = Pager()
+        printer.write(header)
+        for issue in issues:
+            lines = format_issue(issue, verbose)
+            printer.write("\n".join(lines))
+        printer.close()
+        
 
     def __get_issue(self, number):
         result = self.__submit(number)
                                     for)
 %prog open (o) <nr>                   (re)open issue <nr>
 %prog remove (rm) <nr>                remove issue <nr>
+%prog search (s) <term>               search for <term>
 %prog -r <user>/<repo>                specify a repository (can be used for
                                     all commands)
 %prog -r <repo>                       specify a repository (gets user from
         cmd = 'list' # default command
 
     # handle command aliases
-    cmd = {'n': 'new', 'o': 'open', 'c': 'close', 'e': 'edit', 'rm': 'remove'
-        }.get(cmd, cmd)
+    cmd = {'n': 'new', 'o': 'open', 'c': 'close', 'e': 'edit', 'rm': 'remove',
+        's': 'search'}.get(cmd, cmd)
 
     try:
         repository = kwargs.get('repo')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.