Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make terminology more consistent #116

Merged
merged 3 commits into from
Jan 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use DestDir instead of TargetDir in code
  • Loading branch information
twpayne committed Jan 13, 2019
commit af4b71436855f772e9ab789d0a0c6a5ec75d6e51
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ to apply the changes to the destination state:
## Using `chezmoi` outside your home directory

`chezmoi`, by default, operates on your home directory, but this can be
overridden with the `--target` command line flag or by specifying `targetDir`
in your `~/.config/chezmoi/chezmoi.yaml`. In theory, you could use `chezmoi` to
overridden with the `--dest` command line flag or by specifying `destDir` in
your `~/.config/chezmoi/chezmoi.yaml`. In theory, you could use `chezmoi` to
manage any aspect of your filesystem. That said, although you can do this, you
probably shouldn't. Existing configuration management tools like
[Puppet](https://puppet.com/), [Chef](https://www.chef.io/chef/),
Expand Down
4 changes: 2 additions & 2 deletions cmd/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func TestAddAfterModification(t *testing.T) {
c := &Config{
SourceDir: "/home/user/.chezmoi",
TargetDir: "/home/user",
DestDir: "/home/user",
Umask: 022,
DryRun: false,
Verbose: true,
Expand Down Expand Up @@ -252,7 +252,7 @@ func TestAddCommand(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
c := &Config{
SourceDir: "/home/user/.chezmoi",
TargetDir: "/home/user",
DestDir: "/home/user",
Umask: 022,
DryRun: false,
Verbose: true,
Expand Down
2 changes: 1 addition & 1 deletion cmd/chattr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func TestChattrCommand(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
c := &Config{
SourceDir: "/home/user/.config/share/chezmoi",
TargetDir: "/home/user",
DestDir: "/home/user",
Umask: 022,
Verbose: true,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestExercise(t *testing.T) {

c := &Config{
SourceDir: "/home/user/.chezmoi",
TargetDir: "/home/user",
DestDir: "/home/user",
Umask: 022,
Verbose: true,
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// A Config represents a configuration.
type Config struct {
SourceDir string
TargetDir string
DestDir string
Umask octalIntValue
DryRun bool
Verbose bool
Expand Down Expand Up @@ -62,7 +62,7 @@ func (c *Config) applyArgs(fs vfs.FS, args []string, mutator chezmoi.Mutator) er
return err
}
for _, entry := range entries {
if err := entry.Apply(fs, ts.TargetDir, ts.TargetIgnore.Match, ts.Umask, mutator); err != nil {
if err := entry.Apply(fs, ts.DestDir, ts.TargetIgnore.Match, ts.Umask, mutator); err != nil {
return err
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func (c *Config) getDefaultMutator(fs vfs.FS) chezmoi.Mutator {
if c.DryRun {
mutator = chezmoi.NullMutator
} else {
mutator = chezmoi.NewFSMutator(fs, c.TargetDir)
mutator = chezmoi.NewFSMutator(fs, c.DestDir)
}
if c.Verbose {
mutator = chezmoi.NewLoggingMutator(os.Stdout, mutator)
Expand Down Expand Up @@ -140,7 +140,7 @@ func (c *Config) getTargetState(fs vfs.FS) (*chezmoi.TargetState, error) {
for key, value := range c.Data {
data[key] = value
}
ts := chezmoi.NewTargetState(c.TargetDir, os.FileMode(c.Umask), c.SourceDir, data, c.funcs)
ts := chezmoi.NewTargetState(c.DestDir, os.FileMode(c.Umask), c.SourceDir, data, c.funcs)
readOnlyFS := vfs.NewReadOnlyFS(fs)
if err := ts.Populate(readOnlyFS); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c *Config) runDumpCommand(fs vfs.FS, args []string) error {
}
var concreteValues []interface{}
for _, entry := range entries {
entryConcreteValue, err := entry.ConcreteValue(ts.TargetDir, ts.TargetIgnore.Match, ts.SourceDir, c.dump.recursive)
entryConcreteValue, err := entry.ConcreteValue(ts.DestDir, ts.TargetIgnore.Match, ts.SourceDir, c.dump.recursive)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *Config) runEditCommand(fs vfs.FS, args []string) error {
if c.edit.diff {
mutator = chezmoi.NewLoggingMutator(os.Stdout, mutator)
}
if err := entry.Apply(readOnlyFS, ts.TargetDir, ts.TargetIgnore.Match, ts.Umask, mutator); err != nil {
if err := entry.Apply(readOnlyFS, ts.DestDir, ts.TargetIgnore.Match, ts.Umask, mutator); err != nil {
return err
}
if c.edit.apply && anyMutator.Mutated() {
Expand All @@ -81,7 +81,7 @@ func (c *Config) runEditCommand(fs vfs.FS, args []string) error {
c.edit.prompt = false
}
}
if err := entry.Apply(readOnlyFS, ts.TargetDir, ts.TargetIgnore.Match, ts.Umask, applyMutator); err != nil {
if err := entry.Apply(readOnlyFS, ts.DestDir, ts.TargetIgnore.Match, ts.Umask, applyMutator); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *Config) runRemoveCommand(fs vfs.FS, args []string) error {
}
mutator := c.getDefaultMutator(fs)
for _, entry := range entries {
if err := mutator.RemoveAll(filepath.Join(c.TargetDir, entry.TargetName())); err != nil && !os.IsNotExist(err) {
if err := mutator.RemoveAll(filepath.Join(c.DestDir, entry.TargetName())); err != nil && !os.IsNotExist(err) {
return err
}
if err := mutator.RemoveAll(filepath.Join(c.SourceDir, entry.SourceName())); err != nil && !os.IsNotExist(err) {
Expand Down
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ func init() {
persistentFlags.BoolVarP(&config.DryRun, "dry-run", "n", false, "dry run")
viper.BindPFlag("dry-run", persistentFlags.Lookup("dry-run"))

persistentFlags.StringVarP(&config.SourceDir, "source", "s", getDefaultSourceDir(x, homeDir), "source directory")
persistentFlags.StringVarP(&config.SourceDir, "source", "S", getDefaultSourceDir(x, homeDir), "source directory")
viper.BindPFlag("source", persistentFlags.Lookup("source"))

persistentFlags.StringVarP(&config.TargetDir, "target", "t", homeDir, "target directory")
viper.BindPFlag("target", persistentFlags.Lookup("target"))
persistentFlags.StringVarP(&config.DestDir, "destination", "D", homeDir, "destination directory")
viper.BindPFlag("destination", persistentFlags.Lookup("destination"))

persistentFlags.VarP(&config.Umask, "umask", "u", "umask")
viper.BindPFlag("umask", persistentFlags.Lookup("umask"))
Expand Down
4 changes: 2 additions & 2 deletions lib/chezmoi/chezmoi.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type templateFuncError struct {

// An Entry is either a Dir, a File, or a Symlink.
type Entry interface {
Apply(fs vfs.FS, targetDir string, ignore func(string) bool, umask os.FileMode, mutator Mutator) error
ConcreteValue(targetDir string, ignore func(string) bool, sourceDir string, recursive bool) (interface{}, error)
Apply(fs vfs.FS, destDir string, ignore func(string) bool, umask os.FileMode, mutator Mutator) error
ConcreteValue(destDir string, ignore func(string) bool, sourceDir string, recursive bool) (interface{}, error)
Evaluate(ignore func(string) bool) error
SourceName() string
TargetName() string
Expand Down
14 changes: 7 additions & 7 deletions lib/chezmoi/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ func newDir(sourceName string, targetName string, exact bool, perm os.FileMode)
}
}

// Apply ensures that targetDir in fs matches d.
func (d *Dir) Apply(fs vfs.FS, targetDir string, ignore func(string) bool, umask os.FileMode, mutator Mutator) error {
// Apply ensures that destDir in fs matches d.
func (d *Dir) Apply(fs vfs.FS, destDir string, ignore func(string) bool, umask os.FileMode, mutator Mutator) error {
if ignore(d.targetName) {
return nil
}
targetPath := filepath.Join(targetDir, d.targetName)
targetPath := filepath.Join(destDir, d.targetName)
info, err := fs.Lstat(targetPath)
switch {
case err == nil && info.Mode().IsDir():
Expand All @@ -112,7 +112,7 @@ func (d *Dir) Apply(fs vfs.FS, targetDir string, ignore func(string) bool, umask
return err
}
for _, entryName := range sortedEntryNames(d.Entries) {
if err := d.Entries[entryName].Apply(fs, targetDir, ignore, umask, mutator); err != nil {
if err := d.Entries[entryName].Apply(fs, destDir, ignore, umask, mutator); err != nil {
return err
}
}
Expand All @@ -134,14 +134,14 @@ func (d *Dir) Apply(fs vfs.FS, targetDir string, ignore func(string) bool, umask
}

// ConcreteValue implements Entry.ConcreteValue.
func (d *Dir) ConcreteValue(targetDir string, ignore func(string) bool, sourceDir string, recursive bool) (interface{}, error) {
func (d *Dir) ConcreteValue(destDir string, ignore func(string) bool, sourceDir string, recursive bool) (interface{}, error) {
if ignore(d.targetName) {
return nil, nil
}
var entryConcreteValues []interface{}
if recursive {
for _, entryName := range sortedEntryNames(d.Entries) {
entryConcreteValue, err := d.Entries[entryName].ConcreteValue(targetDir, ignore, sourceDir, recursive)
entryConcreteValue, err := d.Entries[entryName].ConcreteValue(destDir, ignore, sourceDir, recursive)
if err != nil {
return nil, err
}
Expand All @@ -153,7 +153,7 @@ func (d *Dir) ConcreteValue(targetDir string, ignore func(string) bool, sourceDi
return &dirConcreteValue{
Type: "dir",
SourcePath: filepath.Join(sourceDir, d.SourceName()),
TargetPath: filepath.Join(targetDir, d.TargetName()),
TargetPath: filepath.Join(destDir, d.TargetName()),
Exact: d.Exact,
Perm: int(d.Perm),
Entries: entryConcreteValues,
Expand Down
8 changes: 4 additions & 4 deletions lib/chezmoi/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ func (fa FileAttributes) SourceName() string {
}

// Apply ensures that the state of targetPath in fs matches f.
func (f *File) Apply(fs vfs.FS, targetDir string, ignore func(string) bool, umask os.FileMode, mutator Mutator) error {
func (f *File) Apply(fs vfs.FS, destDir string, ignore func(string) bool, umask os.FileMode, mutator Mutator) error {
if ignore(f.targetName) {
return nil
}
contents, err := f.Contents()
if err != nil {
return err
}
targetPath := filepath.Join(targetDir, f.targetName)
targetPath := filepath.Join(destDir, f.targetName)
info, err := fs.Lstat(targetPath)
var currData []byte
switch {
Expand Down Expand Up @@ -158,7 +158,7 @@ func (f *File) Apply(fs vfs.FS, targetDir string, ignore func(string) bool, umas
}

// ConcreteValue implements Entry.ConcreteValue.
func (f *File) ConcreteValue(targetDir string, ignore func(string) bool, sourceDir string, recursive bool) (interface{}, error) {
func (f *File) ConcreteValue(destDir string, ignore func(string) bool, sourceDir string, recursive bool) (interface{}, error) {
if ignore(f.targetName) {
return nil, nil
}
Expand All @@ -169,7 +169,7 @@ func (f *File) ConcreteValue(targetDir string, ignore func(string) bool, sourceD
return &fileConcreteValue{
Type: "file",
SourcePath: filepath.Join(sourceDir, f.SourceName()),
TargetPath: filepath.Join(targetDir, f.TargetName()),
TargetPath: filepath.Join(destDir, f.TargetName()),
Empty: f.Empty,
Perm: int(f.Perm),
Template: f.Template,
Expand Down
4 changes: 2 additions & 2 deletions lib/chezmoi/fs_mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ type FSMutator struct {
}

// NewFSMutator returns an mutator that acts on fs.
func NewFSMutator(fs vfs.FS, targetDir string) *FSMutator {
func NewFSMutator(fs vfs.FS, destDir string) *FSMutator {
var dir string
// Special case: if writing to the real filesystem, use github.com/google/renameio
if fs == vfs.OSFS {
dir = renameio.TempDir(targetDir)
dir = renameio.TempDir(destDir)
}
return &FSMutator{
FS: fs,
Expand Down
8 changes: 4 additions & 4 deletions lib/chezmoi/symlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ type symlinkConcreteValue struct {
}

// Apply ensures that the state of s's target in fs matches s.
func (s *Symlink) Apply(fs vfs.FS, targetDir string, ignore func(string) bool, umask os.FileMode, mutator Mutator) error {
func (s *Symlink) Apply(fs vfs.FS, destDir string, ignore func(string) bool, umask os.FileMode, mutator Mutator) error {
if ignore(s.targetName) {
return nil
}
target, err := s.Linkname()
if err != nil {
return err
}
targetPath := filepath.Join(targetDir, s.targetName)
targetPath := filepath.Join(destDir, s.targetName)
info, err := fs.Lstat(targetPath)
switch {
case err == nil && info.Mode()&os.ModeType == os.ModeSymlink:
Expand All @@ -55,7 +55,7 @@ func (s *Symlink) Apply(fs vfs.FS, targetDir string, ignore func(string) bool, u
}

// ConcreteValue implements Entry.ConcreteValue.
func (s *Symlink) ConcreteValue(targetDir string, ignore func(string) bool, sourceDir string, recursive bool) (interface{}, error) {
func (s *Symlink) ConcreteValue(destDir string, ignore func(string) bool, sourceDir string, recursive bool) (interface{}, error) {
if ignore(s.targetName) {
return nil, nil
}
Expand All @@ -66,7 +66,7 @@ func (s *Symlink) ConcreteValue(targetDir string, ignore func(string) bool, sour
return &symlinkConcreteValue{
Type: "symlink",
SourcePath: filepath.Join(sourceDir, s.SourceName()),
TargetPath: filepath.Join(targetDir, s.TargetName()),
TargetPath: filepath.Join(destDir, s.TargetName()),
Template: s.Template,
Linkname: linkname,
}, nil
Expand Down
26 changes: 13 additions & 13 deletions lib/chezmoi/target_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type ImportTAROptions struct {

// A TargetState represents the root target state.
type TargetState struct {
TargetDir string
DestDir string
TargetIgnore PatternSet
Umask os.FileMode
SourceDir string
Expand All @@ -44,9 +44,9 @@ type TargetState struct {
}

// NewTargetState creates a new TargetState.
func NewTargetState(targetDir string, umask os.FileMode, sourceDir string, data map[string]interface{}, funcs template.FuncMap) *TargetState {
func NewTargetState(destDir string, umask os.FileMode, sourceDir string, data map[string]interface{}, funcs template.FuncMap) *TargetState {
return &TargetState{
TargetDir: targetDir,
DestDir: destDir,
TargetIgnore: NewPatternSet(),
Umask: umask,
SourceDir: sourceDir,
Expand All @@ -58,10 +58,10 @@ func NewTargetState(targetDir string, umask os.FileMode, sourceDir string, data

// Add adds a new target to ts.
func (ts *TargetState) Add(fs vfs.FS, addOptions AddOptions, targetPath string, info os.FileInfo, mutator Mutator) error {
if !filepath.HasPrefix(targetPath, ts.TargetDir) {
if !filepath.HasPrefix(targetPath, ts.DestDir) {
return fmt.Errorf("%s: outside target directory", targetPath)
}
targetName, err := filepath.Rel(ts.TargetDir, targetPath)
targetName, err := filepath.Rel(ts.DestDir, targetPath)
if err != nil {
return err
}
Expand All @@ -82,7 +82,7 @@ func (ts *TargetState) Add(fs vfs.FS, addOptions AddOptions, targetPath string,
return err
}
if parentEntry == nil {
if err := ts.Add(fs, addOptions, filepath.Join(ts.TargetDir, parentDirName), nil, mutator); err != nil {
if err := ts.Add(fs, addOptions, filepath.Join(ts.DestDir, parentDirName), nil, mutator); err != nil {
return err
}
parentEntry, err = ts.findEntry(parentDirName)
Expand Down Expand Up @@ -132,10 +132,10 @@ func (ts *TargetState) Add(fs vfs.FS, addOptions AddOptions, targetPath string,
}
}

// Apply ensures that ts.TargetDir in fs matches ts.
// Apply ensures that ts.DestDir in fs matches ts.
func (ts *TargetState) Apply(fs vfs.FS, mutator Mutator) error {
for _, entryName := range sortedEntryNames(ts.Entries) {
if err := ts.Entries[entryName].Apply(fs, ts.TargetDir, ts.TargetIgnore.Match, ts.Umask, mutator); err != nil {
if err := ts.Entries[entryName].Apply(fs, ts.DestDir, ts.TargetIgnore.Match, ts.Umask, mutator); err != nil {
return err
}
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func (ts *TargetState) Archive(w *tar.Writer, umask os.FileMode) error {
func (ts *TargetState) ConcreteValue(recursive bool) (interface{}, error) {
var entryConcreteValues []interface{}
for _, entryName := range sortedEntryNames(ts.Entries) {
entryConcreteValue, err := ts.Entries[entryName].ConcreteValue(ts.TargetDir, ts.TargetIgnore.Match, ts.SourceDir, recursive)
entryConcreteValue, err := ts.Entries[entryName].ConcreteValue(ts.DestDir, ts.TargetIgnore.Match, ts.SourceDir, recursive)
if err != nil {
return nil, err
}
Expand All @@ -205,10 +205,10 @@ func (ts *TargetState) Evaluate() error {

// Get returns the state of the given target, or nil if no such target is found.
func (ts *TargetState) Get(target string) (Entry, error) {
if !filepath.HasPrefix(target, ts.TargetDir) {
if !filepath.HasPrefix(target, ts.DestDir) {
return nil, fmt.Errorf("%s: outside target directory", target)
}
targetName, err := filepath.Rel(ts.TargetDir, target)
targetName, err := filepath.Rel(ts.DestDir, target)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -543,9 +543,9 @@ func (ts *TargetState) importHeader(r io.Reader, importTAROptions ImportTAROptio
if importTAROptions.DestinationDir != "" {
targetPath = filepath.Join(importTAROptions.DestinationDir, targetPath)
} else {
targetPath = filepath.Join(ts.TargetDir, targetPath)
targetPath = filepath.Join(ts.DestDir, targetPath)
}
targetName, err := filepath.Rel(ts.TargetDir, targetPath)
targetName, err := filepath.Rel(ts.DestDir, targetPath)
if err != nil {
return err
}
Expand Down
Loading