Skip to content

Commit

Permalink
Set default index when receipt is parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskim06 committed Mar 4, 2020
1 parent 60c4d60 commit 22764a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
3 changes: 3 additions & 0 deletions internal/index/indexscanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ func ReadPlugin(f io.ReadCloser) (index.Plugin, error) {
func ReadReceiptFromFile(path string) (index.Receipt, error) {
var receipt index.Receipt
err := readFromFile(path, &receipt)
if receipt.Status.Source.Name == "" {
receipt.Status.Source.Name = constants.DefaultIndexName
}
return receipt, err
}

Expand Down
16 changes: 1 addition & 15 deletions internal/installation/receipt/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ import (
"sigs.k8s.io/yaml"

"sigs.k8s.io/krew/internal/index/indexscanner"
"sigs.k8s.io/krew/pkg/constants"
"sigs.k8s.io/krew/pkg/index"
)

// Store saves the given plugin receipt at the destination.
// The caller has to ensure that the destination directory exists.
func Store(plugin index.Plugin, dest string) error {
receipt := receiptFromPlugin(plugin, constants.DefaultIndexName)
yamlBytes, err := yaml.Marshal(receipt)
yamlBytes, err := yaml.Marshal(plugin)
if err != nil {
return errors.Wrapf(err, "convert to yaml")
}
Expand All @@ -43,15 +41,3 @@ func Store(plugin index.Plugin, dest string) error {
func Load(path string) (index.Receipt, error) {
return indexscanner.ReadReceiptFromFile(path)
}

// receiptFromPlugin creates a receipt object using the Plugin and index name.
func receiptFromPlugin(plugin index.Plugin, indexName string) index.Receipt {
return index.Receipt{
Plugin: plugin,
Status: index.ReceiptStatus{
Source: index.SourceIndex{
Name: indexName,
},
},
}
}

0 comments on commit 22764a6

Please sign in to comment.