From bf15999c02ba47e7430b71dc9ec075c417b6cad2 Mon Sep 17 00:00:00 2001 From: Overbool Date: Thu, 1 Nov 2018 15:26:19 +0800 Subject: [PATCH] cmds/env: add a config path helper License: MIT Signed-off-by: Overbool --- core/commands/cmdenv/env.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/commands/cmdenv/env.go b/core/commands/cmdenv/env.go index c3f36fd8c88..603a8bd3322 100644 --- a/core/commands/cmdenv/env.go +++ b/core/commands/cmdenv/env.go @@ -40,3 +40,13 @@ func GetConfig(env cmds.Environment) (*config.Config, error) { return ctx.GetConfig() } + +// GetConfigRoot extracts the config root from the environment +func GetConfigRoot(env cmds.Environment) (string, error) { + ctx, ok := env.(*commands.Context) + if !ok { + return "", fmt.Errorf("expected env to be of type %T, got %T", ctx, env) + } + + return ctx.ConfigRoot, nil +}