diff --git a/README.md b/README.md index c5d18b4..82ee1f3 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ However, for now (and for backward compatibility reasons) the class name stays t ## Cloudflare API version 4 The Cloudflare API can be found [here](https://api.cloudflare.com/). -Each API call is provided via a similarly named function within the _CloudFlare_ class. +Each API call is provided via a similarly named function within the **CloudFlare** class. A full list is provided below. ## Example code @@ -167,7 +167,7 @@ if __name__ == '__main__': ## Providing Cloudflare Username and API Key -When you create a _CloudFlare_ class you can pass up to four paramaters. +When you create a **CloudFlare** class you can pass up to four paramaters. * Account email * Account API key @@ -412,10 +412,10 @@ For API calls that need to pass data or parameters there is various formats to u The simplest form is ```item=value```. This passes the value as a string within the APIs JSON data. -If you need a numeric value passed then _==_ can be used to force the value to be treated as a numeric value within the APIs JSON data. +If you need a numeric value passed then **==** can be used to force the value to be treated as a numeric value within the APIs JSON data. For example: ```item==value```. -if you need to pass a list of items; then _[]_ can be used. For example: +if you need to pass a list of items; then **[]** can be used. For example: ``` pool_id1="11111111111111111111111111111111" @@ -424,9 +424,20 @@ pool_id3="33333333333333333333333333333333" cli4 --post global_pools="[ ${pool_id1}, ${pool_id2}, ${pool_id3} ]" region_pools="[ ]" /user/load_balancers/maps ``` +Data or parameters can be either named or unnamed. +It can not be both. +Named is the majority format; as described above. +Unnamed parameters simply don't have anything before the **=** sign, as in ```=value```. +This format is presently only used by the Cloudflare Load Balancer API calls. +For example: + +``` +cli4 --put ="[ 00000000000000000000000000000000 ]" /user/load_balancers/maps/:00000000000000000000000000000000/region/WNAM +``` + ### CLI output -The output from the CLI command is in JSON or YAML format (and human readable). This is controled by the _--yaml_ or _--json_ flags (JSON is the default). +The output from the CLI command is in JSON or YAML format (and human readable). This is controled by the **--yaml** or **--json** flags (JSON is the default). ### Simple CLI examples diff --git a/README.rst b/README.rst index c6a0634..bc75361 100644 --- a/README.rst +++ b/README.rst @@ -45,7 +45,7 @@ Cloudflare API version 4 The Cloudflare API can be found `here `__. Each API call is provided via a similarly named function within the -*CloudFlare* class. A full list is provided below. +**CloudFlare** class. A full list is provided below. Example code ------------ @@ -187,7 +187,8 @@ A more complex example follows. Providing Cloudflare Username and API Key ----------------------------------------- -When you create a *CloudFlare* class you can pass up to four paramaters. +When you create a **CloudFlare** class you can pass up to four +paramaters. - Account email - Account API key @@ -459,11 +460,12 @@ formats to use. The simplest form is ``item=value``. This passes the value as a string within the APIs JSON data. -If you need a numeric value passed then *==* can be used to force the +If you need a numeric value passed then **==** can be used to force the value to be treated as a numeric value within the APIs JSON data. For example: ``item==value``. -if you need to pass a list of items; then *[]* can be used. For example: +if you need to pass a list of items; then **[]** can be used. For +example: :: @@ -472,12 +474,22 @@ if you need to pass a list of items; then *[]* can be used. For example: pool_id3="33333333333333333333333333333333" cli4 --post global_pools="[ ${pool_id1}, ${pool_id2}, ${pool_id3} ]" region_pools="[ ]" /user/load_balancers/maps +Data or parameters can be either named or unnamed. It can not be both. +Named is the majority format; as described above. Unnamed parameters +simply don't have anything before the **=** sign, as in ``=value``. This +format is presently only used by the Cloudflare Load Balancer API calls. +For example: + +:: + + cli4 --put ="[ 00000000000000000000000000000000 ]" /user/load_balancers/maps/:00000000000000000000000000000000/region/WNAM + CLI output ~~~~~~~~~~ The output from the CLI command is in JSON or YAML format (and human -readable). This is controled by the *--yaml* or *--json* flags (JSON is -the default). +readable). This is controled by the **--yaml** or **--json** flags (JSON +is the default). Simple CLI examples ~~~~~~~~~~~~~~~~~~~ diff --git a/cli4/cli4.py b/cli4/cli4.py index afaae99..44c6a03 100644 --- a/cli4/cli4.py +++ b/cli4/cli4.py @@ -146,7 +146,7 @@ def cli4(args): + '[-V|--version] [-h|--help] [-v|--verbose] [-q|--quiet] [-j|--json] [-y|--yaml] ' + '[-r|--raw] ' + '[-d|--dump] ' - + '[--get|--patch|--post|-put|--delete] ' + + '[--get|--patch|--post|--put|--delete] ' + '[item=value ...] ' + '/command...') @@ -193,7 +193,7 @@ def cli4(args): digits_only = re.compile('^[0-9]+$') # next grab the params. These are in the form of tag=value - params = {} + params = None while len(args) > 0 and '=' in args[0]: tag_string, value_string = args.pop(0).split('=', 1) if value_string == 'true': @@ -213,8 +213,22 @@ def cli4(args): exit('cli4: %s="%s" - can\'t parse json value' % (tag_string, value_string)) else: value = value_string - tag = tag_string - params[tag] = value + if tag_string == '': + # There's no tag; it's just an unnamed list + if params == None: + params = [] + try: + params.append(value) + except AttributeError: + exit('cli4: %s=%s - param error. Can\'t mix unnamed and named list' % (tag_string, value_string)) + else: + if params == None: + params = {} + tag = tag_string + try: + params[tag] = value + except TypeError: + exit('cli4: %s=%s - param error. Can\'t mix unnamed and named list' % (tag_string, value_string)) if dump: cf = CloudFlare.CloudFlare()