Skip to content

Commit 4fe1246

Browse files
authored
Esacape shell args to allow paths with spaces. (#31)
1 parent 6f19a0c commit 4fe1246

4 files changed

Lines changed: 138 additions & 8 deletions

File tree

R/cmd.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ louper_create_cloupe <- function(
2929
h5path <- normalizePath(path.expand(h5path))
3030
loupe_path <- suppressWarnings(normalizePath(path.expand(loupe_path)))
3131

32-
input_flag <- sprintf("--input=%s", h5path)
33-
output_flag <- sprintf("--output=%s", loupe_path)
32+
input_flag <- sprintf("--input=%s", shQuote(h5path))
33+
output_flag <- sprintf("--output=%s", shQuote(loupe_path))
3434
args <- c("create", input_flag, output_flag)
3535

3636
if (file.exists(loupe_path) && !force) {

tests/testthat/mock_louper

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,59 @@
11
#!/usr/bin/env bash
22

33
echo "-----------RUNNING MOCK LOUPER EXECUTABLE--------------"
4-
echo Arguments passed to the script: "$@"
4+
5+
# Default values
6+
force=false
7+
8+
# Check if the correct number of arguments is provided
9+
if [ "$#" -lt 3 ] || [ "$#" -gt 4 ]; then
10+
echo "Usage: $0 create --input=SOME_PATH --output=SOME_PATH [--force]"
11+
exit 1
12+
fi
13+
14+
# Check if the first argument is "create"
15+
if [ "$1" != "create" ]; then
16+
echo "Error: First argument must be 'create'"
17+
exit 1
18+
fi
19+
20+
# shift args
21+
shift
22+
23+
# Parse and validate the input and output options
24+
input=""
25+
output=""
26+
27+
while [ "$#" -gt 0 ]; do
28+
case "$1" in
29+
--input=*)
30+
input="${1#*=}"
31+
;;
32+
--output=*)
33+
output="${1#*=}"
34+
;;
35+
--force)
36+
force=true
37+
;;
38+
*)
39+
echo "Error: Unknown option '$1'"
40+
exit 1
41+
;;
42+
esac
43+
shift
44+
done
45+
46+
# Check if input and output paths are provided
47+
if [ -z "$input" ] || [ -z "$output" ]; then
48+
echo "Error: Both --input and --output options must be provided"
49+
exit 1
50+
fi
51+
52+
# Additional processing with the arguments can be added here
53+
54+
echo "Action: create"
55+
echo "Input path: $input"
56+
echo "Output path: $output"
57+
echo "Force: $force"
58+
559
echo "-------------------------------------------------------"

tests/testthat/mock_louper.bat

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,66 @@
11
@echo off
22

33
echo "-----------RUNNING MOCK LOUPER.BAT EXECUTABLE--------------"
4-
echo Arguments passed to the script: %*
4+
5+
setlocal enabledelayedexpansion
6+
7+
set "force=false"
8+
9+
REM Check if the correct number of arguments is provided
10+
if "%~1" neq "create" (
11+
echo Error: First argument must be 'create'
12+
goto :eof
13+
)
14+
shift
15+
16+
REM Parse and validate the input and output options
17+
set "input="
18+
set "output="
19+
20+
:parse_args
21+
if "%~1" equ "" goto :check_paths
22+
23+
if /i "%~1" equ "--input" (
24+
set "input=%~2"
25+
shift
26+
shift
27+
goto :parse_args
28+
)
29+
30+
if /i "%~1" equ "--output" (
31+
set "output=%~2"
32+
shift
33+
shift
34+
goto :parse_args
35+
)
36+
37+
if /i "%~1" equ "--force" (
38+
set "force=true"
39+
shift
40+
goto :parse_args
41+
)
42+
43+
echo Error: Unknown option '%1'
44+
goto :eof
45+
46+
:check_paths
47+
REM Check if input and output paths are provided
48+
if not defined input (
49+
echo Error: --input option must be provided
50+
goto :eof
51+
)
52+
53+
if not defined output (
54+
echo Error: --output option must be provided
55+
goto :eof
56+
)
57+
58+
REM Additional processing with the arguments can be added here
59+
60+
echo Action: create
61+
echo Input path: !input!
62+
echo Output path: !output!
63+
echo Force: !force!
64+
65+
:end
566
echo "-----------------------------------------------------------"

tests/testthat/test-lib.R

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
test_that("can run create_loupe_from_seurat", {
1+
create_default_seurat_obj <- function() {
22
barcode_count <- 3
33

44
count_mat <- create_count_mat(100, barcode_count, valid_barcodes = TRUE)
@@ -9,23 +9,38 @@ test_that("can run create_loupe_from_seurat", {
99
obj[["proj1"]] <- proj
1010
obj[["cluster1"]] <- cluster
1111

12+
obj
13+
}
14+
15+
test_that("can run create_loupe_from_seurat", {
1216
# create eula lock file to avoid interactive setup
1317
eula_create()
1418

19+
obj <- create_default_seurat_obj()
1520
x <- create_loupe_from_seurat(obj, executable_path = get_executable_path())
1621
expect(x, "create_loupe_from_seurat returns TRUE")
1722
})
1823

24+
test_that("can run create_loupe with spaces in output_name", {
25+
# create eula lock file to avoid interactive setup
26+
eula_create()
27+
28+
obj <- create_default_seurat_obj()
29+
x <- create_loupe_from_seurat(obj, executable_path = get_executable_path(), output_name = "name with spaces")
30+
expect(x, "create_loupe_from_seurat returns TRUE")
31+
})
32+
1933
test_that("can run create_loupe", {
34+
# create eula lock file to avoid interactive setup
35+
eula_create()
36+
2037
barcode_count <- 5
2138
count_mat <- create_count_mat(100, barcode_count, valid_barcodes = TRUE)
2239
proj <- create_dense_mat(barcode_count, 2)
2340
clusters <- list("f1" = factor(c("a", "c", "b", "a", "b"), levels=c("a", "b", "c"), ordered=TRUE))
2441
projections <- list("p1" = proj)
2542

26-
# create eula lock file to avoid interactive setup
27-
eula_create()
28-
2943
x <- create_loupe(count_mat, clusters = clusters, projections = projections, executable_path = get_executable_path())
3044
expect(x, "create_loupe returns TRUE")
3145
})
46+

0 commit comments

Comments
 (0)