Skip to content

Commit 56dcf8b

Browse files
committed
Make sure README commands work (also disable type checking in plugin signature)
1 parent c114cd9 commit 56dcf8b

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ I'm still trying to figure out what is the most useful way of using this plugin.
1111
send feedback in [Discussions](https://github.com/realcundo/nu_plugin_dcm/discussions) or report problems in [Issues](https://github.com/realcundo/nu_plugin_dcm/issues).
1212

1313
## Usage
14-
`dcm` plugin reads its input from single values or from specific columns:
14+
`dcm` plugin reads its input from single values, from specific columns, or from list of values:
1515
- `dcm`: expects a string/filename or binary DICOM data
1616
- `dcm $column_name`: reads a string/filename or binary DICOM data from `$column`. This is
1717
equivalent to `get $column | dcm`.
18+
- `ls *.dcm | select name | dcm`: reads all files foun dby `ls` and returns a list of records.
19+
20+
See Examples for more details.
1821

1922
## Error handling
2023

2124
`dcm` plugin works in two modes:
22-
- default, when errors are reported as error rows,
23-
- in custom columns when `--error` option is used. This will report all errors in the specified column. Empty column value means no error.
25+
- default, when errors are reported as error rows, reported by nu,
26+
- when `--error` option is used, errors are reported in provided column. If there were no errors, the column value is empty.
2427

2528
## Known Limitations
2629

@@ -35,16 +38,15 @@ send feedback in [Discussions](https://github.com/realcundo/nu_plugin_dcm/discus
3538
Without `into binary`, `dcm` would see a list of strings, assuming it's a list of filenames.
3639

3740

38-
3941
## Examples
4042

41-
### Output DICOM file as a table
43+
### Output DICOM file as a record/table (list of records)
4244
```sh
4345
echo file.dcm | dcm # uses filename/string to specify which file to open
4446
open --raw file.dcm | dcm # pass binary data to `dcm`
4547
ls file.dcm | dcm name # use `name` column as the filename (equivalent of `ls file.dcm | select name | dcm`)
4648
echo file.dcm | wrap foo | dcm foo # use `foo` column as the filename
47-
open -r file.dcm | wrap foo | dcm foo # use `foo` column as binary data
49+
open -r file.dcm | into binary | wrap foo | dcm foo # use `foo` column as binary data (see Known Limitations for details)
4850
```
4951

5052
### Dump DICOM file as a JSON/YAML document
@@ -66,6 +68,7 @@ ls **/* |
6668
where type == file |
6769
dcm name -e error |
6870
where error == "" |
71+
select --ignore-errors SOPInstanceUID Modality |
6972
group-by Modality
7073
```
7174
@@ -93,7 +96,7 @@ ls **/* | where type == file |
9396
par-each { |it| {
9497
name: $it.name,
9598
size: $it.size,
96-
sha256: (open $it.name | hash sha256),
99+
sha256: (open --raw $it.name | hash sha256),
97100
dcm: ($it.name | dcm -e error)
98101
} } |
99102
select --ignore-errors name size sha256 dcm.Modality dcm.SOPInstanceUID dcm.error |
@@ -118,5 +121,5 @@ plugin add ~/.cargo/bin/nu_plugin_dcm
118121
To start using it without restarting nu, you can [import it](https://www.nushell.sh/book/plugins.html#importing-plugins):
119122
120123
```nu
121-
plugin use nu_plugin_dcm
124+
plugin use ~/.cargo/bin/nu_plugin_dcm
122125
```

src/plugin.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use nu_plugin::{EngineInterface, Plugin, PluginCommand};
1212
use nu_protocol::ast::CellPath;
1313
use nu_protocol::{
1414
Category, Example, LabeledError, PipelineData, Record, ShellError, Signature, Span,
15-
SyntaxShape, Type, Value,
15+
SyntaxShape, Value,
1616
};
1717

1818
#[derive(Default)]
@@ -45,6 +45,7 @@ impl PluginCommand for DcmPluginCommand {
4545
}
4646

4747
fn signature(&self) -> Signature {
48+
/*
4849
// Some example DICOM fields
4950
let dicom_record_fields = vec![
5051
("StudyInstanceUID".to_string(), Type::String),
@@ -64,8 +65,12 @@ impl PluginCommand for DcmPluginCommand {
6465
6566
let dicom_record_type = Type::Record(dicom_record_fields.into_boxed_slice());
6667
let file_record_type = Type::Record(file_record_fields.into_boxed_slice());
68+
*/
6769

6870
Signature::build(nu_plugin::PluginCommand::name(self))
71+
// TODO is it possible to specify all input/output types? The plugin is very
72+
// dynamic and e.g. `echo file.dcm | wrap foo | dcm foo` failed the type check...
73+
/*
6974
.input_output_types(
7075
vec![
7176
// String (filename) -> Record (DICOM data)
@@ -81,6 +86,7 @@ impl PluginCommand for DcmPluginCommand {
8186
// List of file records) -> List of Records (e.g. `ls *.dcm | dcm name`)
8287
(Type::List(Box::new(file_record_type.clone())), Type::List(Box::new(dicom_record_type))),
8388
])
89+
*/
8490
.named(
8591
"error",
8692
SyntaxShape::String,

0 commit comments

Comments
 (0)