Files
sgard/cmd/sgard/list.go
Kyle Isom 34f9598a19 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>
2026-03-23 21:51:01 -07:00

42 lines
725 B
Go

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)
}