diff --git a/internal/cmd/catcmd.go b/internal/cmd/catcmd.go index 0d93a2c24b3..0014943424b 100644 --- a/internal/cmd/catcmd.go +++ b/internal/cmd/catcmd.go @@ -27,9 +27,7 @@ func (c *Config) newCatCmd() *cobra.Command { } func (c *Config) runCatCmd(cmd *cobra.Command, args []string, sourceState *chezmoi.SourceState) error { - targetRelPaths, err := c.targetRelPaths(sourceState, args, targetRelPathsOptions{ - mustBeManaged: true, - }) + targetRelPaths, err := c.targetRelPaths(sourceState, args, nil) if err != nil { return err } diff --git a/internal/cmd/chattrcmd.go b/internal/cmd/chattrcmd.go index 057f2d94ac9..689b3f1dc22 100644 --- a/internal/cmd/chattrcmd.go +++ b/internal/cmd/chattrcmd.go @@ -150,9 +150,8 @@ func (c *Config) runChattrCmd(cmd *cobra.Command, args []string, sourceState *ch return err } - targetRelPaths, err := c.targetRelPaths(sourceState, args[1:], targetRelPathsOptions{ - mustBeManaged: true, - recursive: c.chattr.recursive, + targetRelPaths, err := c.targetRelPaths(sourceState, args[1:], &targetRelPathsOptions{ + recursive: c.chattr.recursive, }) if err != nil { return err diff --git a/internal/cmd/config.go b/internal/cmd/config.go index ea779703f08..ae496cf0de5 100644 --- a/internal/cmd/config.go +++ b/internal/cmd/config.go @@ -631,9 +631,8 @@ func (c *Config) applyArgs( return err } default: - targetRelPaths, err = c.targetRelPaths(sourceState, args, targetRelPathsOptions{ - mustBeManaged: true, - recursive: options.recursive, + targetRelPaths, err = c.targetRelPaths(sourceState, args, &targetRelPathsOptions{ + recursive: options.recursive, }) if err != nil { return err @@ -2437,9 +2436,8 @@ func (c *Config) setEnvironmentVariables() error { // sourceAbsPaths returns the source absolute paths for each target path in // args. func (c *Config) sourceAbsPaths(sourceState *chezmoi.SourceState, args []string) ([]chezmoi.AbsPath, error) { - targetRelPaths, err := c.targetRelPaths(sourceState, args, targetRelPathsOptions{ + targetRelPaths, err := c.targetRelPaths(sourceState, args, &targetRelPathsOptions{ mustBeInSourceState: true, - mustBeManaged: true, }) if err != nil { return nil, err @@ -2462,7 +2460,6 @@ func (c *Config) targetRelPath(absPath chezmoi.AbsPath) (chezmoi.RelPath, error) type targetRelPathsOptions struct { mustBeInSourceState bool - mustBeManaged bool recursive bool } @@ -2471,7 +2468,7 @@ type targetRelPathsOptions struct { func (c *Config) targetRelPaths( sourceState *chezmoi.SourceState, args []string, - options targetRelPathsOptions, + options *targetRelPathsOptions, ) (chezmoi.RelPaths, error) { targetRelPaths := make(chezmoi.RelPaths, 0, len(args)) for _, arg := range args { @@ -2484,16 +2481,16 @@ func (c *Config) targetRelPaths( return nil, err } sourceStateEntry := sourceState.Get(targetRelPath) - if options.mustBeManaged && sourceStateEntry == nil { + if sourceStateEntry == nil { return nil, fmt.Errorf("%s: not managed", arg) } - if options.mustBeInSourceState { + if options != nil && options.mustBeInSourceState { if _, ok := sourceStateEntry.(*chezmoi.SourceStateRemove); ok { return nil, fmt.Errorf("%s: not in source state", arg) } } targetRelPaths = append(targetRelPaths, targetRelPath) - if options.recursive { + if options != nil && options.recursive { parentRelPath := targetRelPath // FIXME we should not call s.TargetRelPaths() here - risk of // accidentally quadratic diff --git a/internal/cmd/editcmd.go b/internal/cmd/editcmd.go index 8a55bb38511..8a9ad256418 100644 --- a/internal/cmd/editcmd.go +++ b/internal/cmd/editcmd.go @@ -76,9 +76,8 @@ func (c *Config) runEditCmd(cmd *cobra.Command, args []string) error { return err } - targetRelPaths, err := c.targetRelPaths(sourceState, args, targetRelPathsOptions{ + targetRelPaths, err := c.targetRelPaths(sourceState, args, &targetRelPathsOptions{ mustBeInSourceState: true, - mustBeManaged: true, }) if err != nil { return err diff --git a/internal/cmd/forgetcmd.go b/internal/cmd/forgetcmd.go index 62d1e737185..7ce64f4e9a8 100644 --- a/internal/cmd/forgetcmd.go +++ b/internal/cmd/forgetcmd.go @@ -28,9 +28,7 @@ func (c *Config) newForgetCmd() *cobra.Command { } func (c *Config) runForgetCmd(cmd *cobra.Command, args []string, sourceState *chezmoi.SourceState) error { - targetRelPaths, err := c.targetRelPaths(sourceState, args, targetRelPathsOptions{ - mustBeManaged: true, - }) + targetRelPaths, err := c.targetRelPaths(sourceState, args, nil) if err != nil { return err } diff --git a/internal/cmd/mergecmd.go b/internal/cmd/mergecmd.go index 3ed2a4a739f..17d95663477 100644 --- a/internal/cmd/mergecmd.go +++ b/internal/cmd/mergecmd.go @@ -37,9 +37,8 @@ func (c *Config) newMergeCmd() *cobra.Command { } func (c *Config) runMergeCmd(cmd *cobra.Command, args []string, sourceState *chezmoi.SourceState) error { - targetRelPaths, err := c.targetRelPaths(sourceState, args, targetRelPathsOptions{ + targetRelPaths, err := c.targetRelPaths(sourceState, args, &targetRelPathsOptions{ mustBeInSourceState: true, - mustBeManaged: false, recursive: true, }) if err != nil { diff --git a/internal/cmd/readdcmd.go b/internal/cmd/readdcmd.go index 92b899939ea..544d1b9c1e0 100644 --- a/internal/cmd/readdcmd.go +++ b/internal/cmd/readdcmd.go @@ -52,9 +52,8 @@ func (c *Config) runReAddCmd(cmd *cobra.Command, args []string, sourceState *che ) } else { var err error - targetRelPaths, err = c.targetRelPaths(sourceState, args, targetRelPathsOptions{ - mustBeManaged: true, - recursive: c.reAdd.recursive, + targetRelPaths, err = c.targetRelPaths(sourceState, args, &targetRelPathsOptions{ + recursive: c.reAdd.recursive, }) if err != nil { return err diff --git a/internal/cmd/removecmd.go b/internal/cmd/removecmd.go index 88f2e806ae0..1c0df4a875b 100644 --- a/internal/cmd/removecmd.go +++ b/internal/cmd/removecmd.go @@ -37,9 +37,8 @@ func (c *Config) newRemoveCmd() *cobra.Command { } func (c *Config) runRemoveCmd(cmd *cobra.Command, args []string, sourceState *chezmoi.SourceState) error { - targetRelPaths, err := c.targetRelPaths(sourceState, args, targetRelPathsOptions{ - mustBeManaged: true, - recursive: c.remove.recursive, + targetRelPaths, err := c.targetRelPaths(sourceState, args, &targetRelPathsOptions{ + recursive: c.remove.recursive, }) if err != nil { return err