Skip to content

Commit 8cfa2db

Browse files
committed
bug: Fixed error output for CLI operations
Related to #273 Right now, the output you get when you call a CLI operation without arguments is as follows: ```bash $ linode-cli networking ip-update usage: linode-cli [-h] [--rdns rdns] address linode-cli: error: the following arguments are required: address ``` The "usage" line in that output is clearly wrong, as you did not invoke `linode-cli` by itself. This change adds the command/action you provided into that output to make it display correctly: ```bash $ linode-cli networking ip-update usage: linode-cli networking ip-update [-h] [--rdns rdns] address linode-cli networking ip-update: error: the following arguments are required: address ```
1 parent c7cb983 commit 8cfa2db

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

linodecli/cli.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,18 @@ def bake(self, spec):
289289
use_path = use_path.replace("{"+p.name+"}", "{"+p.name+"_}")
290290
p.name += '_'
291291

292-
self.ops[command][action] = CLIOperation(m, use_path, summary,
293-
cli_args, response_model,
294-
use_params, use_servers,
295-
allowed_defaults=allowed_defaults)
292+
self.ops[command][action] = CLIOperation(
293+
command,
294+
action,
295+
m,
296+
use_path,
297+
summary,
298+
cli_args,
299+
response_model,
300+
use_params,
301+
use_servers,
302+
allowed_defaults=allowed_defaults,
303+
)
296304

297305
# hide the base_url from the spec away
298306
self.ops['_base_url'] = spec['servers'][0]['url']

linodecli/operation.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ class CLIOperation:
122122
are responsible for parsing their own arguments and processing their
123123
responses with the help of their ResponseModel
124124
"""
125-
def __init__(self, method, url, summary, args, response_model,
125+
def __init__(self, command, action, method, url, summary, args, response_model,
126126
params, servers, allowed_defaults = None):
127+
self.command = command
128+
self.action = action
127129
self.method = method
128130
self._url = url
129131
self.summary = summary
@@ -149,7 +151,10 @@ def parse_args(self, args):
149151
list_items = []
150152

151153
# build an argparse
152-
parser = argparse.ArgumentParser(description=self.summary)
154+
parser = argparse.ArgumentParser(
155+
prog="linode-cli {} {}".format(self.command, self.action),
156+
description=self.summary,
157+
)
153158
for param in self.params:
154159
parser.add_argument(param.name, metavar=param.name,
155160
type=TYPES[param.param_type])

0 commit comments

Comments
 (0)