Files
cburn/cmd/projects.go
teernisse 083e7d40ce refactor!: rename module to github.com/theirongolddev/cburn
Change module path from 'cburn' to 'github.com/theirongolddev/cburn'
to enable standard Go remote installation:

  go install github.com/theirongolddev/cburn@latest

This is a BREAKING CHANGE for any external code importing this module
(though as a CLI tool, this is unlikely to affect anyone).

All internal imports updated to use the new module path.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-23 10:09:26 -05:00

62 lines
1.3 KiB
Go

package cmd
import (
"fmt"
"github.com/theirongolddev/cburn/internal/cli"
"github.com/theirongolddev/cburn/internal/pipeline"
"github.com/spf13/cobra"
)
var projectsCmd = &cobra.Command{
Use: "projects",
Short: "Project usage ranking",
RunE: runProjects,
}
func init() {
rootCmd.AddCommand(projectsCmd)
}
func runProjects(_ *cobra.Command, _ []string) error {
result, err := loadData()
if err != nil {
return err
}
if len(result.Sessions) == 0 {
fmt.Println("\n No sessions found.")
return nil
}
filtered, since, until := applyFilters(result.Sessions)
projects := pipeline.AggregateProjects(filtered, since, until)
if len(projects) == 0 {
fmt.Println("\n No project data in the selected time range.")
return nil
}
fmt.Println()
fmt.Println(cli.RenderTitle(fmt.Sprintf("PROJECTS Last %dd", flagDays)))
fmt.Println()
rows := make([][]string, 0, len(projects))
for _, ps := range projects {
rows = append(rows, []string{
truncate(ps.Project, 18),
cli.FormatNumber(int64(ps.Sessions)),
cli.FormatNumber(int64(ps.Prompts)),
cli.FormatTokens(ps.TotalTokens),
cli.FormatCost(ps.EstimatedCost),
})
}
fmt.Print(cli.RenderTable(cli.Table{
Headers: []string{"Project", "Sessions", "Prompts", "Tokens", "Cost"},
Rows: rows,
}))
return nil
}