'''
The management of salt command line utilities are stored in here
'''
# Import python libs
import optparse
import os
import sys

# Import salt components
import salt.client

class SaltCMD(object):
    '''
    The execution of a salt command happens here
    '''
    def __init__(self):
        '''
        Cretae a SaltCMD object
        '''
        self.opts = self.__parse()

    def __parse(self):
        '''
        Parse the command line
        '''
        parser = optparse.OptionParser()
        
        parser.add_option('-t',
                '--timeout',
                default=5,
                type=int,
                dest='timeout',
                help='Set the return timeout for batch jobs')
        parser.add_option('-E',
                '--pcre',
                default=False,
                dest='pcre',
                action='store_true'
                help='Instead of using shell globs to evaluate the target'\
                   + ' servers, use pcre regular expressions')
        parser.add_option('-Q',
                '--query',
                dest='query',
                default=False,
                action='store_true',
                help='Execute a salt command query, this can be used to find'\
                    + ' previous function calls, of to look up a call that'\
                    + ' occured at a specific time.')
        parser.add_option('-c',
                '--cmd',
                dest='cmd',
                default='',
                help='Used with the Query option, pass in the command to get'\
                    + ' results from.')

        options, args = parser.parse_args()

        opts = {}

        opts['timeout'] = options.timeout
        opts['pcre'] = options.pcre
        if options.query:
            opts['query'] = options.query
            opts['cmd'] = options.cmd
        else:
            opts['tgt'] = args[0]
            opts['fun'] = args[1]
            opts['arg'] = args[2:]

        return opts

    def run(self):
        '''
        Execute the salt command line
        '''
        if opts['query']:
            cli = 
        local = salt.client.LocalClient()
        args = [self.opts['tgt'],
                self.opts['fun'],
                self.opts['arg'],
                self.opts['timeout'],
                ]
        if self.opts['pcre']:
            args.append('pcre')
        print local.cmd(*args)


@@ -1374,488 +1374,466 @@
 .')%0A
-        parser.add_option('-c',%0A                '--cmd',%0A                dest='cmd',%0A                default='',%0A                help='Used with the Query option, pass in the command to get'%5C%0A                    + ' results from.')%0A%0A        options, args = parser.parse_args()%0A%0A        opts = %7B%7D%0A%0A        opts%5B'timeout'%5D = options.timeout%0A        opts%5B'pcre'%5D = options.pcre%0A        if options.query:%0A            opts%5B'query'%5D = options.query%0A            opts%5B'cmd'%5D = options.cmd
+%0A        options, args = parser.parse_args()%0A%0A        opts = %7B%7D%0A%0A        opts%5B'timeout'%5D = options.timeout%0A        opts%5B'pcre'%5D = options.pcre%0A        if options.query:%0A            opts%5B'query'%5D = options.query%0A            if len(args) %3C 1:%0A                err = 'Please pass in a command to query the old salt calls'%5C%0A                    + ' for.'%0A                sys.stderr.write(err, + '%5Cn')%0A                sys.exit('2')%0A            opts%5B'cmd'%5D = args%5B0%5D
 %0A   
@@ -2061,87 +2061,142 @@
     
-if opts%5B'query'%5D:%0A            cli = %0A        local = salt.client.LocalClient()%0A
+local = salt.client.LocalClient()%0A        if self.opts%5B'query'%5D:%0A            print local.find_cmd(self.opts%5B'cmd'%5D)%0A        else:%0A    
     
@@ -2233,32 +2233,36 @@
                 
+ 
+   
 self.opts%5B'fun'%5D
@@ -2259,24 +2259,28 @@
 pts%5B'fun'%5D,%0A
+    
             
@@ -2309,32 +2309,36 @@
                 
+  
+  
 self.opts%5B'timeo
@@ -2359,26 +2359,33 @@
         
-%5D%0A
+    %5D%0A   
         
 if self.
@@ -2368,32 +2368,33 @@
    %5D%0A           
+ 
 if self.opts%5B'pc
@@ -2407,24 +2407,28 @@
             
+    
 args.append(
@@ -2435,16 +2435,20 @@
 'pcre')%0A
+    
         

Add the correct logic to execute queries from the command line