PR feedback changes
This commit is contained in:
parent
88a8ad9da6
commit
dcf7ea84e0
|
@ -7,7 +7,7 @@
|
||||||
# language without adding any extra dependencies to our tests.
|
# language without adding any extra dependencies to our tests.
|
||||||
|
|
||||||
const NUSHELL_VERSION = "0.96.2"
|
const NUSHELL_VERSION = "0.96.2"
|
||||||
const PLUGIN_VERSION = "0.1.0" # bump if you change commands!
|
const PLUGIN_VERSION = "0.1.1" # bump if you change commands!
|
||||||
|
|
||||||
def main [--stdio] {
|
def main [--stdio] {
|
||||||
if ($stdio) {
|
if ($stdio) {
|
||||||
|
@ -133,7 +133,7 @@ def process_call [
|
||||||
|
|
||||||
# Create a Value of type List that will be encoded and sent to Nushell
|
# Create a Value of type List that will be encoded and sent to Nushell
|
||||||
let value = {
|
let value = {
|
||||||
Value: { value: {
|
Value: [{
|
||||||
List: {
|
List: {
|
||||||
vals: (0..9 | each { |x|
|
vals: (0..9 | each { |x|
|
||||||
{
|
{
|
||||||
|
@ -157,8 +157,7 @@ def process_call [
|
||||||
}),
|
}),
|
||||||
span: $span
|
span: $span
|
||||||
}
|
}
|
||||||
}
|
}, null]
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
write_response $id { PipelineData: $value }
|
write_response $id { PipelineData: $value }
|
||||||
|
|
|
@ -28,7 +28,7 @@ import json
|
||||||
|
|
||||||
|
|
||||||
NUSHELL_VERSION = "0.96.2"
|
NUSHELL_VERSION = "0.96.2"
|
||||||
PLUGIN_VERSION = "0.1.0" # bump if you change commands!
|
PLUGIN_VERSION = "0.1.1" # bump if you change commands!
|
||||||
|
|
||||||
|
|
||||||
def signatures():
|
def signatures():
|
||||||
|
@ -125,31 +125,31 @@ def process_call(id, plugin_call):
|
||||||
span = plugin_call["call"]["head"]
|
span = plugin_call["call"]["head"]
|
||||||
|
|
||||||
# Creates a Value of type List that will be encoded and sent to Nushell
|
# Creates a Value of type List that will be encoded and sent to Nushell
|
||||||
def f(x, y): return {
|
def f(x, y):
|
||||||
"Int": {
|
return {"Int": {"val": x * y, "span": span}}
|
||||||
"val": x * y,
|
|
||||||
"span": span
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
value = {
|
value = {
|
||||||
"Value": {
|
"Value": [
|
||||||
"List": {
|
{
|
||||||
"vals": [
|
"List": {
|
||||||
{
|
"vals": [
|
||||||
"Record": {
|
{
|
||||||
"val": {
|
"Record": {
|
||||||
"one": f(x, 0),
|
"val": {
|
||||||
"two": f(x, 1),
|
"one": f(x, 0),
|
||||||
"three": f(x, 2),
|
"two": f(x, 1),
|
||||||
},
|
"three": f(x, 2),
|
||||||
"span": span
|
},
|
||||||
|
"span": span,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} for x in range(0, 10)
|
for x in range(0, 10)
|
||||||
],
|
],
|
||||||
"span": span
|
"span": span,
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
None,
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
write_response(id, {"PipelineData": value})
|
write_response(id, {"PipelineData": value})
|
||||||
|
@ -172,7 +172,7 @@ def tell_nushell_hello():
|
||||||
"Hello": {
|
"Hello": {
|
||||||
"protocol": "nu-plugin", # always this value
|
"protocol": "nu-plugin", # always this value
|
||||||
"version": NUSHELL_VERSION,
|
"version": NUSHELL_VERSION,
|
||||||
"features": []
|
"features": [],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sys.stdout.write(json.dumps(hello))
|
sys.stdout.write(json.dumps(hello))
|
||||||
|
@ -200,22 +200,26 @@ def write_error(id, text, span=None):
|
||||||
Use this error format to send errors to nushell in response to a plugin call. The ID of the
|
Use this error format to send errors to nushell in response to a plugin call. The ID of the
|
||||||
plugin call is required.
|
plugin call is required.
|
||||||
"""
|
"""
|
||||||
error = {
|
error = (
|
||||||
"Error": {
|
{
|
||||||
"msg": "ERROR from plugin",
|
"Error": {
|
||||||
"labels": [
|
"msg": "ERROR from plugin",
|
||||||
{
|
"labels": [
|
||||||
"text": text,
|
{
|
||||||
"span": span,
|
"text": text,
|
||||||
}
|
"span": span,
|
||||||
],
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} if span is not None else {
|
if span is not None
|
||||||
"Error": {
|
else {
|
||||||
"msg": "ERROR from plugin",
|
"Error": {
|
||||||
"help": text,
|
"msg": "ERROR from plugin",
|
||||||
|
"help": text,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
write_response(id, error)
|
write_response(id, error)
|
||||||
|
|
||||||
|
|
||||||
|
@ -230,11 +234,14 @@ def handle_input(input):
|
||||||
elif "Call" in input:
|
elif "Call" in input:
|
||||||
[id, plugin_call] = input["Call"]
|
[id, plugin_call] = input["Call"]
|
||||||
if plugin_call == "Metadata":
|
if plugin_call == "Metadata":
|
||||||
write_response(id, {
|
write_response(
|
||||||
"Metadata": {
|
id,
|
||||||
"version": PLUGIN_VERSION,
|
{
|
||||||
}
|
"Metadata": {
|
||||||
})
|
"version": PLUGIN_VERSION,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
elif plugin_call == "Signature":
|
elif plugin_call == "Signature":
|
||||||
write_response(id, signatures())
|
write_response(id, signatures())
|
||||||
elif "Run" in plugin_call:
|
elif "Run" in plugin_call:
|
||||||
|
@ -258,4 +265,4 @@ if __name__ == "__main__":
|
||||||
if len(sys.argv) == 2 and sys.argv[1] == "--stdio":
|
if len(sys.argv) == 2 and sys.argv[1] == "--stdio":
|
||||||
plugin()
|
plugin()
|
||||||
else:
|
else:
|
||||||
print("Run me from inside nushell!")
|
print("Run me from inside nushell!")
|
||||||
|
|
|
@ -178,7 +178,7 @@ fn handle_message(
|
||||||
id,
|
id,
|
||||||
{
|
{
|
||||||
"PipelineData": {
|
"PipelineData": {
|
||||||
"Value": {"value": return_value}
|
"Value": [return_value, None::<Value>]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user