From 16037737eb6bbea91b4cc21e3895efda1f35f3ff Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 22 Mar 2012 17:36:12 +0000 Subject: Implement "morph init" and fix tests accordingly --- morph | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'morph') diff --git a/morph b/morph index d981bbb6..5b1bed7b 100755 --- a/morph +++ b/morph @@ -358,6 +358,24 @@ class Morph(cliapp.Application): def cmd_init(self, args): '''Initialize a mine.''' + + if not args: + args = ['.'] + elif len(args) > 1: + raise cliapp.AppException('init must get at most one argument') + + dirname = args[0] + + if os.path.exists(dirname): + if os.listdir(dirname) != []: + raise cliapp.AppException('can only initialize empty ' + 'directory: %s' % dirname) + else: + raise cliapp.AppException('can only initialize an existing ' + 'empty directory: %s' % dirname) + + os.mkdir(os.path.join(dirname, '.morph')) + os.mkdir(os.path.join(dirname, '.morph', 'cache')) def msg(self, msg): '''Show a message to the user about what is going on.''' -- cgit v1.2.1