代码拉取完成,页面将自动刷新
package se
import (
"os"
"path"
"gitee.com/xuender/oils/logs"
"github.com/BurntSushi/toml"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// Config 设置.
type Config struct {
DataBasePath string
Deploy bool
Limit uint `toml:"-"`
Offset uint `toml:"-"`
Start string `toml:"-"`
Exts []string
Ignore []string
PassDir bool
}
// NewConfig 新建配置.
func NewConfig() *Config {
c := &Config{}
c.Chack()
return c
}
// Read 从命令行中读取配置.
func (p *Config) Read(cmd *cobra.Command) {
if db, err := cmd.Flags().GetString("db"); db != "" && err == nil {
p.DataBasePath = db
}
if limit, err := cmd.Flags().GetUint("limit"); err == nil {
p.Limit = limit
}
if offset, err := cmd.Flags().GetUint("offset"); err == nil {
p.Offset = offset
}
if start, err := cmd.Flags().GetString("start"); err == nil {
p.Start = start
}
}
// Chack 配置检查.
func (p *Config) Chack() {
if p.Limit == 0 {
p.Limit = 100
}
if p.DataBasePath == "" {
dir := logs.PanicString(homedir.Dir())
p.DataBasePath = path.Join(dir, ".se")
}
if len(p.Exts) == 0 {
p.Exts = []string{".go", ".txt", ".puml", ".java"}
}
if len(p.Ignore) == 0 {
p.Ignore = []string{"vendor", "target", "node_modules", ".git"}
}
}
// Save 保存配置.
func (p *Config) Save() {
if viper.ConfigFileUsed() == "" {
home := logs.PanicString(homedir.Dir())
viper.SetConfigFile(path.Join(home, ".se.toml"))
}
logs.Debug("保存日志", viper.ConfigFileUsed())
p.Chack()
file, err := os.Create(viper.ConfigFileUsed())
logs.Panic(err)
defer file.Close()
e := toml.NewEncoder(file)
logs.Panic(e.Encode(p))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。