Skip to content

Commit

Permalink
Small improvements to ChangeDirFlag.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitar authored and alecthomas committed Jan 3, 2022
1 parent f5bd146 commit 76d5ed9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
}

0 comments on commit 76d5ed9

Please sign in to comment.