-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnu_plugin_hello
More file actions
executable file
·48 lines (33 loc) · 1.4 KB
/
nu_plugin_hello
File metadata and controls
executable file
·48 lines (33 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
# Copyright (C) 2017-2019 Vanessa Sochat.
# This Source Code Form is subject to the terms of the
# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
from nushell.sink import SinkPlugin
# Your sink function will be called by the sink Plugin, and should
# accept the plugin and the dictionary of params
def sink(plugin, params):
'''sink will be executed by the calling SinkPlugin when method is "sink"
'''
message = "Hello"
excited = params.get("excited", False)
name = params.get("name", "")
# If we have a name, add to message
message = "%s %s" %(message, name)
# Are we excited?
if excited:
message += "!"
print(message)
# The main function is where you create your plugin and run it.
def main():
# Initialize a new plugin
plugin = SinkPlugin(name="hello",
usage="A friendly plugin")
# Add named arguments (notice we check for in params in sink function)
# add_named_argument(name, argType, syntaxShape=None, usage=None)
plugin.add_named_argument("excited", "Switch", usage="add an exclamation point!")
plugin.add_named_argument("name", "Optional", "String", usage="say hello to...")
# Run the plugin by passing your sink function
plugin.run(sink)
if __name__ == '__main__':
main()