-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportProjectsCommand.java
More file actions
48 lines (38 loc) · 1.77 KB
/
ExportProjectsCommand.java
File metadata and controls
48 lines (38 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.preponderous.parpt.command;
import com.preponderous.parpt.domain.Project;
import com.preponderous.parpt.repo.ProjectMarkdownWriter;
import com.preponderous.parpt.service.ProjectService;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;
import org.springframework.shell.standard.ShellOption;
import java.util.List;
@ShellComponent
public class ExportProjectsCommand {
private final ProjectService projectService;
private final ProjectMarkdownWriter markdownWriter;
public ExportProjectsCommand(ProjectService projectService, ProjectMarkdownWriter markdownWriter) {
this.projectService = projectService;
this.markdownWriter = markdownWriter;
}
@ShellMethod(key = "export", value = "Exports all projects to Markdown format, sorted by score.")
public String execute(
@ShellOption(value = {"-s", "--sort"}, help = "Sort by 'ice' or 'rice' score (default: ice)", defaultValue = "ice") String sortBy
) {
List<Project> projects = projectService.getProjects();
if (projects.isEmpty()) {
return "No projects found to export.";
}
boolean sortByRice = "rice".equalsIgnoreCase(sortBy);
if (!sortByRice && !"ice".equalsIgnoreCase(sortBy)) {
return "Invalid sort option. Use 'ice' or 'rice'.";
}
try {
markdownWriter.writeMarkdown(projects, sortByRice);
String scoreType = sortByRice ? "RICE" : "ICE";
return String.format("Successfully exported %d projects to projects.md, sorted by %s score.",
projects.size(), scoreType);
} catch (Exception e) {
return "Failed to export projects: " + e.getMessage();
}
}
}