-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This introduces the builtin semver type and the ability to use semver for comparisons. Semvers are created via the `semver` keyword, which takes a string as an argument: ```coffee semver('1.2.3') ``` Semvers can be compared with each other and with strings: ```coffee semver('1.2.3') < semver('2.3') semver('1.10') >= '1.2' ``` Signed-off-by: Dominik Richter <[email protected]>
- Loading branch information
Showing
8 changed files
with
192 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package llx | ||
|
||
import ( | ||
"github.com/Masterminds/semver" | ||
"go.mondoo.com/cnquery/v9/types" | ||
) | ||
|
||
func semverLT(left interface{}, right interface{}) *RawData { | ||
leftv, err := semver.NewVersion(left.(string)) | ||
if err != nil { | ||
return BoolData(left.(string) < right.(string)) | ||
} | ||
rightv, err := semver.NewVersion(right.(string)) | ||
if err != nil { | ||
return BoolData(left.(string) < right.(string)) | ||
} | ||
return BoolData(leftv.LessThan(rightv)) | ||
} | ||
|
||
func semverGT(left interface{}, right interface{}) *RawData { | ||
leftv, err := semver.NewVersion(left.(string)) | ||
if err != nil { | ||
return BoolData(left.(string) > right.(string)) | ||
} | ||
rightv, err := semver.NewVersion(right.(string)) | ||
if err != nil { | ||
return BoolData(left.(string) > right.(string)) | ||
} | ||
return BoolData(leftv.GreaterThan(rightv)) | ||
} | ||
|
||
func semverLTE(left interface{}, right interface{}) *RawData { | ||
leftv, err := semver.NewVersion(left.(string)) | ||
if err != nil { | ||
return BoolData(left.(string) <= right.(string)) | ||
} | ||
rightv, err := semver.NewVersion(right.(string)) | ||
if err != nil { | ||
return BoolData(left.(string) <= right.(string)) | ||
} | ||
return BoolData(!leftv.GreaterThan(rightv)) | ||
} | ||
|
||
func semverGTE(left interface{}, right interface{}) *RawData { | ||
leftv, err := semver.NewVersion(left.(string)) | ||
if err != nil { | ||
return BoolData(left.(string) >= right.(string)) | ||
} | ||
rightv, err := semver.NewVersion(right.(string)) | ||
if err != nil { | ||
return BoolData(left.(string) >= right.(string)) | ||
} | ||
return BoolData(!leftv.LessThan(rightv)) | ||
} | ||
|
||
func semverCmpSemver(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) { | ||
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, func(left, right interface{}) *RawData { | ||
return BoolData(left.(string) == right.(string)) | ||
}) | ||
} | ||
|
||
func semverNotSemver(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) { | ||
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, func(left, right interface{}) *RawData { | ||
return BoolData(left.(string) != right.(string)) | ||
}) | ||
} | ||
|
||
func semverLTsemver(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) { | ||
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, semverLT) | ||
} | ||
|
||
func semverGTsemver(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) { | ||
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, semverGT) | ||
} | ||
|
||
func semverLTEsemver(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) { | ||
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, semverLTE) | ||
} | ||
|
||
func semverGTEsemver(e *blockExecutor, bind *RawData, chunk *Chunk, ref uint64) (*RawData, uint64, error) { | ||
return nonNilDataOpV2(e, bind, chunk, ref, types.Bool, semverGTE) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters