Changeset - 955956f4bdda
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 13 years ago 2012-06-26 03:39:34
marcin@python-works.com
Show proper error on argument parse when using api-cli
1 file changed with 6 insertions and 1 deletions:
0 comments (0 inline, 0 general)
rhodecode/bin/rhodecode_api.py
Show inline comments
 
@@ -202,31 +202,36 @@ def main(argv=None):
 

	
 
    conf = None
 
    parser, args, other = argparser(argv)
 

	
 
    api_credentials_given = (args.apikey and args.apihost)
 
    if args.method == '_create_config':
 
        if not api_credentials_given:
 
            raise parser.error('_create_config requires --apikey and --apihost')
 
        conf = RcConf(autocreate=True, config={'apikey': args.apikey,
 
                                               'apihost': args.apihost})
 
        sys.stdout.write('Create new config in %s\n' % CONFIG_NAME)
 

	
 
    if not conf:
 
        conf = RcConf(autoload=True)
 
        if not conf:
 
            if not api_credentials_given:
 
                parser.error('Could not find config file and missing '
 
                             '--apikey or --apihost in params')
 

	
 
    apikey = args.apikey or conf['apikey']
 
    host = args.apihost or conf['apihost']
 
    method = args.method
 
    if method == '_create_config':
 
        sys.exit()
 
    margs = dict(map(lambda s: s.split(':', 1), other))
 

	
 
    try:
 
        margs = dict(map(lambda s: s.split(':', 1), other))
 
    except:
 
        sys.stderr.write('Error parsing arguments \n')
 
        sys.exit()
 

	
 
    api_call(apikey, host, args.format, method, **margs)
 
    return 0
 

	
 
if __name__ == '__main__':
 
    sys.exit(main(sys.argv))
0 comments (0 inline, 0 general)