代码拉取完成,页面将自动刷新
package config
import (
"fmt"
"regexp"
"github.com/fatih/color"
"github.com/xalanq/cf-tool/client"
"github.com/xalanq/cf-tool/util"
)
// SetGenAfterParse set it yes or no
func (c *Config) SetGenAfterParse() (err error) {
c.GenAfterParse = util.YesOrNo(`Run "cf gen" after "cf parse" (y/n)? `)
return c.save()
}
func formatHost(host string) (string, error) {
reg := regexp.MustCompile(`https?://[\w\-]+(\.[\w\-]+)+/?`)
if !reg.MatchString(host) {
return "", fmt.Errorf(`Invalid host "%v"`, host)
}
for host[len(host)-1:] == "/" {
host = host[:len(host)-1]
}
return host, nil
}
func formatProxy(proxy string) (string, error) {
reg := regexp.MustCompile(`[\w\-]+?://[\w\-]+(\.[\w\-]+)*(:\d+)?`)
if !reg.MatchString(proxy) {
return "", fmt.Errorf(`Invalid proxy "%v"`, proxy)
}
return proxy, nil
}
// SetHost set host for Codeforces
func (c *Config) SetHost() (err error) {
host, err := formatHost(c.Host)
if err != nil {
host = "https://codeforces.com"
}
color.Green("Current host domain is %v", host)
color.Cyan(`Set a new host domain (e.g. "https://codeforces.com"`)
color.Cyan(`Note: Don't forget the "http://" or "https://"`)
for {
host, err = formatHost(util.ScanlineTrim())
if err == nil {
break
}
color.Red(err.Error())
}
c.Host = host
color.Green("New host domain is %v", host)
return c.save()
}
// SetProxy set proxy for client
func (c *Config) SetProxy() (err error) {
proxy, err := formatProxy(c.Proxy)
if err != nil {
proxy = ""
}
if len(proxy) == 0 {
color.Green("Current proxy is based on environment")
} else {
color.Green("Current proxy is %v", proxy)
}
color.Cyan(`Set a new proxy (e.g. "http://127.0.0.1:2333", "socks5://127.0.0.1:1080"`)
color.Cyan(`Enter empty line if you want to use default proxy from environment`)
color.Cyan(`Note: Proxy URL should match "protocol://host[:port]"`)
for {
proxy, err = formatProxy(util.ScanlineTrim())
if err == nil {
break
}
color.Red(err.Error())
}
c.Proxy = proxy
if len(proxy) == 0 {
color.Green("Current proxy is based on environment")
} else {
color.Green("Current proxy is %v", proxy)
}
return c.save()
}
// SetFolderName set folder name
func (c *Config) SetFolderName() (err error) {
color.Cyan(`Set folders' name`)
color.Cyan(`Enter empty line if you don't want to change the value`)
color.Green(`Root path (current: %v)`, c.FolderName["root"])
if value := util.ScanlineTrim(); value != "" {
c.FolderName["root"] = value
}
for _, problemType := range client.ProblemTypes {
color.Green(`%v path (current: %v)`, problemType, c.FolderName[problemType])
if value := util.ScanlineTrim(); value != "" {
c.FolderName[problemType] = value
}
}
return c.save()
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。