-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dependabot/go_modules/github.com/sigstore/co…
…sign/v2-2.2.4
- Loading branch information
Showing
34 changed files
with
1,014 additions
and
73 deletions.
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
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
99 changes: 99 additions & 0 deletions
99
cmds/ocm/commands/ocmcmds/common/handlers/vershdlr/options.go
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,99 @@ | ||
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package vershdlr | ||
|
||
import ( | ||
"github.com/Masterminds/semver/v3" | ||
|
||
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/options/lookupoption" | ||
"github.com/open-component-model/ocm/cmds/ocm/commands/ocmcmds/common/options/versionconstraintsoption" | ||
"github.com/open-component-model/ocm/cmds/ocm/pkg/options" | ||
"github.com/open-component-model/ocm/pkg/contexts/ocm" | ||
"github.com/open-component-model/ocm/pkg/utils" | ||
) | ||
|
||
type Option interface { | ||
ApplyToHandler(handler *TypeHandler) | ||
} | ||
|
||
type Options []Option | ||
|
||
func (o Options) ApplyToHandler(handler *TypeHandler) { | ||
for _, e := range o { | ||
e.ApplyToHandler(handler) | ||
} | ||
} | ||
|
||
func OptionsFor(o options.OptionSetProvider) Options { | ||
var hopts []Option | ||
if constr := versionconstraintsoption.From(o); constr != nil { | ||
if len(constr.Constraints) > 0 { | ||
hopts = append(hopts, WithVersionConstraints(constr.Constraints)) | ||
} | ||
if constr.Latest { | ||
hopts = append(hopts, LatestOnly()) | ||
} | ||
} | ||
if lookup := lookupoption.From(o); lookup != nil { | ||
hopts = append(hopts, Resolver(lookup)) | ||
} | ||
return hopts | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
type constraints struct { | ||
constraints []*semver.Constraints | ||
} | ||
|
||
func (o constraints) ApplyToHandler(handler *TypeHandler) { | ||
handler.constraints = o.constraints | ||
} | ||
|
||
func WithVersionConstraints(c []*semver.Constraints) Option { | ||
return constraints{c} | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
type latestonly struct { | ||
flag bool | ||
} | ||
|
||
func (o latestonly) ApplyToHandler(handler *TypeHandler) { | ||
handler.latest = o.flag | ||
} | ||
|
||
func LatestOnly(b ...bool) Option { | ||
return latestonly{utils.OptionalDefaultedBool(true, b...)} | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
type resolver struct { | ||
resolver ocm.ComponentVersionResolver | ||
} | ||
|
||
func (o resolver) ApplyToHandler(handler *TypeHandler) { | ||
handler.resolver = o.resolver | ||
} | ||
|
||
func Resolver(r ocm.ComponentVersionResolver) Option { | ||
return resolver{r} | ||
} | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
type repository struct { | ||
repository ocm.Repository | ||
} | ||
|
||
func (o repository) ApplyToHandler(handler *TypeHandler) { | ||
handler.repobase = o.repository | ||
} | ||
|
||
func Repository(r ocm.Repository) Option { | ||
return repository{r} | ||
} |
26 changes: 26 additions & 0 deletions
26
cmds/ocm/commands/ocmcmds/common/handlers/vershdlr/sort.go
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,26 @@ | ||
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package vershdlr | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/open-component-model/ocm/cmds/ocm/pkg/processing" | ||
"github.com/open-component-model/ocm/pkg/semverutils" | ||
) | ||
|
||
func Compare(a, b interface{}) int { | ||
aa := a.(*Object) | ||
ab := b.(*Object) | ||
|
||
c := strings.Compare(aa.Component, ab.Component) | ||
if c != 0 { | ||
return c | ||
} | ||
return semverutils.Compare(aa.Version, ab.Version) | ||
} | ||
|
||
// Sort is a processing chain sorting original objects provided by type handler. | ||
var Sort = processing.Sort(Compare) |
Oops, something went wrong.