Skip to content

Commit 39475ef

Browse files
committed
Add files commands
1 parent 52c4735 commit 39475ef

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

cmd/dots/files.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/spf13/cobra"
8+
9+
"go.evanpurkhiser.com/dots/resolver"
10+
)
11+
12+
var filesCmd = cobra.Command{
13+
Use: "files [filter...]",
14+
Short: "List resolved dotfile paths",
15+
RunE: func(cmd *cobra.Command, args []string) error {
16+
dotfiles := resolver.ResolveDotfiles(*sourceConfig, *sourceLockfile)
17+
18+
fmt.Println(strings.Join(dotfiles.Filter(args).Files(), "\n"))
19+
20+
return nil
21+
},
22+
}

config/config.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,25 @@ type SourceLockfile struct {
7878
Profile string `json:"profile"`
7979

8080
// Groups is a list of groups to be installed if no profile is specified.
81-
// Does nothing if a profile has been specified.
81+
// Does nothing if a profile has been specified. The base groups from the
82+
// configuration will always be installed.
8283
Groups []string `json:"groups"`
8384

8485
// IntalledFiles is the current list of insatlled configuration files
8586
InstalledFiles []string `json:"installed_files"`
8687
}
8788

89+
// ResolveGroups returns the list of groups the lockfile is currently locked to.
90+
func (l *SourceLockfile) ResolveGroups(config SourceConfig) []string {
91+
profileGroups, ok := config.Profiles[l.Profile]
92+
if ok {
93+
return append(config.BaseGroups, profileGroups...)
94+
}
95+
96+
// Use lockfile groups override list
97+
return append(config.BaseGroups, l.Groups...)
98+
}
99+
88100
// SourceConfigPath determines the location of the source configuration file.
89101
func SourceConfigPath() string {
90102
if path := os.Getenv(sourceConfigEnv); path != "" {

0 commit comments

Comments
 (0)