MCPcopy Create free account
hub / github.com/ElementsProject/lightning / create_shell_command

Function create_shell_command

tools/fromschema.py:318–347  ·  view source on GitHub ↗

Output shell command for the request example

(rpc, example)

Source from the content-addressed store, hash-verified

316
317
318def create_shell_command(rpc, example):
319 """Output shell command for the request example"""
320 output('```shell\n')
321 shell_command = f'lightning-cli {rpc} '
322 if 'params' in example['request']:
323 if isinstance(example['request']['params'], list):
324 if rpc == 'sql' and example['request']['params'] and '=' in example['request']['params'][0]:
325 # For SQL queries in shell, prepend '-o' flag to the query
326 query = example['request']['params'][0]
327 shell_command += f"-o '{query}'" if "'" not in query else f'-o "{query}"'
328 else:
329 shell_command += ' '.join(f'"{item}"' for item in example['request']['params'])
330 elif example['request']['params'].items():
331 shell_command += '-k '
332 for k, v in example['request']['params'].items():
333 # If the value is a string, wrap it in double quotes
334 # otherwise, keep the json as is and wrap the whole value in single quotes
335 # Example 1: wrap route list in single quotes
336 # lightning-cli check -k "command_to_check"="sendpay" "route"='[{"amount_msat": 1011, "id": "022d223620a359a47ff7f7ac447c85c46c923da53389221a0054c11c1e3ca31d59", "delay": 20, "channel": "1x1x1"}, {"amount_msat": 1000, "id": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d", "delay": 10, "channel": "2x2x2"}]' "payment_hash"="0000000000000000000000000000000000000000000000000000000000000000"
337 # Example 2: keep subcommand value ("slowcmd") in double quotes
338 # lightning-cli check -k "command_to_check"="dev" "subcommand"="slowcmd" "msec"=1000
339 if isinstance(v, str):
340 shell_command += f'"{k}"="{v}" '
341 elif isinstance(v, int):
342 shell_command += f'"{k}"={v} '
343 else:
344 shell_command += f'"{k}"=\'' + json.dumps(v) + '\' '
345 shell_command = shell_command.strip()
346 output(shell_command + '\n')
347 output('```\n')
348
349
350def generate_header(schema, name):

Callers 1

generate_footerFunction · 0.85

Calls 2

outputFunction · 0.85
joinMethod · 0.80

Tested by

no test coverage detected