Small improvements to ChangeDirFlag.

This commit is contained in:
Mitar
2022-01-03 21:28:14 +01:00
committed by Alec Thomas
parent f5bd1465d8
commit 76d5ed9ac1
+3
View File
@@ -40,6 +40,8 @@ func (v VersionFlag) BeforeApply(app *Kong, vars Vars) error {
// early in the parsing process, changing how other flags resolve relative paths.
//
// Use this flag to provide a "git -C" like functionality.
//
// It is not compatible with custom named decoders, e.g., existingdir.
type ChangeDirFlag string
// Decode is used to create a side effect of changing the current working directory.
@@ -49,6 +51,7 @@ func (c ChangeDirFlag) Decode(ctx *DecodeContext) error {
if err != nil {
return err
}
path = ExpandPath(path)
ctx.Value.Target.Set(reflect.ValueOf(ChangeDirFlag(path)))
return os.Chdir(path)
}