query
On this page

tryCPEPatchVersionInUpdateWithVendor

lib.meta.tryCPEPatchVersionInUpdateWithVendor

Docs pulled from | This Revision | 9 minutes ago


Alternate version of lib.meta.cpePatchVersionInUpdateWithVendor. If cpePatchVersionInUpdateWithVendor succeeds, returns an attribute set with success set to true and value set to the result. Otherwise, success is set to false and error is set to the string representation of the error.

Inputs

vendor

package's vendor

version

package's version

Type

tryCPEPatchVersionInUpdateWithVendor :: string -> string -> AttrSet

Examples

lib.meta.tryCPEPatchVersionInUpdateWithVendor usage example

lib.meta.tryCPEPatchVersionInUpdateWithVendor "gnu" "1.2.3"
=> {
  success = true;
  value = {
    vendor = "gnu";
    version = "1.2";
    update = "3";
  };
}

lib.meta.cpePatchVersionInUpdateWithVendor error example

lib.meta.tryCPEPatchVersionInUpdateWithVendor "gnu" "5.3p0"
=> {
  success = false;
  error = "version 5.3p0 doesn't match regex `([0-9]+\\.[0-9]+)\\.([0-9]+)`";
}

Noogle detected

Implementation

The following is the current implementation of this function.

tryCPEPatchVersionInUpdateWithVendor =
    vendor: version:
    let
      regex = "([0-9]+\\.[0-9]+)\\.([0-9]+)";
      # we have to call toString here in case version is an attrset with __toString attribute
      versionMatch = builtins.match regex (toString version);
    in
    if versionMatch == null then
      {
        success = false;
        error = "version ${version} doesn't match regex `${regex}`";
      }
    else
      {
        success = true;
        value = {
          inherit vendor;
          version = elemAt versionMatch 0;
          update = elemAt versionMatch 1;
        };
      };