Skip to content

Commit

Permalink
Make add by core contract case insensitive (#1770)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Sep 24, 2024
1 parent 605907c commit 30eaa63
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions internal/dependencymanager/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ package dependencymanager

import (
"fmt"
"strings"

"github.com/onflow/flow-cli/internal/util"
"github.com/onflow/flow-go/fvm/systemcontracts"

"github.com/spf13/cobra"

"github.com/onflow/flowkit/v2"
"github.com/onflow/flowkit/v2/output"

flowGo "github.com/onflow/flow-go/model/flow"

"github.com/onflow/flow-cli/internal/command"
"github.com/onflow/flow-cli/internal/util"
)

type addFlagsCollection struct {
Expand Down Expand Up @@ -77,8 +81,9 @@ func add(
}

// First check if the dependency is a core contract.
if isCoreContract(dep) {
if err := installer.AddByCoreContractName(dep, addFlags.name); err != nil {
coreContractName := findCoreContractCaseInsensitive(dep)
if coreContractName != "" {
if err := installer.AddByCoreContractName(coreContractName, addFlags.name); err != nil {
logger.Error(fmt.Sprintf("Error: %v", err))
return nil, err
}
Expand All @@ -93,3 +98,12 @@ func add(

return nil, nil
}

func findCoreContractCaseInsensitive(name string) string {
for _, contract := range systemcontracts.SystemContractsForChain(flowGo.Mainnet).All() {
if strings.EqualFold(contract.Name, name) {
return contract.Name
}
}
return ""
}

0 comments on commit 30eaa63

Please sign in to comment.