"""Script for activating/creating a project in the projects folder."""
import argparse
import os
from plumbum import local
from plumbum.cmd import ln


class DefaultsInstaller:
    """Adds subdirectories to defaults/commands and defaults/projects."""

    def _args(self):
        """Get command line args."""
        parser = argparse.ArgumentParser()

        group = parser.add_mutually_exclusive_group(required=True)
        group.add_argument(
            '--git',
            action="store_true",
            dest="use_git",
            help='Use a git repository'
        )
        group.add_argument(
            '--ln',
            action="store_false",
            dest="use_git",
            help='Use a symlink'
        )

        group = parser.add_mutually_exclusive_group(required=True)
        group.add_argument('--commands')
        group.add_argument('--projects')
        return parser.parse_args()

    def _install(self, dest_folder, url, use_git):
        """Install resource 'url' into dest_folder."""
        if use_git:
            with local.cwd(dest_folder):
                local['git']['clone', url]()
        else:
            ln("-s", os.path.abspath(url), dest_folder)

    def _install_commands(self, url, use_git):
        """Install the folder with the default commands."""
        commands_dir = os.path.join(
            self.source_folder, "defaults", "commands"
        )
        self._install(commands_dir, url, use_git)

    def _install_projects(self, url, use_git):
        """Install the folder with the default commands."""
        projects_dir = os.path.join(
            self.source_folder, "defaults", "projects"
        )
        self._install(projects_dir, url, use_git)

    def run(self):
        """Activate or create a project in the projects folder."""
        bin_folder = os.path.dirname(__file__)
        self.source_folder = os.path.dirname(bin_folder)
        args = self._args()

        url, install = (
            (args.commands, self._install_commands)
            if args.commands else
            (args.projects, self._install_projects)
        )

        if not args.use_git and not os.path.exists(url):
            print("Error: path not found: %s" % url)
            return

        install(url, args.use_git)

@@ -90,16 +90,28 @@
 port os%0A
+import sys%0A%0A
 from plu
@@ -155,16 +155,77 @@
 port ln%0A
+from plumbum.commands.processes import ProcessExecutionError%0A
 %0A%0Aclass 
@@ -982,24 +982,102 @@
 rse_args()%0A%0A
+    def _report_error(self, msg):%0A        sys.stderr.write(msg + os.linesep)%0A%0A
     def _ins
@@ -1162,32 +1162,49 @@
 dest_folder.%22%22%22%0A
+        try:%0A    
         if use_g
@@ -1207,16 +1207,20 @@
 se_git:%0A
+    
         
@@ -1268,16 +1268,20 @@
         
+    
 local%5B'g
@@ -1309,16 +1309,20 @@
         
+   
+ 
 else:%0A  
@@ -1335,51 +1335,891 @@
     
-ln(%22-s%22, os.path.abspath(url), dest_folder)
+    if not os.path.exists(url):%0A                    self._report_error(%22Error: path not found: %25s%22 %25 url)%0A                    return False%0A                ln(%22-s%22, os.path.abspath(url), dest_folder)%0A        except ProcessExecutionError:%0A            if use_git:%0A                self._report_error((%0A                    %22Could not clone into %25s. Check that the %22 +%0A                    %22destination does not already exist.%22) %25 dest_folder%0A                )%0A            else:%0A                dest_path = os.path.join(dest_folder, os.path.basename(url))%0A                msg = (%0A                    %22%25s already exists (no changes were made).%22 %25 dest_path%0A                    if os.path.exists(dest_path) else%0A                    %22Error: could not create a symlink in %25s.%22 %25 dest_folder%0A                )%0A                self._report_error(msg)%0A            return False%0A%0A        return True
 %0A%0A  
@@ -2425,32 +2425,39 @@
       )%0A        
+return 
 self._install(co
@@ -2696,24 +2696,31 @@
   )%0A        
+return 
 self._instal
@@ -3132,16 +3132,16 @@
 ojects)%0A
+
         
@@ -3147,138 +3147,8 @@
  )%0A%0A
-        if not args.use_git and not os.path.exists(url):%0A            print(%22Error: path not found: %25s%22 %25 url)%0A            return%0A%0A
     

Improve error messages for dodo-install-defaults