Skip to content

Commit

Permalink
Add db tool
Browse files Browse the repository at this point in the history
  • Loading branch information
zyedidia committed Apr 25, 2023
1 parent 70d3e5b commit 0f21fcf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions knit.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ func Run(out io.Writer, args []string, flags Flags) (string, error) {
t = &rules.StatusTool{W: w, Db: db, Hash: flags.Hash}
case "path":
t = &rules.PathTool{W: w, Path: knitpath}
case "db":
t = &rules.DbTool{W: w, Db: db}
default:
return knitpath, fmt.Errorf("unknown tool: %s", flags.Tool)
}
Expand Down
19 changes: 19 additions & 0 deletions rules/tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var tools = []Tool{
&CommandsTool{},
&StatusTool{},
&PathTool{},
&DbTool{},
}

type Tool interface {
Expand Down Expand Up @@ -535,6 +536,24 @@ func (t *StatusTool) String() string {
return "status - output dependency status information"
}

type DbTool struct {
Db *Database
W io.Writer
}

func (t *DbTool) Run(g *Graph, args []string) error {
for hash, files := range t.Db.Prereqs.Hashes {
for fname, file := range files.Data {
fmt.Fprintf(t.W, "%016x: %s: hash=%x, time=%v, size=%d, exists=%v\n", hash, fname, file.Full, file.ModTime, file.Size, file.Exists)
}
}
return nil
}

func (t *DbTool) String() string {
return "db - show database information"
}

type PathTool struct {
W io.Writer
Path string
Expand Down

0 comments on commit 0f21fcf

Please sign in to comment.