Add list command to display all tracked entries

Adds Garden.List() method that returns manifest entries, unit tests
for empty and populated repos, and a CLI command that formats output
by entry type (file with hash prefix, link with target, directory).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 21:51:01 -07:00
parent 0d53ca34aa
commit 34f9598a19
3 changed files with 116 additions and 0 deletions

41
cmd/sgard/list.go Normal file
View File

@@ -0,0 +1,41 @@
package main
import (
"fmt"
"github.com/kisom/sgard/garden"
"github.com/spf13/cobra"
)
var listCmd = &cobra.Command{
Use: "list",
Short: "List all tracked files",
RunE: func(cmd *cobra.Command, args []string) error {
g, err := garden.Open(repoFlag)
if err != nil {
return err
}
entries := g.List()
for _, e := range entries {
switch e.Type {
case "file":
hash := e.Hash
if len(hash) > 8 {
hash = hash[:8]
}
fmt.Printf("%-6s %s\t%s\n", "file", e.Path, hash)
case "link":
fmt.Printf("%-6s %s\t-> %s\n", "link", e.Path, e.Target)
case "directory":
fmt.Printf("%-6s %s\n", "dir", e.Path)
}
}
return nil
},
}
func init() {
rootCmd.AddCommand(listCmd)
}