Last active
May 31, 2022 12:35
-
-
Save cygnetix/769b4b90bdfce78145240ea7235db4f1 to your computer and use it in GitHub Desktop.
A vlang adaptation of the nushell python example plugin https://github.com/nushell/nushell/blob/main/crates/nu_plugin_python/plugin.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import json | |
| struct Signature { | |
| name string | |
| usage string | |
| extra_usage string | |
| required_positional []string | |
| optional_positional []string | |
| named []string | |
| search_terms []string | |
| is_filter bool | |
| creates_scope bool | |
| category string | |
| } | |
| const example_response = '{ | |
| "Value": { | |
| "List": { | |
| "vals": [ | |
| { | |
| "Record": { | |
| "cols": ["one", "two", "three"], | |
| "vals": [ | |
| { | |
| "Int": { | |
| "val": 8, | |
| "span": {"start": 0, "end": 1} | |
| } | |
| }, | |
| { | |
| "Int": { | |
| "val": 2, | |
| "span": {"start": 0, "end": 1} | |
| } | |
| }, | |
| { | |
| "Int": { | |
| "val": 0, | |
| "span": {"start": 0, "end": 1} | |
| } | |
| } | |
| ], | |
| "span": {"start": 0, "end": 1} | |
| } | |
| }, | |
| { | |
| "Record": { | |
| "cols": ["one", "two", "three"], | |
| "vals": [ | |
| { | |
| "Int": { | |
| "val": 0, | |
| "span": {"start": 0, "end": 1} | |
| } | |
| }, | |
| { | |
| "Int": { | |
| "val": 1, | |
| "span": {"start": 0, "end": 1} | |
| } | |
| }, | |
| { | |
| "Int": { | |
| "val": 5, | |
| "span": {"start": 0, "end": 1} | |
| } | |
| } | |
| ], | |
| "span": {"start": 0, "end": 1} | |
| } | |
| } | |
| ], | |
| "span": {"start": 0, "end": 1} | |
| } | |
| } | |
| }' | |
| fn main() { | |
| mut file := os.open_file('output.log', 'a') or { panic(err) } | |
| defer { | |
| file.close() | |
| } | |
| plugin_call := os.get_line() | |
| if plugin_call == '"Signature"' { | |
| s := Signature{ | |
| name: 'vplugin' | |
| usage: 'Example Nushell plugin for the V programming language' | |
| extra_usage: '' | |
| required_positional: []string{} | |
| optional_positional: []string{} | |
| named: []string{} | |
| search_terms: []string{} | |
| is_filter: false | |
| creates_scope: false | |
| category: 'Experimental' | |
| } | |
| print('{"Signature": [${json.encode(s)}]}') | |
| } else if plugin_call.starts_with('{"CallInfo"') { | |
| print(example_response) | |
| } else { | |
| print('{ | |
| "Error": { | |
| "label": "ERROR from plugin", | |
| "msg": "error message pointing to call head span", | |
| "span": {"start": 0, "end": 1}, | |
| } | |
| }') | |
| } | |
| file.write_string('$plugin_call\n') or { panic(err) } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.