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:
41
cmd/sgard/list.go
Normal file
41
cmd/sgard/list.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user