forked from mirrors/nixpkgs
lib.strings: isSimpleCoercibleString -> isStringLike
This commit is contained in:
parent
5b8de3d9d8
commit
872a24ebbc
2 changed files with 10 additions and 10 deletions
|
@ -395,7 +395,7 @@ rec {
|
||||||
*/
|
*/
|
||||||
toShellVar = name: value:
|
toShellVar = name: value:
|
||||||
lib.throwIfNot (isValidPosixName name) "toShellVar: ${name} is not a valid shell variable name" (
|
lib.throwIfNot (isValidPosixName name) "toShellVar: ${name} is not a valid shell variable name" (
|
||||||
if isAttrs value && ! isSimpleCoercibleToString value then
|
if isAttrs value && ! isStringLike value then
|
||||||
"declare -A ${name}=(${
|
"declare -A ${name}=(${
|
||||||
concatStringsSep " " (lib.mapAttrsToList (n: v:
|
concatStringsSep " " (lib.mapAttrsToList (n: v:
|
||||||
"[${escapeShellArg n}]=${escapeShellArg v}"
|
"[${escapeShellArg n}]=${escapeShellArg v}"
|
||||||
|
@ -800,7 +800,7 @@ rec {
|
||||||
|
|
||||||
/* Soft-deprecated name for isMoreCoercibleToString */
|
/* Soft-deprecated name for isMoreCoercibleToString */
|
||||||
isCoercibleToString = lib.warnIf (lib.isInOldestRelease 2305)
|
isCoercibleToString = lib.warnIf (lib.isInOldestRelease 2305)
|
||||||
"lib.strings.isCoercibleToString is deprecated in favor of either isSimpleCoercibleToString or isMoreCoercibleString. Only use the latter if it needs to return true for null, numbers, booleans and list of similarly coercibles."
|
"lib.strings.isCoercibleToString is deprecated in favor of either isStringLike or isMoreCoercibleString. Only use the latter if it needs to return true for null, numbers, booleans and list of similarly coercibles."
|
||||||
isMoreCoercibleToString;
|
isMoreCoercibleToString;
|
||||||
|
|
||||||
/* Check whether a list or other value can be passed to toString.
|
/* Check whether a list or other value can be passed to toString.
|
||||||
|
@ -814,13 +814,13 @@ rec {
|
||||||
x ? outPath ||
|
x ? outPath ||
|
||||||
x ? __toString;
|
x ? __toString;
|
||||||
|
|
||||||
/* Check whether a value can be coerced to a string,
|
/* Check whether a value can be coerced to a string.
|
||||||
The value must be a string, path, or attribute set.
|
The value must be a string, path, or attribute set.
|
||||||
|
|
||||||
This follows Nix's internal coerceToString(coerceMore = false) logic,
|
String-like values can be used without explicit conversion in
|
||||||
except for external types, for which we return false.
|
string interpolations and in most functions that expect a string.
|
||||||
*/
|
*/
|
||||||
isSimpleCoercibleToString = x:
|
isStringLike = x:
|
||||||
elem (typeOf x) [ "path" "string" ] ||
|
elem (typeOf x) [ "path" "string" ] ||
|
||||||
x ? outPath ||
|
x ? outPath ||
|
||||||
x ? __toString;
|
x ? __toString;
|
||||||
|
@ -838,7 +838,7 @@ rec {
|
||||||
=> false
|
=> false
|
||||||
*/
|
*/
|
||||||
isStorePath = x:
|
isStorePath = x:
|
||||||
if isSimpleCoercibleToString x then
|
if isStringLike x then
|
||||||
let str = toString x; in
|
let str = toString x; in
|
||||||
substring 0 1 str == "/"
|
substring 0 1 str == "/"
|
||||||
&& dirOf str == storeDir
|
&& dirOf str == storeDir
|
||||||
|
|
|
@ -54,7 +54,7 @@ let
|
||||||
concatStringsSep
|
concatStringsSep
|
||||||
escapeNixString
|
escapeNixString
|
||||||
hasInfix
|
hasInfix
|
||||||
isSimpleCoercibleToString
|
isStringLike
|
||||||
;
|
;
|
||||||
inherit (lib.trivial)
|
inherit (lib.trivial)
|
||||||
boolToString
|
boolToString
|
||||||
|
@ -227,7 +227,7 @@ rec {
|
||||||
merge = loc: defs:
|
merge = loc: defs:
|
||||||
let
|
let
|
||||||
getType = value:
|
getType = value:
|
||||||
if isAttrs value && isSimpleCoercibleToString value
|
if isAttrs value && isStringLike value
|
||||||
then "stringCoercibleSet"
|
then "stringCoercibleSet"
|
||||||
else builtins.typeOf value;
|
else builtins.typeOf value;
|
||||||
|
|
||||||
|
@ -479,7 +479,7 @@ rec {
|
||||||
path = mkOptionType {
|
path = mkOptionType {
|
||||||
name = "path";
|
name = "path";
|
||||||
descriptionClass = "noun";
|
descriptionClass = "noun";
|
||||||
check = x: isSimpleCoercibleToString x && builtins.substring 0 1 (toString x) == "/";
|
check = x: isStringLike x && builtins.substring 0 1 (toString x) == "/";
|
||||||
merge = mergeEqualOption;
|
merge = mergeEqualOption;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue