MCPcopy Create free account
hub / github.com/Facets-cloud/flow / listProjectsCmd

Function listProjectsCmd

internal/app/list.go:550–721  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

548}
549
550func listProjectsCmd(args []string) int {
551 fs := flagSet("list projects")
552 status := fs.String("status", "", "active|done")
553 includeArchived := fs.Bool("include-archived", false, "include archived projects")
554 opts := addListFlags(fs)
555 if err := fs.Parse(args); err != nil {
556 return 2
557 }
558 fmtKind, err := listfmt.ParseFormat(*opts.format)
559 if err != nil {
560 fmt.Fprintf(os.Stderr, "error: %v\n", err)
561 return 2
562 }
563 filter := flowdb.ProjectFilter{
564 Status: *status,
565 IncludeArchived: *includeArchived,
566 }
567 dbPath, err := flowDBPath()
568 if err != nil {
569 fmt.Fprintf(os.Stderr, "error: %v\n", err)
570 return 1
571 }
572 db, err := flowdb.OpenDB(dbPath)
573 if err != nil {
574 fmt.Fprintf(os.Stderr, "error: open db: %v\n", err)
575 return 1
576 }
577 defer db.Close()
578
579 projects, err := flowdb.ListProjects(db, filter)
580 if err != nil {
581 fmt.Fprintf(os.Stderr, "error: %v\n", err)
582 return 1
583 }
584
585 headers := []string{"PRIORITY", "SLUG", "STATUS", "TASKS", "BREAKDOWN", "NOTES"}
586 tsvHeaders := []string{"slug", "priority", "status", "total", "in_progress", "backlog", "done", "archived"}
587 if len(projects) == 0 {
588 return emptyResult(fmtKind, "projects", tsvHeaders)
589 }
590
591 // Sort projects by priority (high, med, low) then slug. ListProjects
592 // currently sorts by slug only, so reorder here.
593 sortedProjects := make([]*flowdb.Project, len(projects))
594 copy(sortedProjects, projects)
595 priorityOrder := func(p string) int {
596 switch p {
597 case "high":
598 return 0
599 case "medium":
600 return 1
601 case "low":
602 return 2
603 }
604 return 3
605 }
606 for i := 1; i < len(sortedProjects); i++ {
607 for j := i; j > 0; j-- {

Callers 1

cmdListFunction · 0.85

Calls 15

WrapMethod · 0.95
RenderMethod · 0.95
ParseFormatFunction · 0.92
OpenDBFunction · 0.92
ListProjectsFunction · 0.92
RenderTSVFunction · 0.92
ColorEnabledFunction · 0.92
flagSetFunction · 0.85
addListFlagsFunction · 0.85
flowDBPathFunction · 0.85
emptyResultFunction · 0.85
projectTaskCountsFunction · 0.85

Tested by

no test coverage detected