remove functions
@@ -20,6 +20,7 @@ package config
import (
"errors"
+ "fmt"
"github.com/onflow/cadence"
@@ -240,6 +241,21 @@ func (c *Contracts) AddOrUpdate(name string, contract Contract) {
*c = append(*c, contract)
}
+func (c *Contracts) Remove(name string) error {
+ contract := c.GetByName(name)
+ if contract == nil {
+ return fmt.Errorf("contract named %s does not exist in configuration", name)
+ }
+
+ for i, contract := range *c {
+ if contract.Name == name {
+ *c = append((*c)[0:i], (*c)[i+1:]...) // remove item
+ }
+ }
+
+ return nil
+}
+
// AccountByName get account by name
func (a *Accounts) GetByName(name string) *Account {
for _, account := range *a {
@@ -263,6 +279,22 @@ func (a *Accounts) AddOrUpdate(name string, account Account) {
*a = append(*a, account)
}
+// Remove remove account by name
+func (a *Accounts) Remove(name string) error {
+ account := a.GetByName(name)
+ if account == nil {
+ return fmt.Errorf("account named %s does not exist in configuration", name)
+ }
+
+ for i, account := range *a {
+ if account.Name == name {
+ *a = append((*a)[0:i], (*a)[i+1:]...) // remove item
+ }
+ }
+
+ return nil
+}
+
// GetByNetwork get all deployments by network
func (d *Deployments) GetByNetwork(network string) Deployments {
var deployments Deployments
@@ -301,6 +333,26 @@ func (d *Deployments) AddOrUpdate(deployment Deploy) {
*d = append(*d, deployment)
}
+// Remove removes deployment by account and network
+func (d *Deployments) Remove(account string, network string) error {
+ deployment := d.GetByAccountAndNetwork(account, network)
+ if deployment == nil {
+ return fmt.Errorf(
+ "deployment for account %s on network %s does not exist in configuration",
+ account,
+ network,
+ )
+ }
+
+ for i, deployment := range *d {
+ if deployment.Network == network && deployment.Account == account {
+ *d = append((*d)[0:i], (*d)[i+1:]...) // remove item
+ }
+ }
+
+ return nil
+}
+
// GetByName get network by name
func (n *Networks) GetByName(name string) *Network {
for _, network := range *n {
@@ -324,6 +376,21 @@ func (n *Networks) AddOrUpdate(name string, network Network) {
*n = append(*n, network)
}
+func (n *Networks) Remove(name string) error {
+ network := n.GetByName(name)
+ if network == nil {
+ return fmt.Errorf("network named %s does not exist in configuration", name)
+ }
+
+ for i, network := range *n {
+ if network.Name == name {
+ *n = append((*n)[0:i], (*n)[i+1:]...) // remove item
+ }
+ }
+
+ return nil
+}
+
// Default gets default emulator
func (e *Emulators) Default() *Emulator {
for _, emulator := range *e {
