From d9f593080a94178e9e703df1b78ab25af2e61c4d Mon Sep 17 00:00:00 2001 From: Martin Levy Date: Mon, 17 Oct 2016 17:16:49 -0700 Subject: [PATCH] added -d/--dump command to display list of API calls --- cli4/cli4.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/cli4/cli4.py b/cli4/cli4.py index c67d596..fff9c8b 100644 --- a/cli4/cli4.py +++ b/cli4/cli4.py @@ -111,28 +111,51 @@ def convert_virtual_dns_to_identifier(cf, virtual_dns_name): exit('cli4: %s - no virtual_dns found' % (virtual_dns_name)) +def walk(m, s): + """recursive walk of the tree""" + for n in sorted(dir(m)): + if n[0] == '_': + # internal + continue + if n in ['delete', 'get', 'patch', 'post', 'put']: + # gone too far + continue + a = getattr(m, n) + d = dir(a) + if 'delete' in d or 'get' in d or 'patch' in d or 'post' in d or 'put' in d: + # it's a known api call - lets print it and continue down the tree + print s + '/' + n + walk(a, s + '/' + n) + +def dump_commands(cf): + """dump a tree of all the known API commands""" + walk(cf, '') + def cli4(args): """Cloudflare API via command line""" verbose = False output = 'json' raw = False + dump = False method = 'GET' usage = ('usage: cli4 ' + '[-V|--version] [-h|--help] [-v|--verbose] [-q|--quiet] [-j|--json] [-y|--yaml] ' + '[-r|--raw] ' + + '[-d|--dump] ' + '[--get|--patch|--post|-put|--delete] ' + '[item=value ...] ' + '/command...') try: opts, args = getopt.getopt(args, - 'VhvqjyrGPOUD', + 'VhvqjyrdGPOUD', [ 'version', 'help', 'verbose', 'quiet', 'json', 'yaml', 'raw', + 'dump', 'get', 'patch', 'post', 'put', 'delete' ]) except getopt.GetoptError: @@ -152,6 +175,8 @@ def cli4(args): output = 'yaml' elif opt in ('-r', '--raw'): raw = True + elif opt in ('-d', '--dump'): + dump = True elif opt in ('-G', '--get'): method = 'GET' elif opt in ('-P', '--patch'): @@ -189,6 +214,11 @@ def cli4(args): tag = tag_string params[tag] = value + if dump: + cf = CloudFlare.CloudFlare() + dump_commands(cf) + exit(0) + # what's left is the command itself if len(args) != 1: exit(usage)