config

package
v0.20.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddAccountCommand = &command.Command{
	Cmd: &cobra.Command{
		Use:     "account",
		Short:   "Add account to configuration",
		Example: "flow config add account",
		Args:    cobra.NoArgs,
	},
	Flags: &addAccountFlags,
	Run: func(
		cmd *cobra.Command,
		args []string,
		globalFlags command.GlobalFlags,
		services *services.Services,
	) (command.Result, error) {
		p, err := project.Load(globalFlags.ConfigPaths)
		if err != nil {
			return nil, fmt.Errorf("configuration does not exists")
		}

		accountData, flagsProvided, err := flagsToAccountData(addAccountFlags)
		if err != nil {
			return nil, err
		}

		if !flagsProvided {
			accountData = output.NewAccountPrompt()
		}

		account, err := config.StringToAccount(
			accountData["name"],
			accountData["address"],
			accountData["keyIndex"],
			accountData["sigAlgo"],
			accountData["hashAlgo"],
			accountData["key"],
		)
		if err != nil {
			return nil, err
		}

		acc, err := project.AccountFromConfig(*account)
		if err != nil {
			return nil, err
		}

		p.AddOrUpdateAccount(acc)

		err = p.SaveDefault()
		if err != nil {
			return nil, err
		}

		return &ConfigResult{
			result: fmt.Sprintf("Account %s added to the configuration", accountData["name"]),
		}, nil

	},
}
View Source
var AddCmd = &cobra.Command{
	Use:              "add <account|contract|deployment|network>",
	Short:            "Add resource to configuration",
	Example:          "flow config add account",
	Args:             cobra.ExactArgs(1),
	TraverseChildren: true,
}
View Source
var AddContractCommand = &command.Command{
	Cmd: &cobra.Command{
		Use:     "contract",
		Short:   "Add contract to configuration",
		Example: "flow config add contract",
		Args:    cobra.NoArgs,
	},
	Flags: &addContractFlags,
	Run: func(
		cmd *cobra.Command,
		args []string,
		globalFlags command.GlobalFlags,
		services *services.Services,
	) (command.Result, error) {
		p, err := project.Load(globalFlags.ConfigPaths)
		if err != nil {
			return nil, fmt.Errorf("configuration does not exists")
		}

		contractData, flagsProvided, err := flagsToContractData(addContractFlags)
		if err != nil {
			return nil, err
		}

		if !flagsProvided {
			contractData = output.NewContractPrompt()
		}

		contracts := config.StringToContracts(
			contractData["name"],
			contractData["source"],
			contractData["emulator"],
			contractData["testnet"],
		)

		for _, contract := range contracts {
			p.Config().Contracts.AddOrUpdate(contract.Name, contract)
		}

		err = p.SaveDefault()
		if err != nil {
			return nil, err
		}

		return &ConfigResult{
			result: fmt.Sprintf("Contract %s added to the configuration", contractData["name"]),
		}, nil
	},
}
View Source
var AddDeploymentCommand = &command.Command{
	Cmd: &cobra.Command{
		Use:     "deployment",
		Short:   "Add deployment to configuration",
		Example: "flow config add deployment",
		Args:    cobra.NoArgs,
	},
	Flags: &addDeploymentFlags,
	Run: func(
		cmd *cobra.Command,
		args []string,
		globalFlags command.GlobalFlags,
		services *services.Services,
	) (command.Result, error) {
		p, err := project.Load(globalFlags.ConfigPaths)
		if err != nil {
			return nil, fmt.Errorf("configuration does not exists")
		}
		conf := p.Config()

		deployData, flagsProvided, err := flagsToDeploymentData(addDeploymentFlags)
		if err != nil {
			return nil, err
		}

		if !flagsProvided {
			deployData = output.NewDeploymentPrompt(conf.Networks, conf.Accounts, conf.Contracts)
		}

		deployment := config.StringToDeployment(
			deployData["network"].(string),
			deployData["account"].(string),
			deployData["contracts"].([]string),
		)

		conf.Deployments.AddOrUpdate(deployment)

		err = p.SaveDefault()
		if err != nil {
			return nil, err
		}

		return &ConfigResult{
			result: "Deployment added to the configuration.\nYou can deploy using 'flow project deploy' command",
		}, nil
	},
}
View Source
var AddNetworkCommand = &command.Command{
	Cmd: &cobra.Command{
		Use:     "network",
		Short:   "Add network to configuration",
		Example: "flow config add network",
		Args:    cobra.NoArgs,
	},
	Flags: &addNetworkFlags,
	Run: func(
		cmd *cobra.Command,
		args []string,
		globalFlags command.GlobalFlags,
		services *services.Services,
	) (command.Result, error) {
		p, err := project.Load(globalFlags.ConfigPaths)
		if err != nil {
			return nil, fmt.Errorf("configuration does not exists")
		}

		networkData, flagsProvided, err := flagsToNetworkData(addNetworkFlags)
		if err != nil {
			return nil, err
		}

		if !flagsProvided {
			networkData = output.NewNetworkPrompt()
		}

		network := config.StringToNetwork(networkData["name"], networkData["host"])
		p.Config().Networks.AddOrUpdate(network.Name, network)

		err = p.SaveDefault()
		if err != nil {
			return nil, err
		}

		return &ConfigResult{
			result: fmt.Sprintf("Network %s added to the configuration", networkData["name"]),
		}, nil
	},
}
View Source
var Cmd = &cobra.Command{
	Use:              "config",
	Short:            "Utilities to manage configuration",
	TraverseChildren: true,
}
View Source
var CompletionCmd = &cobra.Command{
	Use:                   "setup-completions [powershell]",
	Short:                 "Setup command autocompletion",
	DisableFlagsInUseLine: true,
	ValidArgs:             []string{"powershell"},
	Args:                  cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		shell := ""
		if len(args) == 1 {
			shell = args[0]
		}

		if shell == "powershell" {
			_ = cmd.Root().GenPowerShellCompletion(os.Stdout)
		} else {
			shell, shellOS := output.AutocompletionPrompt()

			if shell == "bash" && shellOS == "MacOS" {
				_ = cmd.Root().GenBashCompletionFile("/usr/local/etc/bash_completion.d/flow")

				fmt.Printf("Flow command completions installed in: /usr/local/etc/bash_completion.d/flow\n")
				fmt.Printf("You will need to start a new shell for this setup to take effect.\n\n")
			} else if shell == "bash" && shellOS == "Linux" {
				_ = cmd.Root().GenBashCompletionFile("/etc/bash_completion.d/flow")

				fmt.Printf("Flow command completions installed in: /etc/bash_completion.d/flow\n")
				fmt.Printf("You will need to start a new shell for this setup to take effect.\n\n")
			} else if shell == "zsh" {
				c := exec.Command("zsh", "-c ", `echo -n ${fpath[1]}`)
				path, _ := c.Output()
				_ = cmd.Root().GenZshCompletionFile(fmt.Sprintf("%s/_flow", path))

				fmt.Printf("Flow command completions installed in: '%s/_flow'\n", path)
				fmt.Printf("You will need to start a new shell for this setup to take effect.\n\n")
			}
		}
	},
}
View Source
var InitCommand = &command.Command{
	Cmd: &cobra.Command{
		Use:   "init",
		Short: "Initialize a new configuration",
	},
	Flags: &initFlag,
	Run: func(
		cmd *cobra.Command,
		args []string,
		globalFlags command.GlobalFlags,
		services *services.Services,
	) (command.Result, error) {
		proj, err := services.Project.Init(
			initFlag.Reset,
			initFlag.Global,
			initFlag.ServiceKeySigAlgo,
			initFlag.ServiceKeyHashAlgo,
			initFlag.ServicePrivateKey,
		)
		if err != nil {
			return nil, err
		}

		return &InitResult{proj}, nil
	},
}
View Source
var RemoveAccountCommand = &command.Command{
	Cmd: &cobra.Command{
		Use:     "account <name>",
		Short:   "Remove account from configuration",
		Example: "flow config remove account Foo",
		Args:    cobra.MaximumNArgs(1),
	},
	Flags: &removeAccountFlags,
	Run: func(
		cmd *cobra.Command,
		args []string,
		globalFlags command.GlobalFlags,
		services *services.Services,
	) (command.Result, error) {
		p, err := project.Load(globalFlags.ConfigPaths)
		if err != nil {
			return nil, fmt.Errorf("configuration does not exists")
		}
		conf := p.Config()

		name := ""
		if len(args) == 1 {
			name = args[0]
		} else {
			name = output.RemoveAccountPrompt(conf.Accounts)
		}

		err = p.RemoveAccount(name)
		if err != nil {
			return nil, err
		}

		err = p.SaveDefault()
		if err != nil {
			return nil, err
		}

		return &ConfigResult{
			result: "account removed",
		}, nil
	},
}
View Source
var RemoveCmd = &cobra.Command{
	Use:              "remove <account|contract|deployment|network>",
	Short:            "Remove resource from configuration",
	Example:          "flow config remove account",
	Args:             cobra.ExactArgs(1),
	TraverseChildren: true,
}
View Source
var RemoveContractCommand = &command.Command{
	Cmd: &cobra.Command{
		Use:     "contract <name>",
		Short:   "Remove contract from configuration",
		Example: "flow config remove contract Foo",
		Args:    cobra.MaximumNArgs(1),
	},
	Flags: &removeContractFlags,
	Run: func(
		cmd *cobra.Command,
		args []string,
		globalFlags command.GlobalFlags,
		services *services.Services,
	) (command.Result, error) {
		p, err := project.Load(globalFlags.ConfigPaths)
		if err != nil {
			return nil, fmt.Errorf("configuration does not exists")
		}

		name := ""
		if len(args) == 1 {
			name = args[0]
		} else {
			name = output.RemoveContractPrompt(p.Config().Contracts)
		}

		err = p.Config().Contracts.Remove(name)
		if err != nil {
			return nil, err
		}

		err = p.SaveDefault()
		if err != nil {
			return nil, err
		}

		return &ConfigResult{
			result: "contract removed",
		}, nil
	},
}
View Source
var RemoveDeploymentCommand = &command.Command{
	Cmd: &cobra.Command{
		Use:     "deployment <account> <network>",
		Short:   "Remove deployment from configuration",
		Example: "flow config remove deployment Foo testnet",
		Args:    cobra.MaximumNArgs(2),
	},
	Flags: &removeDeploymentFlags,
	Run: func(
		cmd *cobra.Command,
		args []string,
		globalFlags command.GlobalFlags,
		services *services.Services,
	) (command.Result, error) {
		p, err := project.Load(globalFlags.ConfigPaths)
		if err != nil {
			return nil, fmt.Errorf("configuration does not exists")
		}

		account := ""
		network := ""
		if len(args) == 2 {
			account = args[0]
			network = args[1]
		} else {
			account, network = output.RemoveDeploymentPrompt(p.Config().Deployments)
		}

		err = p.Config().Deployments.Remove(account, network)
		if err != nil {
			return nil, err
		}

		err = p.SaveDefault()
		if err != nil {
			return nil, err
		}

		return &ConfigResult{
			result: "deployment removed",
		}, nil
	},
}
View Source
var RemoveNetworkCommand = &command.Command{
	Cmd: &cobra.Command{
		Use:     "network <name>",
		Short:   "Remove network from configuration",
		Example: "flow config remove network Foo",
		Args:    cobra.MaximumNArgs(1),
	},
	Flags: &removeNetworkFlags,
	Run: func(
		cmd *cobra.Command,
		args []string,
		globalFlags command.GlobalFlags,
		services *services.Services,
	) (command.Result, error) {
		p, err := project.Load(globalFlags.ConfigPaths)
		if err != nil {
			return nil, fmt.Errorf("configuration does not exists")
		}

		name := ""
		if len(args) == 1 {
			name = args[0]
		} else {
			name = output.RemoveNetworkPrompt(p.Config().Networks)
		}

		err = p.Config().Networks.Remove(name)
		if err != nil {
			return nil, err
		}

		err = p.SaveDefault()
		if err != nil {
			return nil, err
		}

		return &ConfigResult{
			result: "network removed",
		}, nil
	},
}

Functions

This section is empty.

Types

type ConfigResult added in v0.19.0

type ConfigResult struct {
	// contains filtered or unexported fields
}

ConfigResult result from configuration

func (*ConfigResult) JSON added in v0.19.0

func (r *ConfigResult) JSON() interface{}

JSON convert result to JSON

func (*ConfigResult) Oneliner added in v0.19.0

func (r *ConfigResult) Oneliner() string

Oneliner show result as one liner grep friendly

func (*ConfigResult) String added in v0.19.0

func (r *ConfigResult) String() string

type FlagsInit

type FlagsInit struct {
	ServicePrivateKey  string `flag:"service-private-key" info:"Service account private key"`
	ServiceKeySigAlgo  string `default:"ECDSA_P256" flag:"service-sig-algo" info:"Service account key signature algorithm"`
	ServiceKeyHashAlgo string `default:"SHA3_256" flag:"service-hash-algo" info:"Service account key hash algorithm"`
	Reset              bool   `default:"false" flag:"reset" info:"Reset configuration file"`
	Global             bool   `default:"false" flag:"global" info:"Initialize global user configuration"`
}

type InitResult

type InitResult struct {
	*project.Project
}

InitResult result structure

func (*InitResult) JSON

func (r *InitResult) JSON() interface{}

JSON convert result to JSON

func (*InitResult) Oneliner

func (r *InitResult) Oneliner() string

Oneliner show result as one liner grep friendly

func (*InitResult) String

func (r *InitResult) String() string

String convert result to string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL