Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add examples from docs #303

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions linodecli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,11 @@ def main():
arg.description,
)
)
if operation.example:
print()
print("Example:")
print(operation.example)

elif operation.method == "get" and parsed.action == "list":
filterable_attrs = [
attr for attr in operation.response_model.attrs if attr.filterable
Expand Down
8 changes: 8 additions & 0 deletions linodecli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ def bake(self, spec):
continue

summary = data[m].get("summary") or ""
example = None

if "x-code-samples" in data[m]:
for c in data[m]["x-code-samples"]:
if "lang" in c and c["lang"].lower() == "cli" and "source" in c:
example = c["source"]
break

use_servers = (
[c["url"] for c in data[m]["servers"]]
Expand Down Expand Up @@ -356,6 +363,7 @@ def bake(self, spec):
use_params,
use_servers,
allowed_defaults=allowed_defaults,
example=example,
)

# remove any empty commands (those that have no actions)
Expand Down
7 changes: 6 additions & 1 deletion linodecli/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ class CLIArg:
are defined in a requestBody in the api spec.
"""

def __init__(self, name, arg_type, description, path, arg_format, list_item=None):
def __init__(
self, name, arg_type, description, path, arg_format, list_item=None
):
self.name = name
self.arg_type = arg_type
self.arg_format = arg_format
Expand Down Expand Up @@ -147,6 +149,7 @@ def __init__(
params,
servers,
allowed_defaults=None,
example=None,
):
self.command = command
self.action = action
Expand All @@ -158,6 +161,7 @@ def __init__(
self.params = params
self.servers = servers
self.allowed_defaults = allowed_defaults
self.example = example

@property
def url(self):
Expand All @@ -178,6 +182,7 @@ def parse_args(self, args):
parser = argparse.ArgumentParser(
prog="linode-cli {} {}".format(self.command, self.action),
description=self.summary,
example=self.example,
)
for param in self.params:
parser.add_argument(
Expand Down