From 30eaa63ef57ba461d0ee7324b5a861f9c731649b Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Tue, 24 Sep 2024 10:58:05 -0700 Subject: [PATCH] Make add by core contract case insensitive (#1770) --- internal/dependencymanager/add.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/internal/dependencymanager/add.go b/internal/dependencymanager/add.go index d589d89dd..736a3b4c7 100644 --- a/internal/dependencymanager/add.go +++ b/internal/dependencymanager/add.go @@ -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 { @@ -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 } @@ -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 "" +}