Skip to content

Commit 66cf501

Browse files
authored
CI-830 - Allow specifying files to upload on non-interactive CLI (#170)
* allow specifying files on upload * refresh readme examples * update data-type example
1 parent cab11d5 commit 66cf501

File tree

5 files changed

+47
-17
lines changed

5 files changed

+47
-17
lines changed

README.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ If you need to change your credentials after this point, and you've opted to sav
2929
## Command Line Usage
3030

3131
#### Downloading a dataset:
32+
3233
```bash
3334
Usage: cirro download [OPTIONS]
3435

@@ -37,29 +38,41 @@ Usage: cirro download [OPTIONS]
3738
Options:
3839
--project TEXT Name or ID of the project
3940
--dataset TEXT ID of the dataset
40-
--file... TEXT Name and relative path of the file (optional)
41+
--file TEXT Relative path of the file(s) to download (optional, can be used multiple times)
4142
--data-directory TEXT Directory to store the files
4243
-i, --interactive Gather arguments interactively
4344
--help Show this message and exit.
4445
```
4546

47+
```bash
48+
$ cirro download --project "Test Project 1" --dataset "test" --data-directory "~/download"
49+
```
50+
4651
#### Uploading a dataset:
52+
4753
```bash
4854
Usage: cirro upload [OPTIONS]
4955

5056
Upload and create a dataset
5157

5258
Options:
53-
--name TEXT Name of the dataset
54-
--description TEXT Description of the dataset (optional)
55-
--project TEXT Name or ID of the project
56-
--data-type TEXT Name or ID of the data type (ingest process)
57-
--data-directory TEXT Directory you wish to upload
58-
-i, --interactive Gather arguments interactively
59-
--help Show this message and exit.
59+
--name TEXT Name of the dataset
60+
--description TEXT Description of the dataset (optional)
61+
--project TEXT Name or ID of the project
62+
--data-type, --process TEXT Name or ID of the data type (--process is deprecated)
63+
--data-directory TEXT Directory you wish to upload
64+
--file TEXT Relative path of the file(s) to upload (optional, can be used multiple times)
65+
-i, --interactive Gather arguments interactively
66+
--include-hidden Include hidden files in the upload (e.g., files starting with .)
67+
--help Show this message and exit.
68+
```
69+
70+
```bash
71+
$ cirro upload --project "Test Project 1" --name "test" --file "sample1.fastq.gz" --file "sample2.fastq.gz" --data-directory "~/data" --data-type "Paired DNAseq (FASTQ)"
6072
```
6173

6274
#### Uploading a reference
75+
6376
```bash
6477
Usage: cirro upload-reference [OPTIONS]
6578

@@ -69,10 +82,9 @@ Options:
6982
--name TEXT Name of the reference
7083
--reference-type TEXT Type of the reference (e.g., Reference Genome (FASTA))
7184
--project TEXT Name or ID of the project
72-
--reference-file TEXT Location of reference file to upload (can specify multiple files)
85+
--reference-file TEXT Location of reference file(s) to upload (can be used multiple times)
7386
-i, --interactive Gather arguments interactively
7487
--help Show this message and exit.
75-
7688
```
7789

7890
#### Listing datasets:

cirro/cli/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def list_datasets(**kwargs):
3838
@click.option('--dataset',
3939
help='ID of the dataset')
4040
@click.option('--file',
41-
help='Name and relative path of the file (optional)',
41+
help='Relative path of the file(s) to download (optional, can be used multiple times)',
4242
default=[],
4343
multiple=True)
4444
@click.option('--data-directory',
@@ -63,6 +63,10 @@ def download(**kwargs):
6363
help='Name or ID of the data type (--process is deprecated)')
6464
@click.option('--data-directory',
6565
help='Directory you wish to upload')
66+
@click.option('--file',
67+
help='Relative path of the file(s) to upload (optional, can be used multiple times)',
68+
default=[],
69+
multiple=True)
6670
@click.option('-i', '--interactive',
6771
help='Gather arguments interactively',
6872
is_flag=True, default=False)
@@ -82,7 +86,7 @@ def upload(**kwargs):
8286
@click.option('--project',
8387
help='Name or ID of the project')
8488
@click.option('--reference-file',
85-
help='Location of reference file to upload (can specify multiple files)',
89+
help='Location of reference file(s) to upload (can be used multiple times)',
8690
multiple=True)
8791
@click.option('-i', '--interactive',
8892
help='Gather arguments interactively',

cirro/cli/controller.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from cirro.cli.interactive.list_dataset_args import gather_list_arguments
1717
from cirro.cli.interactive.upload_args import gather_upload_arguments
1818
from cirro.cli.interactive.upload_reference_args import gather_reference_upload_arguments
19-
from cirro.cli.interactive.utils import get_id_from_name, get_item_from_name_or_id, InputError
19+
from cirro.cli.interactive.utils import get_id_from_name, get_item_from_name_or_id, InputError, validate_files
2020
from cirro.cli.models import ListArguments, UploadArguments, DownloadArguments, CreatePipelineConfigArguments, \
2121
UploadReferenceArguments
2222
from cirro.config import UserConfig, save_user_config, load_user_config
@@ -84,7 +84,14 @@ def run_ingest(input_params: UploadArguments, interactive=False):
8484
input_params['project'] = get_id_from_name(projects, input_params['project'])
8585
input_params['data_type'] = get_id_from_name(processes, input_params['data_type'])
8686
directory = input_params['data_directory']
87-
files = get_files_in_directory(directory)
87+
all_files = get_files_in_directory(directory)
88+
if input_params['file']:
89+
files = input_params['file']
90+
validate_files(all_files, files, directory)
91+
92+
# Default to all files if file param is not provided
93+
else:
94+
files = all_files
8895

8996
if len(files) == 0:
9097
raise InputError("No files to upload")

cirro/cli/interactive/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from pathlib import Path
22
from typing import List, Union, Callable, TypeVar, Optional
33

4-
from prompt_toolkit.validation import Validator, ValidationError
54
import questionary
5+
from prompt_toolkit.validation import Validator, ValidationError
66
from questionary import prompt
77

88

@@ -108,3 +108,9 @@ def get_item_from_name_or_id(items: List[T], name_or_id: str) -> Optional[T]:
108108
if matched:
109109
return matched
110110
return next((p for p in items if p.name == name_or_id), None)
111+
112+
113+
def validate_files(all_files: List[str], files: List[str], directory: str):
114+
for file in files:
115+
if file not in all_files:
116+
raise InputError(f"File '{file}' not found in directory '{directory}'")

cirro/cli/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
from typing import TypedDict, List, Optional
1+
from typing import TypedDict, Optional
22

33

44
class DownloadArguments(TypedDict):
55
project: str
66
dataset: str
77
data_directory: str
88
interactive: bool
9+
file: Optional[list[str]]
910

1011

1112
class UploadArguments(TypedDict):
@@ -16,7 +17,7 @@ class UploadArguments(TypedDict):
1617
data_directory: str
1718
include_hidden: bool
1819
interactive: bool
19-
files: Optional[List[str]]
20+
file: Optional[list[str]]
2021

2122

2223
class ListArguments(TypedDict):

0 commit comments

Comments
 (0)