feat: add --reverse flag to bd dep tree command
- Add --reverse boolean flag to depTreeCmd - Pass reverse parameter to GetDependencyTree - Update display messages based on mode: - Normal: 'Dependency tree' / 'no dependencies' - Reverse: 'Dependent tree' / 'no dependents' Enables discovery tree visualization from goals downward.
This commit is contained in:
@@ -179,6 +179,7 @@ var depTreeCmd = &cobra.Command{
|
|||||||
|
|
||||||
showAllPaths, _ := cmd.Flags().GetBool("show-all-paths")
|
showAllPaths, _ := cmd.Flags().GetBool("show-all-paths")
|
||||||
maxDepth, _ := cmd.Flags().GetInt("max-depth")
|
maxDepth, _ := cmd.Flags().GetInt("max-depth")
|
||||||
|
reverse, _ := cmd.Flags().GetBool("reverse")
|
||||||
|
|
||||||
if maxDepth < 1 {
|
if maxDepth < 1 {
|
||||||
fmt.Fprintf(os.Stderr, "Error: --max-depth must be >= 1\n")
|
fmt.Fprintf(os.Stderr, "Error: --max-depth must be >= 1\n")
|
||||||
@@ -186,7 +187,7 @@ var depTreeCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
tree, err := store.GetDependencyTree(ctx, args[0], maxDepth, showAllPaths)
|
tree, err := store.GetDependencyTree(ctx, args[0], maxDepth, showAllPaths, reverse)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@@ -202,12 +203,20 @@ var depTreeCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(tree) == 0 {
|
if len(tree) == 0 {
|
||||||
fmt.Printf("\n%s has no dependencies\n", args[0])
|
if reverse {
|
||||||
|
fmt.Printf("\n%s has no dependents\n", args[0])
|
||||||
|
} else {
|
||||||
|
fmt.Printf("\n%s has no dependencies\n", args[0])
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cyan := color.New(color.FgCyan).SprintFunc()
|
cyan := color.New(color.FgCyan).SprintFunc()
|
||||||
fmt.Printf("\n%s Dependency tree for %s:\n\n", cyan("🌲"), args[0])
|
if reverse {
|
||||||
|
fmt.Printf("\n%s Dependent tree for %s:\n\n", cyan("🌲"), args[0])
|
||||||
|
} else {
|
||||||
|
fmt.Printf("\n%s Dependency tree for %s:\n\n", cyan("🌲"), args[0])
|
||||||
|
}
|
||||||
|
|
||||||
hasTruncation := false
|
hasTruncation := false
|
||||||
for _, node := range tree {
|
for _, node := range tree {
|
||||||
@@ -286,6 +295,7 @@ func init() {
|
|||||||
depAddCmd.Flags().StringP("type", "t", "blocks", "Dependency type (blocks|related|parent-child|discovered-from)")
|
depAddCmd.Flags().StringP("type", "t", "blocks", "Dependency type (blocks|related|parent-child|discovered-from)")
|
||||||
depTreeCmd.Flags().Bool("show-all-paths", false, "Show all paths to nodes (no deduplication for diamond dependencies)")
|
depTreeCmd.Flags().Bool("show-all-paths", false, "Show all paths to nodes (no deduplication for diamond dependencies)")
|
||||||
depTreeCmd.Flags().IntP("max-depth", "d", 50, "Maximum tree depth to display (safety limit)")
|
depTreeCmd.Flags().IntP("max-depth", "d", 50, "Maximum tree depth to display (safety limit)")
|
||||||
|
depTreeCmd.Flags().Bool("reverse", false, "Show dependent tree (what was discovered from this) instead of dependency tree (what blocks this)")
|
||||||
depCmd.AddCommand(depAddCmd)
|
depCmd.AddCommand(depAddCmd)
|
||||||
depCmd.AddCommand(depRemoveCmd)
|
depCmd.AddCommand(depRemoveCmd)
|
||||||
depCmd.AddCommand(depTreeCmd)
|
depCmd.AddCommand(depTreeCmd)
|
||||||
|
|||||||
Reference in New Issue
Block a user