Skip to content

Commit

Permalink
Implement 'braindump ls' command to list topics
Browse files Browse the repository at this point in the history
  • Loading branch information
Problematic committed Jan 27, 2013
1 parent 6ab5e7c commit 16d08af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion braindump/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
braindump - record what's on your mind
Usage:
braindump ls
braindump [options] [TOPIC]
Arguments:
ls Output a list of topic files
TOPIC Subject to braindump on, determines filename [default: braindump]
Options:
Expand Down Expand Up @@ -53,7 +55,13 @@ def main():
dumper = FSDumper(settings)
topic = arguments['TOPIC'] if arguments['TOPIC'] is not None else settings['default_topic']

if arguments['-m'] is not None:
if arguments['ls'] is True:
topics = dumper.list_topics()
output = '{0} braindump topics:'.format(len(topics))
for topic in topics:
output += '\n- {0}'.format(topic)
print output
elif arguments['-m'] is not None:
dumper.quick_add(topic, arguments['-m'])
else:
dumper.edit_topic(topic)
8 changes: 8 additions & 0 deletions braindump/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import os
from subprocess import call, Popen
from glob import glob


class FSDumper(object):
Expand All @@ -23,6 +24,13 @@ def quick_add(self, topic, message):
def edit_topic(self, topic):
self._launch_editor(self.settings['editor'], self._get_topic_filename(topic))

def list_topics(self):
topic_files = glob('{0}/*{1}'.format(self.settings['braindump_dir'], self.settings['file_ext']))
topics = []
for topic in topic_files:
topics.append(os.path.splitext(os.path.basename(topic))[0])
return topics

def _get_topic_filename(self, topic, full=True):
filename = topic + self.settings['file_ext']

Expand Down

0 comments on commit 16d08af

Please sign in to comment.