8000 adding help for filters · vsoch/nushell-plugin-python@b64910f · GitHub
[go: up one dir, main page]

Skip to content

Commit b64910f

Browse files
committed
adding help for filters
Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>
1 parent 491ac31 commit b64910f

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Critical items to know are:
1616
Versions here coincide with releases on pypi.
1717

1818
## [master](https://github.com/vsoch/nushell-plugin-python)
19+
- allowing end-filter to return help response (0.0.15)
1920
- adding general function to get any primitive (0.0.14)
2021
- parsing of positional arguments (0.0.13)
2122
- support for sink pipes (0.0.12)

examples/len/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ the present working directory.
6161
```
6262

6363
As a helper, the plugin library automatically adds a `--help` function that also shows
64-
usage for each argument, if the creator provided it. Since this is a filter,
65-
you have to run it as a filter (to trigger the filter method) to see it:
64+
usage for each argument, if the creator provided it.
6665

6766
```bash
68-
> echo four | len --help
67+
> len --help
6968
len: Return the length of a string
69+
7070
--help show this usage
7171
```
7272

nushell/filter.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ def run(self, runFilter):
7878
self.logger.info("REQUEST %s" % line)
7979
self.logger.info("METHOD %s" % method)
8080

81-
# Store raw parameters for the plugin memory
82-
self.params = x.get('params', {})
81+
# Store raw parameters for the plugin memory, only if not end filter
82+
if method != "end_filter":
83+
self.params = x.get('params', {})
8384

8485
# Case 1: Nu is asking for the config to discover the plugin
8586
if method == "config":
@@ -95,21 +96,25 @@ def run(self, runFilter):
9596
self.logger.info("Begin Filter Args: %s" % self.args)
9697
self.print_good_response([])
9798

99+
# End filter can end the filter, OR call a custom sink function
98100
elif method == "end_filter":
99-
self.print_good_response([])
100-
break
101-
102-
# Run the filter, passing the unparsed params
103-
elif method == "filter":
104101

105102
# If the user wants help, return the help and break
106103
if "help" in self.args:
104+
105+
# We need to update so name_tag is tag (not logical I know)
106+
self.params['tag'] = self.params.get('name_tag', self.getTag())
107107
self.logger.info("User requested --help")
108108
self.print_string_response(self.get_help())
109-
110109
else:
111-
self.logger.info("RAW PARAMS: %s" % self.params)
112-
runFilter(self, self.args)
110+
self.print_good_response([])
111+
break
112+
113+
# Run the filter, passing the unparsed params
114+
elif method == "filter":
115+
116+
self.logger.info("RAW PARAMS: %s" % self.params)
117+
runFilter(self, self.args)
113118

114119
else:
115120
break

nushell/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
66
# with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
77

8-
__version__ = "0.0.14"
8+
__version__ = "0.0.15"
99
AUTHOR = 'Vanessa Sochat'
1010
AUTHOR_EMAIL = 'vsochat@stanford.edu'
1111
NAME = 'nushell'

0 commit comments

Comments
 (0)
0