Skip to content

Commit

Permalink
Missing content of #59 (#79)
Browse files Browse the repository at this point in the history
* Deleted a bunch of things which significantly sped up build time

* Apply suggestions from code review

Co-authored-by: Balazs Nadasdi <[email protected]>

* Updated error message and added expected type information

* Putting back the removed stuff

* Renaming funcs with underscore in it.

Co-authored-by: Gergely Brautigam <[email protected]>
Co-authored-by: Balazs Nadasdi <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2022
1 parent 25c80aa commit 3a483ae
Show file tree
Hide file tree
Showing 41 changed files with 315 additions and 632 deletions.
7 changes: 3 additions & 4 deletions cmds/ocm/commands/ocicmds/artefacts/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@ package artefacts
import (
"github.com/spf13/cobra"

"github.com/open-component-model/ocm/pkg/contexts/clictx"

"github.com/open-component-model/ocm/cmds/ocm/pkg/utils"

"github.com/open-component-model/ocm/cmds/ocm/commands/ocicmds/artefacts/describe"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocicmds/artefacts/download"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocicmds/artefacts/get"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocicmds/artefacts/transfer"
"github.com/open-component-model/ocm/cmds/ocm/commands/ocicmds/names"
"github.com/open-component-model/ocm/cmds/ocm/pkg/utils"
"github.com/open-component-model/ocm/pkg/contexts/clictx"
)

var Names = names.Artefacts
Expand All @@ -35,6 +33,7 @@ func NewCommand(ctx clictx.Context) *cobra.Command {
cmd := utils.MassageCommand(&cobra.Command{
Short: "Commands acting on OCI artefacts",
}, Names...)

cmd.AddCommand(get.NewCommand(ctx, get.Verb))
cmd.AddCommand(describe.NewCommand(ctx, describe.Verb))
cmd.AddCommand(transfer.NewCommand(ctx, transfer.Verb))
Expand Down
4 changes: 2 additions & 2 deletions cmds/ocm/commands/ocicmds/artefacts/describe/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ func (o *Command) Run() error {

/////////////////////////////////////////////////////////////////////////////

var outputs = output.NewOutputs(get_regular, output.Outputs{}).AddChainedManifestOutputs(infoChain)
var outputs = output.NewOutputs(getRegular, output.Outputs{}).AddChainedManifestOutputs(infoChain)

func get_regular(opts *output.Options) output.Output {
func getRegular(opts *output.Options) output.Output {
return output.NewProcessingFunctionOutput(opts.Context, processing.Chain(), outInfo)
}

Expand Down
4 changes: 2 additions & 2 deletions cmds/ocm/commands/ocicmds/artefacts/download/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ func (o *Command) Run() error {

////////////////////////////////////////////////////////////////////////////////

var outputs = output.NewOutputs(get_download)
var outputs = output.NewOutputs(getDownload)

func get_download(opts *output.Options) output.Output {
func getDownload(opts *output.Options) output.Output {
return &download{opts: opts}
}

Expand Down
24 changes: 12 additions & 12 deletions cmds/ocm/commands/ocicmds/artefacts/get/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,24 @@ func TableOutput(opts *output.Options, mapping processing.MappingFunction, wide
}
}

var outputs = output.NewOutputs(get_regular, output.Outputs{
"wide": get_wide,
"tree": get_tree,
var outputs = output.NewOutputs(getRegular, output.Outputs{
"wide": getWide,
"tree": getTree,
}).AddChainedManifestOutputs(OutputChainFunction())

func get_regular(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, map_get_regular_output)).New()
func getRegular(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, mapGetRegularOutput)).New()
}

func get_wide(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, map_get_wide_output, "MIMETYPE", "CONFIGTYPE")).New()
func getWide(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, mapGetWideOutput, "MIMETYPE", "CONFIGTYPE")).New()
}

func get_tree(opts *output.Options) output.Output {
return output.TreeOutput(TableOutput(opts, map_get_regular_output), "NESTING").New()
func getTree(opts *output.Options) output.Output {
return output.TreeOutput(TableOutput(opts, mapGetRegularOutput), "NESTING").New()
}

func map_get_regular_output(e interface{}) interface{} {
func mapGetRegularOutput(e interface{}) interface{} {
digest := "unknown"
p := e.(*artefacthdlr.Object)
blob, err := p.Artefact.Blob()
Expand All @@ -142,12 +142,12 @@ func map_get_regular_output(e interface{}) interface{} {
return []string{p.Spec.UniformRepositorySpec.String(), p.Spec.Repository, kind, tag, digest}
}

func map_get_wide_output(e interface{}) interface{} {
func mapGetWideOutput(e interface{}) interface{} {
p := e.(*artefacthdlr.Object)

config := "-"
if p.Artefact.IsManifest() {
config = p.Artefact.ManifestAccess().GetDescriptor().Config.MediaType
}
return output.Fields(map_get_regular_output(e), p.Artefact.GetDescriptor().MimeType(), config)
return output.Fields(mapGetRegularOutput(e), p.Artefact.GetDescriptor().MimeType(), config)
}
13 changes: 9 additions & 4 deletions cmds/ocm/commands/ocmcmds/common/inputs/inputtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,21 @@ func (t *inputTypeScheme) GetInputType(name string) InputType {

func (t *inputTypeScheme) RegisterByDecoder(name string, decoder runtime.TypedObjectDecoder) error {
if _, ok := decoder.(InputType); !ok {
errors.ErrInvalid("type", reflect.TypeOf(decoder).String())
return errors.ErrInvalid("type", reflect.TypeOf(decoder).String())
}
return t.Scheme.RegisterByDecoder(name, decoder)
}

func (t *inputTypeScheme) AddKnownTypes(scheme runtime.Scheme) {
func (t *inputTypeScheme) AddKnownTypes(scheme runtime.Scheme) error {
if _, ok := scheme.(InputTypeScheme); !ok {
panic("can only add RepositoryTypeSchemes")
return errors.ErrInvalid("type", reflect.TypeOf(scheme).String(), "expected", "InputTypeScheme")
}
t.Scheme.AddKnownTypes(scheme)

if err := t.Scheme.AddKnownTypes(scheme); err != nil {
return fmt.Errorf("failed to add known type in inputTypeScheme: %w", err)
}

return nil
}

func (t *inputTypeScheme) Register(name string, rtype InputType) {
Expand Down
24 changes: 12 additions & 12 deletions cmds/ocm/commands/ocmcmds/components/get/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,24 @@ func Format(opts *output.Options) processing.ProcessChain {

/////////////////////////////////////////////////////////////////////////////

var outputs = output.NewOutputs(get_regular, output.Outputs{
"wide": get_wide,
"tree": get_tree,
var outputs = output.NewOutputs(getRegular, output.Outputs{
"wide": getWide,
"tree": getTree,
}).AddChainedManifestOutputs(output.ComposeChain(closureoption.OutputChainFunction(comphdlr.ClosureExplode, comphdlr.Sort), Format))

func get_regular(opts *output.Options) output.Output {
return TableOutput(opts, map_get_regular_output).New()
func getRegular(opts *output.Options) output.Output {
return TableOutput(opts, mapGetRegularOutput).New()
}

func get_wide(opts *output.Options) output.Output {
return TableOutput(opts, map_get_wide_output, "REPOSITORY").New()
func getWide(opts *output.Options) output.Output {
return TableOutput(opts, mapGetWideOutput, "REPOSITORY").New()
}

func get_tree(opts *output.Options) output.Output {
return output.TreeOutput(TableOutput(opts, map_get_regular_output), "NESTING").New()
func getTree(opts *output.Options) output.Output {
return output.TreeOutput(TableOutput(opts, mapGetRegularOutput), "NESTING").New()
}

func map_get_regular_output(e interface{}) interface{} {
func mapGetRegularOutput(e interface{}) interface{} {
p := e.(*comphdlr.Object)

tag := "-"
Expand All @@ -169,7 +169,7 @@ func map_get_regular_output(e interface{}) interface{} {
return []string{p.Spec.Component, tag, string(p.ComponentVersion.GetDescriptor().Provider.Name)}
}

func map_get_wide_output(e interface{}) interface{} {
func mapGetWideOutput(e interface{}) interface{} {
p := e.(*comphdlr.Object)
return output.Fields(map_get_regular_output(e), p.Spec.UniformRepositorySpec.String())
return output.Fields(mapGetRegularOutput(e), p.Spec.UniformRepositorySpec.String())
}
24 changes: 12 additions & 12 deletions cmds/ocm/commands/ocmcmds/references/get/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,29 @@ func TableOutput(opts *output.Options, mapping processing.MappingFunction, wide
}
}

var outputs = output.NewOutputs(get_regular, output.Outputs{
"wide": get_wide,
"tree": get_tree,
var outputs = output.NewOutputs(getRegular, output.Outputs{
"wide": getWide,
"tree": getTree,
}).AddManifestOutputs()

func get_regular(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, map_get_regular_output)).New()
func getRegular(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, mapGetRegularOutput)).New()
}

func get_wide(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, map_get_wide_output, "IDENTITY")).New()
func getWide(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, mapGetWideOutput, "IDENTITY")).New()
}

func get_tree(opts *output.Options) output.Output {
return output.TreeOutput(TableOutput(opts, map_get_wide_output, "IDENTITY"), "COMPONENTVERSION").New()
func getTree(opts *output.Options) output.Output {
return output.TreeOutput(TableOutput(opts, mapGetWideOutput, "IDENTITY"), "COMPONENTVERSION").New()
}

func map_get_regular_output(e interface{}) interface{} {
func mapGetRegularOutput(e interface{}) interface{} {
r := common.Elem(e)
return output.Fields(r.GetName(), r.ComponentName, r.GetVersion())
}

func map_get_wide_output(e interface{}) interface{} {
func mapGetWideOutput(e interface{}) interface{} {
o := e.(*elemhdlr.Object)
return output.Fields(map_get_regular_output(e), o.Id.String())
return output.Fields(mapGetRegularOutput(e), o.Id.String())
}
2 changes: 1 addition & 1 deletion cmds/ocm/commands/ocmcmds/resources/add/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (ResourceSpecHandler) Set(v ocm.ComponentVersionAccess, r common.Resource,
},
Type: spec.Type,
Relation: spec.Relation,
SourceRef: compdescv2.Convert_SourceRefs_to(spec.SourceRef),
SourceRef: compdescv2.ConvertSourcerefsTo(spec.SourceRef),
}
return v.SetResource(meta, acc)
}
Expand Down
34 changes: 17 additions & 17 deletions cmds/ocm/commands/ocmcmds/resources/get/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,37 +101,37 @@ func TableOutput(opts *output.Options, mapping processing.MappingFunction, wide
}
}

var outputs = output.NewOutputs(get_regular, output.Outputs{
"wide": get_wide,
"tree": get_tree,
"treewide": get_treewide,
var outputs = output.NewOutputs(getRegular, output.Outputs{
"wide": getWide,
"tree": getTree,
"treewide": getTreewide,
}).AddManifestOutputs()

func get_regular(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, map_get_regular_output)).New()
func getRegular(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, mapGetRegularOutput)).New()
}

func get_wide(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, map_get_wide_output, elemhdlr.AccessOutput...)).New()
func getWide(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, mapGetWideOutput, elemhdlr.AccessOutput...)).New()
}

func get_tree(opts *output.Options) output.Output {
return output.TreeOutput(TableOutput(opts, map_get_regular_output), "COMPONENTVERSION").New()
func getTree(opts *output.Options) output.Output {
return output.TreeOutput(TableOutput(opts, mapGetRegularOutput), "COMPONENTVERSION").New()
}

func get_treewide(opts *output.Options) output.Output {
return output.TreeOutput(TableOutput(opts, map_get_treewide_output, "ACCESS"), "COMPONENTVERSION").New()
func getTreewide(opts *output.Options) output.Output {
return output.TreeOutput(TableOutput(opts, mapGetTreewideOutput, "ACCESS"), "COMPONENTVERSION").New()
}

func map_get_regular_output(e interface{}) interface{} {
func mapGetRegularOutput(e interface{}) interface{} {
r := common.Elem(e)
return append(elemhdlr.MapMetaOutput(e), r.Type, string(r.Relation))
}

func map_get_wide_output(e interface{}) interface{} {
return output.Fields(map_get_regular_output(e), elemhdlr.MapAccessOutput(common.Elem(e).Access))
func mapGetWideOutput(e interface{}) interface{} {
return output.Fields(mapGetRegularOutput(e), elemhdlr.MapAccessOutput(common.Elem(e).Access))
}

func map_get_treewide_output(e interface{}) interface{} {
return output.Fields(map_get_regular_output(e), common.Elem(e).Access.GetKind())
func mapGetTreewideOutput(e interface{}) interface{} {
return output.Fields(mapGetRegularOutput(e), common.Elem(e).Access.GetKind())
}
24 changes: 12 additions & 12 deletions cmds/ocm/commands/ocmcmds/sources/get/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,28 @@ func TableOutput(opts *output.Options, mapping processing.MappingFunction, wide
}
}

var outputs = output.NewOutputs(get_regular, output.Outputs{
"wide": get_wide,
"tree": get_tree,
var outputs = output.NewOutputs(getRegular, output.Outputs{
"wide": getWide,
"tree": getTree,
}).AddManifestOutputs()

func get_regular(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, map_get_regular_output)).New()
func getRegular(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, mapGetRegularOutput)).New()
}

func get_wide(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, map_get_wide_output, elemhdlr.AccessOutput...)).New()
func getWide(opts *output.Options) output.Output {
return closureoption.TableOutput(TableOutput(opts, mapGetWideOutput, elemhdlr.AccessOutput...)).New()
}

func get_tree(opts *output.Options) output.Output {
return output.TreeOutput(TableOutput(opts, map_get_regular_output), "COMPONENTVERSION").New()
func getTree(opts *output.Options) output.Output {
return output.TreeOutput(TableOutput(opts, mapGetRegularOutput), "COMPONENTVERSION").New()
}

func map_get_regular_output(e interface{}) interface{} {
func mapGetRegularOutput(e interface{}) interface{} {
r := common.Elem(e)
return append(elemhdlr.MapMetaOutput(e), r.Type)
}

func map_get_wide_output(e interface{}) interface{} {
return append(map_get_regular_output(e).([]string), elemhdlr.MapAccessOutput(common.Elem(e).Access)...)
func mapGetWideOutput(e interface{}) interface{} {
return append(mapGetRegularOutput(e).([]string), elemhdlr.MapAccessOutput(common.Elem(e).Access)...)
}
6 changes: 0 additions & 6 deletions cmds/ocm/pkg/data/indexed.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ func (this IndexedSliceAccess) Copy() IndexedSliceAccess {
return n
}

/*
func (this IndexedSliceAccess) entry_iterator() entry_iterator {
return (&_slice_entry_iterator{}).new(this)
}
*/

func NewSliceIterator(slice []interface{}) *IndexedIterator {
return NewIndexedIterator(IndexedSliceAccess(slice))
}
8 changes: 4 additions & 4 deletions cmds/ocm/pkg/output/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var _ = Describe("sort", func() {

It("sort a", func() {
slice := data.IndexedSliceAccess(values).Copy()
slice.Sort(compare_column(2))
slice.Sort(compareColumn(2))
Expect(slice).To(Equal(data.IndexedSliceAccess{
h1i2a1b3,
h2i2a1b3,
Expand All @@ -53,7 +53,7 @@ var _ = Describe("sort", func() {
})
It("sort b", func() {
slice := data.IndexedSliceAccess(values).Copy()
slice.Sort(compare_column(3))
slice.Sort(compareColumn(3))
Expect(slice).To(Equal(data.IndexedSliceAccess{
h1i2a2b1,
h2i2a2b1,
Expand All @@ -65,7 +65,7 @@ var _ = Describe("sort", func() {
})
It("sort fixed h a", func() {
slice := data.IndexedSliceAccess(values).Copy()
sortFixed(1, slice, compare_column(2))
sortFixed(1, slice, compareColumn(2))
Expect(slice).To(Equal(data.IndexedSliceAccess{
h1i2a1b3,
h1i2a2b1,
Expand All @@ -85,7 +85,7 @@ var _ = Describe("sort", func() {
}
slice = data.IndexedSliceAccess(values)
//slice.SortIndexed(compare_fixed_column(1, 2))
sortFixed(1, slice, compare_column(2))
sortFixed(1, slice, compareColumn(2))
Expect(slice).To(Equal(data.IndexedSliceAccess{
h1i2a1b3,
h2i2a1b3,
Expand Down
4 changes: 2 additions & 2 deletions cmds/ocm/pkg/output/tableoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (this *TableProcessingOutput) Out() error {
if n < this.opts.FixedColums {
return errors.Newf("field '%s' not possible", k)
}
cmp := compare_column(idxs[key])
cmp := compareColumn(idxs[key])
if this.opts.FixedColums > 0 {
sortFixed(this.opts.FixedColums, slice, cmp)
} else {
Expand All @@ -111,7 +111,7 @@ func (this *TableProcessingOutput) Out() error {
return nil
}

func compare_column(c int) CompareFunction {
func compareColumn(c int) CompareFunction {
return func(a interface{}, b interface{}) int {
aa := a.([]string)
ab := b.([]string)
Expand Down
Loading

0 comments on commit 3a483ae

Please sign in to comment.