   when 'shell'
     command=''
     log "DB Shell Active type 'exit' or 'quit' to escape, 'help' or 'docs' for information"
-
+    rl.prompt();
     rl.on "line", (token) ->
       args=token.split(' ')
       command=args[0]
       args.splice(0,1)
-      executeCommand()
+      executeCommand(token,command,args)
+      rl.prompt();
 
     
   when 'docs'

"Shell Active type 'exit' or 'quit' to escape"
where <command> [command-specific-options] is one of:
  exit/quit                       exit shell
  get:sites [<slug>]              get sites with shell
  get:allsites                    returns a list of id_slug mappings for all sites
  get:objects_c <collection>      get objects with collection

        db.get('sites').find query, (err, sites) =>
         for site in sites
            log "_id: #{site.data._id}, slug:#{site.data.slug}"

    when 'get:objects_c'
      getDB (db) ->
        db.get('objects').find {collection: l_args[0]}, (err, objects) ->
          for object in objects
            log "------Object------"
            log JSON.stringify(object.val(), null, 4)
            log "------End Object------"

    when 'get:objects_t'
      getDB (db) ->
       db.get('objects').find {type: l_args[0]}, (err, objects) ->
        for object in objects
          log "------Object------"
          log JSON.stringify(object.val(), null, 4)
          log "------End Object------"

    when 'help' or 'docs'
      log USAGE_SHELL

    else
      checkForDb=l_token.match(/db.+(?=\()/)+""
      log "Check for DB #{checkForDb}"
      
      #helper function to extract jsons from a token
      extractJsons = (token)  =>
        count=0;
        stringToForm=""
        arr=[]
        started=false
        startIndex=token.indexOf '{'
        for index in [startIndex...token.length]
          char = token.charAt index 
          
          if char=="{"
            started=true
            count++
          else if char=="}"
            count--
        
          stringToForm+=char
          if count == 0 and started
            arr.push(stringToForm)
            stringToForm=""
            started=false

        return arr

      switch checkForDb
        when 'db.sites.find','db.sites.findOne','db.sites.findById'
          extractJsons l_token
          getDB (db) ->
            func=l_token.match(/f[a-zA-Z]+/)
            functionArgs=extractJsons(l_token)
            db.get('sites')[func] functionArgs[0],functionArgs[1], (err, objects) ->
              log objects
              for object in objects
                log "------Object------"
                log JSON.stringify(object.val(), null, 4)
                log "------End Object------"

        when 'db.objects.find','db.objects.findOne','db.objects.findById'
          extractJsons l_token
          getDB (db) ->
            func=l_token.match(/f[a-zA-Z]+/)
            functionArgs=extractJsons(l_token)
            db.get('sites')[func] functionArgs[0],functionArgs[1], (err, objects) ->
              for object in objects
                log "------Object------"
                log JSON.stringify(object.val(), null, 4)
                log "------End Object------"




# execute selected command
