func (c *Config) EditPlain(envName, configPlain string) (string, error) {
	result, err := editor.Edit(configPlain, "edit_proxy*.yaml")
	if err != nil {
		return "", err
	}
	var tmpConfig Config
	if err := yaml.Unmarshal([]byte(result), &tmpConfig); err != nil {
		return result, err
	}
	if l := len(tmpConfig.Proxies); l != 1 {
		return result, fmt.Errorf("need one proxy confugration, find %d", l)
	}
	newProxy, err := tmpConfig.FindProxy(envName)
	if err != nil {
		newProxy = tmpConfig.Proxies[0]
	}
	if err := newProxy.Validate(); err != nil {
		return result, fmt.Errorf("failed to validate %v", err)
	}
	for i, proxy := range c.Proxies {
		if proxy.Env == envName {
			c.Proxies[i] = newProxy
		}
	}
	return result, c.save()
}
EditPlain edit specific proxy configuration by config plain
package config
import (
	"encoding/json"
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"github.com/adzimzf/tpot/editor"
	"github.com/manifoldco/promptui"
	"gopkg.in/yaml.v2"
)
var (
	Dir = os.Getenv("HOME") + "/.tpot/"
	ErrValidateConfig = errors.New("config is invalid")
)
const configFileName = "config.yaml"
type Config struct {
	Editor string `json:"editor"  yaml:"editor"`
	Proxies []*Proxy `json:"proxies" yaml:"proxies"`
}
func NewConfig() (*Config, error) {
	if err := addConfigDirExist(); err != nil {
		return nil, err
	}
	config, err := getConfig()
	if errors.Is(err, os.ErrNotExist) {
		config = &Config{
			Editor: editor.DefaultEditor,
		}
		if err := config.save(); err != nil {
			return nil, err
		}
	} else if err != nil {
		return nil, err
	}
	return config, nil
}
func getConfig() (*Config, error) {
	bytes, err := ioutil.ReadFile(Dir + configFileName)
	if errors.Is(err, os.ErrNotExist) {
		bytes, err := ioutil.ReadFile(Dir + "config.json")
		if err != nil {
			return nil, err
		}
		var config Config
		err = json.Unmarshal(bytes, &config)
		if err != nil {
			return nil, err
		}
		if err = config.save(); err != nil {
			return nil, err
		}
		return &config, nil
	}
	if err != nil {
		return nil, err
	}
	var config Config
	err = yaml.Unmarshal(bytes, &config)
	if err != nil {
		return nil, err
	}
	return &config, nil
}
func (c *Config) Add() (string, error) {
	return c.AddPlain(proxyTemplate)
}
func (c *Config) AddPlain(configPlain string) (string, error) {
	result, err := editor.Edit(configPlain, "add_proxy*.yaml")
	if err != nil {
		return "", err
	}
	if result == proxyTemplate {
		return "", fmt.Errorf("there's no proxy was added")
	}
	var tmpConfig Config
	if err := yaml.Unmarshal([]byte(result), &tmpConfig); err != nil {
		return result, err
	}
	if l := len(tmpConfig.Proxies); l != 1 {
		return result, fmt.Errorf("need one proxy confugration, find %d", l)
	}
	if err := tmpConfig.Proxies[0].Validate(); err != nil {
		return result, fmt.Errorf("failed to validate %v", err)
	}
	_, err = c.FindProxy(tmpConfig.Proxies[0].Env)
	if err != ErrEnvNotFound {
		return result, fmt.Errorf("environment %s is already exist", tmpConfig.Proxies[0].Env)
	}
	c.Proxies = append(c.Proxies, tmpConfig.Proxies[0])
	return result, c.save()
}
func (c *Config) save() error {
	bytes, err := yaml.Marshal(&c)
	if err != nil {
		return err
	}
	return ioutil.WriteFile(Dir+configFileName, bytes, permission)
}
func (c *Config) Edit(envName string) (string, error) {
	proxy, err := c.FindProxy(envName)
	if err != nil {
		return "", fmt.Errorf("proxy %s is not found", envName)
	}
	tmpConfig := Config{
		Proxies: []*Proxy{
			proxy,
		},
	}
	marshal, err := yaml.Marshal(tmpConfig)
	if err != nil {
		return "", fmt.Errorf("proxy confugration is invalid")
	}
	return c.EditPlain(envName, string(marshal))
}