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
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
Add printing of symlinks to cat command
  • Loading branch information
twpayne committed Jan 13, 2019
commit d855c1e58b5065788d195bab0eff57502c77f3ad
29 changes: 18 additions & 11 deletions cmd/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var catCommand = &cobra.Command{
Use: "cat",
Args: cobra.MinimumNArgs(1),
Short: "Write the target state of a file to stdout",
Short: "Write the target state of a file or symlink to stdout",
RunE: makeRunE(config.runCatCommand),
}

Expand All @@ -30,16 +30,23 @@ func (c *Config) runCatCommand(fs vfs.FS, args []string) error {
return err
}
for i, entry := range entries {
f, ok := entry.(*chezmoi.File)
if !ok {
return fmt.Errorf("%s: not a regular file", args[i])
}
contents, err := f.Contents()
if err != nil {
return err
}
if _, err := os.Stdout.Write(contents); err != nil {
return err
switch entry := entry.(type) {
case *chezmoi.File:
contents, err := entry.Contents()
if err != nil {
return err
}
if _, err := os.Stdout.Write(contents); err != nil {
return err
}
case *chezmoi.Symlink:
linkname, err := entry.Linkname()
if err != nil {
return err
}
fmt.Println(linkname)
default:
return fmt.Errorf("%s: not a file or symlink", args[i])
}
}
return nil
Expand Down