file-tree issueshttps://git.fmrib.ox.ac.uk/ndcn0236/file-tree/-/issues2024-03-27T15:45:26+00:00https://git.fmrib.ox.ac.uk/ndcn0236/file-tree/-/issues/1Add command line interface2024-03-27T15:45:26+00:00Michiel Cottaarmichiel.cottaar@ndcn.ox.ac.ukAdd command line interfaceSupport the following features:
- getting individual filenames
- iterating over placeholders (e.g., subjects). Potentially, support globbing to determine subject values.
# Examples
Given a file-tree
```
sub-{subject}
T1w.nii.gz
T1w_...Support the following features:
- getting individual filenames
- iterating over placeholders (e.g., subjects). Potentially, support globbing to determine subject values.
# Examples
Given a file-tree
```
sub-{subject}
T1w.nii.gz
T1w_bet.nii.gz
```
I want the following to work:
```sh
for FT_subject in A B ; do
bet $(. file-tree get T1w) $(. file-tree get T1w_bet)
done
```
This should in effect call:
```sh
bet ./sub-A/T1w.nii.gz ./sub-A/T1w_bet.nii.gz
bet ./sub-B/T1w.nii.gz ./sub-B/T1w_bet.nii.gz
```
We should also support iteration.
```sh
call_bet() {
bet $(. file-tree get T1w) $(. file-tree get T1w_bet)
}
. file-tree iter T1w call_bet --glob
```
This will call `bet` for any `sub-*/T1w.nii.gz` file.
# Implementation
This will require `file-tree` to be a shell script, which is sourced from the pipeline script. It will internally call a python script called `file-tree-helper`, which will actually read and interpret the file-tree.
## Getter
```sh
ENVSTRING=$(file-tree-helper ENVSTRING)
echo $(eval $ENVSTRING file-tree-helper get $@)
```
1. `file-tree-helper ENVSTRING` will return a string like: "`FT_subject=$FT_subject FT_session=$FT_session`" for a file-tree containing 2 placeholders (`subject` and `session`).
2. `file-tree-helper get` will return the full filename using the environmental variables `$FT_subject` and `$FT_session`.
## Iter
Implementation for iter:
```bash
for SETENV in $(file-tree-helper SETENV $1); do
eval $SETENV $2
done
```
`file-tree-helper SETENV <template>` will return a string like: "`FT_subject=A FT_session=01`" presuming that the `<template>` depends on subject and session.