package cmd import ( "fmt" "cliprepo/internal/tree" "github.com/spf13/cobra" ) var treeOutput string var treeClipboard bool var treeCmd = &cobra.Command{ Use: "tree", Short: "Print repo tree respecting .gitignore", RunE: func(cmd *cobra.Command, args []string) error { result, err := tree.Generate(".") if err != nil { return err } if treeClipboard { return tree.Copy(result) } if treeOutput != "" { return tree.Write(treeOutput, result) } fmt.Println(result) return nil }, } func init() { rootCmd.AddCommand(treeCmd) treeCmd.Flags().StringVarP(&treeOutput, "output", "o", "", "Output file") treeCmd.Flags().BoolVar(&treeClipboard, "clipboard", false, "Copy to clipboard") }