@@ -38,49 +38,49 @@ def argparser(argv):
"[--config=CONFIG] [--save-config] "
"METHOD <key:val> <key2:val> ...\n"
"Create config file: kallithea-api --apikey=<key> --apihost=http://kallithea.example.com --save-config"
)
parser = argparse.ArgumentParser(description='Kallithea API cli',
usage=usage)
## config
group = parser.add_argument_group('config')
group.add_argument('--apikey', help='api access key')
group.add_argument('--apihost', help='api host')
group.add_argument('--config', help='config file')
group.add_argument('--save-config', action='store_true', help='save the given config into a file')
group = parser.add_argument_group('API')
group.add_argument('method', metavar='METHOD', nargs='?', type=str, default=None,
help='API method name to call followed by key:value attributes',
group.add_argument('--format', dest='format', type=str,
help='output format default: `%s` can '
'be also `%s`' % (FORMAT_PRETTY, FORMAT_JSON),
default=FORMAT_PRETTY
args, other = parser.parse_known_args(args=argv)
args, other = parser.parse_known_args(args=argv[1:])
return parser, args, other
def main(argv=None):
"""
Main execution function for cli
:param argv:
if argv is None:
argv = sys.argv
conf = None
parser, args, other = argparser(argv)
api_credentials_given = (args.apikey and args.apihost)
if args.save_config:
if not api_credentials_given:
raise parser.error('--save-config requires --apikey and --apihost')
conf = RcConf(config_location=args.config,
autocreate=True, config={'apikey': args.apikey,
'apihost': args.apihost})
sys.exit()
@@ -47,49 +47,49 @@ def argparser(argv):
group.add_argument('--config', help='config file path DEFAULT: ~/.config/kallithea')
group.add_argument('--save-config', action='store_true',
help='save the given config into a file')
group = parser.add_argument_group('GIST')
group.add_argument('-p', '--private', action='store_true',
help='create private Gist')
group.add_argument('-f', '--filename',
help='set uploaded gist filename, '
'also defines syntax highlighting')
group.add_argument('-d', '--description', help='Gist description')
group.add_argument('-l', '--lifetime', metavar='MINUTES',
help='gist lifetime in minutes, -1 (DEFAULT) is forever')
help='output format DEFAULT: `%s` can '
def _run(argv):
if not conf:
conf = RcConf(config_location=args.config, autoload=True)
parser.error('Could not find config file and missing '
'--apikey or --apihost in params')
apikey = args.apikey or conf['apikey']
Status change: