package domain import ( "fmt" "os" "redmine_tree/domain/model" ) // UI represents the user interface output. type UI struct { // You can add fields here for more advanced UI customization if needed, // e.g., output writer (os.Stdout, os.Stderr), log levels, etc. } // NewUI creates and returns a new UI instance. func NewUI() *UI { return &UI{} } // PrintError prints an error message to stderr and exits. func (ui *UI) PrintError(format string, a ...interface{}) { fmt.Fprintf(os.Stderr, format, a...) os.Exit(1) } // Printf prints a formatted message to stdout. func (ui *UI) Printf(format string, a ...interface{}) { fmt.Printf(format, a...) } // Println prints a message to stdout with a newline. func (ui *UI) Println(a ...interface{}) { fmt.Println(a...) } // PrintProjects lists projects to stdout. func (ui *UI) PrintProjects(projects []model.Project) { ui.Printf("No project ID provided. Listing all available projects:\n\n") if len(projects) == 0 { ui.Println("No projects found.") } else { for _, p := range projects { ui.Printf(" #%d %s\n", p.ID, p.Name) } } } // PrintUsage prints the application usage message to stderr and exits. func (ui *UI) PrintUsage(appName string) { ui.Printf("Usage: %s \n", appName) ui.Printf(" REDMINE_URL and REDMINE_TOKEN must be set in .env, as environment variables, or in ~/.redmine-tree.json.\n") ui.Printf("Example: REDMINE_URL=https://redmine.example.com REDMINE_TOKEN=abc123 %s my-project\n", appName) ui.Printf("Or: %s my-project (if REDMINE_URL, REDMINE_TOKEN are in .env or ~/.redmine-tree.json)\n", appName) os.Exit(1) } // PrintFetchingProjectDetails prints the message when fetching project details. func (ui *UI) PrintFetchingProjectDetails(projectName, projectID string) { ui.Printf("Fetching issues for project: %s (%s)\n\n", projectName, projectID) } // PrintTotalIssuesFetched prints the total number of issues fetched. func (ui *UI) PrintTotalIssuesFetched(count int) { ui.Printf("Total issues fetched: %d\n\n", count) } // PrintIssueTreeHeader prints the header for the issue tree. func (ui *UI) PrintIssueTreeHeader(rootCount int) { ui.Printf("Issue tree (%d root issues):\n\n", rootCount) } // PrintSummary prints the summary of issues. func (ui *UI) PrintSummary(totalIssues, rootIssues int) { ui.Printf("\n--- Summary ---\n") ui.Printf("Total issues : %d\n", totalIssues) ui.Printf("Root issues : %d\n", rootIssues) }