Skip to content

Commit 18219d3

Browse files
committed
lib: change default flagSeparator from " " to null
The " " default was confusing: it didn't join with a space but produced separate argv entries. Change the default to null which clearly means "separate argv entries", while " " now actually joins with a space (single arg). This makes the semantics consistent with "=". null → ["--flag" "value"] (separate args, default) "=" → ["--flag=value"] (joined) " " → ["--flag value"] (joined with space)
1 parent fc6d9b7 commit 18219d3

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

checks/flags-empty-list.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ let
1313
"--empty" = [ ];
1414
"--output" = "file.txt";
1515
};
16-
flagSeparator = " ";
1716
};
1817

1918
in

checks/flags-false.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ let
1515
"--empty" = [ ];
1616
"--output" = "file.txt";
1717
};
18-
flagSeparator = " ";
1918
};
2019

2120
in

checks/flags-list.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ let
1515
];
1616
"--verbose" = true;
1717
};
18-
flagSeparator = " ";
1918
};
2019

2120
wrappedWithEqualsSep = self.lib.wrapPackage {

checks/flags-space-separator.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ let
1111
"--greeting" = "hi";
1212
"--verbose" = true;
1313
};
14-
flagSeparator = " ";
1514
};
1615

1716
in

lib/default.nix

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
let
33
/**
44
flagToArgs {
5-
flagSeparator: str,
5+
flagSeparator: null | str,
66
name: str,
77
flag: bool | str | [ str | [ str ] ]
8-
} -> [ str
8+
} -> [ str ]
9+
10+
flagSeparator = null -> ["--flag" "value"] (separate argv entries, default)
11+
flagSeparator = "=" -> ["--flag=value"] (joined with separator)
12+
flagSeparator = " " -> ["--flag value"] (joined with space, single arg)
913
*/
1014
flagToArgs =
1115
{
12-
flagSeparator ? " ",
16+
flagSeparator ? null,
1317
name,
1418
flag,
1519
}:
@@ -18,7 +22,7 @@ let
1822
else if flag == true then
1923
[ name ]
2024
else if builtins.isString flag then
21-
if flagSeparator == " " then
25+
if flagSeparator == null then
2226
[
2327
name
2428
flag
@@ -30,7 +34,7 @@ let
3034
lib.concatMap (
3135
v:
3236
if builtins.isString v then
33-
if flagSeparator == " " then
37+
if flagSeparator == null then
3438
[
3539
name
3640
v
@@ -379,7 +383,7 @@ let
379383
- `runtimeInputs`: List of packages to add to PATH (optional)
380384
- `env`: Attribute set of environment variables to export (optional)
381385
- `flags`: Attribute set of command-line flags to add (optional)
382-
- `flagSeparator`: Separator between flag names and values when generating args from flags (optional, defaults to " ")
386+
- `flagSeparator`: Separator between flag names and values when generating args from flags (optional, defaults to null for separate argv entries, use "=" for joined)
383387
- `args`: List of command-line arguments like argv in execve (optional, auto-generated from flags if not provided)
384388
- `preHook`: Shell script to run before executing the command (optional)
385389
- `postHook`: Shell script to run after executing the command, removes the `exec` call. use with care (optional)
@@ -445,8 +449,8 @@ let
445449
runtimeInputs ? [ ],
446450
env ? { },
447451
flags ? { },
448-
flagSeparator ? " ",
449-
# " " for "--flag value" or "=" for "--flag=value"
452+
flagSeparator ? null,
453+
# null for "--flag" "value" (separate args) or "=" for "--flag=value"
450454
args ? generateArgsFromFlags flags flagSeparator,
451455
preHook ? "",
452456
postHook ? "",

lib/modules/flags.nix

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ in
5656
};
5757

5858
options.flagSeparator = lib.mkOption {
59-
type = lib.types.str;
60-
default = " ";
59+
type = lib.types.nullOr lib.types.str;
60+
default = null;
6161
description = ''
6262
Separator between flag names and values when generating args from flags.
63-
" " for "--flag value" or "=" for "--flag=value"
63+
null (default) for separate argv entries: "--flag" "value"
64+
"=" for joined: "--flag=value"
6465
'';
6566
};
6667

0 commit comments

Comments
 (0)