提交 20d6803d 作者: Łukasz Magiera

config: option to apply profile after init

License: MIT
Signed-off-by: 's avatarŁukasz Magiera <magik6k@gmail.com>
上级 9db5471e
......@@ -142,6 +142,7 @@ Set the value of the 'Datastore.Path' key:
"show": configShowCmd,
"edit": configEditCmd,
"replace": configReplaceCmd,
"profile": configProfileCmd,
},
}
......@@ -293,6 +294,59 @@ can't be undone.
},
}
var configProfileCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Apply profiles to config.",
},
Subcommands: map[string]*cmds.Command{
"apply": configProfileApplyCmd,
},
}
var configProfileApplyCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Apply profile to config.",
},
Arguments: []cmds.Argument{
cmds.StringArg("profile", true, false, "The profile to apply to the config."),
},
Run: func(req cmds.Request, res cmds.Response) {
args := req.Arguments()
profile, ok := config.ConfigProfiles[args[0]]
if !ok {
res.SetError(fmt.Errorf("%s in not a profile", args[0]), cmds.ErrNormal)
return
}
r, err := fsrepo.Open(req.InvocContext().ConfigRoot)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
defer r.Close()
cfg, err := r.Config()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
err = profile(cfg)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
err = r.SetConfig(cfg)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
},
}
func getConfig(r repo.Repo, key string) (*ConfigField, error) {
value, err := r.GetConfigKey(key)
if err != nil {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论