cmds/env: add a config path helper
License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>
Overbool committed
Nov 1, 2018 at 15:26 UTC
bf15999c02ba47e7430b71dc9ec075c417b6cad2
1 file changed
+10
core/commands/cmdenv/env.go
+10
@@ -40,3 +40,13 @@ func GetConfig(env cmds.Environment) (*config.Config, error) {
40
41
return ctx.GetConfig()
42
}
43
+
44
+// GetConfigRoot extracts the config root from the environment
45
+func GetConfigRoot(env cmds.Environment) (string, error) {
46
+ ctx, ok := env.(*commands.Context)
47
+ if !ok {
48
+ return "", fmt.Errorf("expected env to be of type %T, got %T", ctx, env)
49
+ }
50
+
51
+ return ctx.ConfigRoot, nil
52
+}