Skip to content

Commit

Permalink
Use path type instead of an auto-expanding string
Browse files Browse the repository at this point in the history
This is required to remove value.FromInstance, but also makes tests
possible without manipulating $HOME, and allows me to remove the (now
archived) go-homedir dependency

Closes #51
  • Loading branch information
bbkane committed Dec 27, 2024
1 parent 41c4cd5 commit 53cacc3
Show file tree
Hide file tree
Showing 28 changed files with 649 additions and 321 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ below this description) is likely unreleased.

## Added

- `path.Path` type that users should call `Expand`/`MustExpand` on.
- `path.Path` type that users should call `Expand`/`MustExpand` on. See `Removed`

## Changed

Expand Down
3 changes: 2 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go.bbkane.com/warg/config"
"go.bbkane.com/warg/flag"
"go.bbkane.com/warg/help"
"go.bbkane.com/warg/path"
"go.bbkane.com/warg/section"
"go.bbkane.com/warg/value"
"go.bbkane.com/warg/value/scalar"
Expand Down Expand Up @@ -127,7 +128,7 @@ func ConfigFlag(
// TODO: put the new stuff at the front to be consistent with OverrideHelpFlag
configFlagName flag.Name,
// TODO: can I make this nicer?
scalarOpts []scalar.ScalarOpt[string],
scalarOpts []scalar.ScalarOpt[path.Path],
newConfigReader config.NewReader,
helpShort flag.HelpShort,
flagOpts ...flag.FlagOpt,
Expand Down
11 changes: 8 additions & 3 deletions app_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go.bbkane.com/warg/config"
"go.bbkane.com/warg/flag"
"go.bbkane.com/warg/help/common"
"go.bbkane.com/warg/path"
"go.bbkane.com/warg/section"
"go.bbkane.com/warg/value"
)
Expand Down Expand Up @@ -441,9 +442,13 @@ func (app *App) parseWithOptHolder(parseOptHolder ParseOptHolder) (*ParseResult,
if err != nil {
return nil, err
}
// NOTE: this *should* always be a string
configPath := app.configFlag.Value.Get().(string)
configReader, err = app.newConfigReader(configPath)
// NOTE: this should *always* be a path.
configPath := app.configFlag.Value.Get().(path.Path)
configPathStr, err := configPath.Expand()
if err != nil {
return nil, fmt.Errorf("error expanding config path ( %s ) : %w", configPath, err)
}
configReader, err = app.newConfigReader(configPathStr)
if err != nil {
return nil, fmt.Errorf("error reading config path ( %s ) : %w", configPath, err)
}
Expand Down
Loading

0 comments on commit 53cacc3

Please sign in to comment.