Skip to content

Commit

Permalink
Rename internal function for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed Aug 10, 2021
1 parent 182b937 commit d79c30e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
54 changes: 27 additions & 27 deletions internal/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ type applyArgsOptions struct {
}

func (c *Config) applyArgs(targetSystem chezmoi.System, targetDirAbsPath chezmoi.AbsPath, args []string, options applyArgsOptions) error {
sourceState, err := c.sourceState()
sourceState, err := c.newSourceState()
if err != nil {
return err
}
Expand Down Expand Up @@ -975,7 +975,7 @@ func (c *Config) gitAutoPush(status *git.Status) error {

func (c *Config) makeRunEWithSourceState(runE func(*cobra.Command, []string, *chezmoi.SourceState) error) func(*cobra.Command, []string) error {
return func(cmd *cobra.Command, args []string) error {
sourceState, err := c.sourceState()
sourceState, err := c.newSourceState()
if err != nil {
return err
}
Expand Down Expand Up @@ -1104,6 +1104,31 @@ func (c *Config) newRootCmd() (*cobra.Command, error) {
return rootCmd, nil
}

func (c *Config) newSourceState(options ...chezmoi.SourceStateOption) (*chezmoi.SourceState, error) {
s := chezmoi.NewSourceState(append([]chezmoi.SourceStateOption{
chezmoi.WithDefaultTemplateDataFunc(c.defaultTemplateData),
chezmoi.WithDestDir(c.DestDirAbsPath),
chezmoi.WithEncryption(c.encryption),
chezmoi.WithInterpreters(c.Interpreters),
chezmoi.WithMode(c.Mode),
chezmoi.WithPriorityTemplateData(c.Data),
chezmoi.WithSourceDir(c.SourceDirAbsPath),
chezmoi.WithSystem(c.sourceSystem),
chezmoi.WithTemplateFuncs(c.templateFuncs),
chezmoi.WithTemplateOptions(c.Template.Options),
}, options...)...)

if err := s.Read(); err != nil {
return nil, err
}

if minVersion := s.MinVersion(); c.version != nil && !isDevVersion(c.version) && c.version.LessThan(minVersion) {
return nil, fmt.Errorf("source state requires version %s or later, chezmoi is version %s", minVersion, c.version)
}

return s, nil
}

func (c *Config) persistentPostRunRootE(cmd *cobra.Command, args []string) error {
defer pprof.StopCPUProfile()

Expand Down Expand Up @@ -1447,31 +1472,6 @@ func (c *Config) sourceAbsPaths(sourceState *chezmoi.SourceState, args []string)
return sourceAbsPaths, nil
}

func (c *Config) sourceState(options ...chezmoi.SourceStateOption) (*chezmoi.SourceState, error) {
s := chezmoi.NewSourceState(append([]chezmoi.SourceStateOption{
chezmoi.WithDefaultTemplateDataFunc(c.defaultTemplateData),
chezmoi.WithDestDir(c.DestDirAbsPath),
chezmoi.WithEncryption(c.encryption),
chezmoi.WithInterpreters(c.Interpreters),
chezmoi.WithMode(c.Mode),
chezmoi.WithPriorityTemplateData(c.Data),
chezmoi.WithSourceDir(c.SourceDirAbsPath),
chezmoi.WithSystem(c.sourceSystem),
chezmoi.WithTemplateFuncs(c.templateFuncs),
chezmoi.WithTemplateOptions(c.Template.Options),
}, options...)...)

if err := s.Read(); err != nil {
return nil, err
}

if minVersion := s.MinVersion(); c.version != nil && !isDevVersion(c.version) && c.version.LessThan(minVersion) {
return nil, fmt.Errorf("source state requires version %s or later, chezmoi is version %s", minVersion, c.version)
}

return s, nil
}

type targetRelPathsOptions struct {
mustBeInSourceState bool
recursive bool
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/executetemplatecmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *Config) runExecuteTemplateCmd(cmd *cobra.Command, args []string) error
if c.executeTemplate.init {
options = append(options, chezmoi.WithReadTemplateData(false))
}
sourceState, err := c.sourceState(options...)
sourceState, err := c.newSourceState(options...)
if err != nil {
return err
}
Expand Down

0 comments on commit d79c30e

Please sign in to comment.