forked from twpayne/chezmoi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunmanagedcmd.go
More file actions
49 lines (43 loc) · 1.24 KB
/
unmanagedcmd.go
File metadata and controls
49 lines (43 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cmd
import (
"os"
"strings"
"github.com/spf13/cobra"
vfs "github.com/twpayne/go-vfs/v2"
"github.com/twpayne/chezmoi/v2/internal/chezmoi"
)
func (c *Config) newUnmanagedCmd() *cobra.Command {
unmanagedCmd := &cobra.Command{
Use: "unmanaged",
Short: "List the unmanaged files in the destination directory",
Long: mustLongHelp("unmanaged"),
Example: example("unmanaged"),
Args: cobra.NoArgs,
RunE: c.makeRunEWithSourceState(c.runUnmanagedCmd),
}
return unmanagedCmd
}
func (c *Config) runUnmanagedCmd(cmd *cobra.Command, args []string, sourceState *chezmoi.SourceState) error {
sb := strings.Builder{}
if err := chezmoi.Walk(c.destSystem, c.destDirAbsPath, func(destAbsPath chezmoi.AbsPath, info os.FileInfo, err error) error {
if err != nil {
return err
}
if destAbsPath == c.destDirAbsPath {
return nil
}
targeRelPath := destAbsPath.MustTrimDirPrefix(c.destDirAbsPath)
_, managed := sourceState.Entry(targeRelPath)
ignored := sourceState.Ignored(targeRelPath)
if !managed && !ignored {
sb.WriteString(string(targeRelPath) + "\n")
}
if info.IsDir() && (!managed || ignored) {
return vfs.SkipDir
}
return nil
}); err != nil {
return err
}
return c.writeOutputString(sb.String())
}