package cmd import ( "fmt" "os" "path/filepath" "github.com/insertr/cli/pkg/parser" "github.com/spf13/cobra" ) var parseCmd = &cobra.Command{ Use: "parse [input-dir]", Short: "Parse HTML files and detect editable elements", Long: `Parse HTML files in the specified directory and detect elements with the 'insertr' class. This command analyzes the HTML structure and reports what editable elements would be enhanced.`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { inputDir := args[0] if _, err := os.Stat(inputDir); os.IsNotExist(err) { fmt.Fprintf(os.Stderr, "Error: Directory %s does not exist\n", inputDir) os.Exit(1) } fmt.Printf("šŸ” Parsing HTML files in: %s\n\n", inputDir) p := parser.New() result, err := p.ParseDirectory(inputDir) if err != nil { fmt.Fprintf(os.Stderr, "Error parsing directory: %v\n", err) os.Exit(1) } printParseResults(result) }, } func printParseResults(result *parser.ParseResult) { fmt.Printf("šŸ“Š Parse Results:\n") fmt.Printf(" Files processed: %d\n", result.Stats.FilesProcessed) fmt.Printf(" Elements found: %d\n", result.Stats.TotalElements) fmt.Printf(" Existing IDs: %d\n", result.Stats.ExistingIDs) fmt.Printf(" Generated IDs: %d\n", result.Stats.GeneratedIDs) if len(result.Stats.TypeBreakdown) > 0 { fmt.Printf("\nšŸ“ Content Types:\n") for contentType, count := range result.Stats.TypeBreakdown { fmt.Printf(" %s: %d\n", contentType, count) } } if len(result.Elements) > 0 { fmt.Printf("\nšŸŽÆ Found Elements:\n") for _, element := range result.Elements { fmt.Printf(" %s <%s> id=%s type=%s\n", filepath.Base(element.FilePath), element.Tag, element.ContentID, element.Type) } } if len(result.Warnings) > 0 { fmt.Printf("\nāš ļø Warnings:\n") for _, warning := range result.Warnings { fmt.Printf(" %s\n", warning) } } }