diff --git a/cmd/ls.go b/cmd/ls.go index d61634d..7dc2644 100644 --- a/cmd/ls.go +++ b/cmd/ls.go @@ -18,7 +18,7 @@ var lsCmd = &cobra.Command{ `, RunE: func(cmd *cobra.Command, _ []string) error { filterFlag, _ := cmd.Flags().GetString("f") - oldUI, _ := cmd.Flags().GetBool("o") + oldUI, _ := cmd.Flags().GetBool("c") data, err := db.GetAllRecords(db.DBName, StatusBucket) if err != nil { return err @@ -37,5 +37,5 @@ var lsCmd = &cobra.Command{ func init() { rootCmd.AddCommand(lsCmd) lsCmd.Flags().String("f", "", "Filter projects by status. Usage : pman ls --f ") - lsCmd.Flags().Bool("o", false, "list projects using the old ui. Usage : pman ls --o") + lsCmd.Flags().Bool("c", false, "list projects using the colorful table. Usage : pman ls --c") } diff --git a/pkg/ui/interactiveTable.go b/pkg/ui/interactiveTable.go index 86fc82c..5e941d3 100644 --- a/pkg/ui/interactiveTable.go +++ b/pkg/ui/interactiveTable.go @@ -3,6 +3,7 @@ package ui import ( "fmt" "sort" + "strings" "github.com/charmbracelet/bubbles/table" tea "github.com/charmbracelet/bubbletea" @@ -10,7 +11,7 @@ import ( "github.com/theredditbandit/pman/pkg" "github.com/theredditbandit/pman/pkg/db" - p "github.com/theredditbandit/pman/pkg/ui/pager" + pgr "github.com/theredditbandit/pman/pkg/ui/pager" "github.com/theredditbandit/pman/pkg/utils" ) @@ -38,7 +39,11 @@ func (m tableModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Quit case "enter": project := m.table.SelectedRow()[1] - err := p.LaunchRenderer(project) + if strings.Contains(project, ")") { // project is of the form a-long-project-name (alias) + projectAliasArr := strings.Split(project, " ") + project = projectAliasArr[0] + } + err := pgr.LaunchRenderer(project) if err != nil { return m, tea.Quit } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index ddca814..670afdf 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -96,14 +96,19 @@ func BeautifyMD(data []byte) (string, error) { // ReadREADME: returns the byte array of README.md of a project func ReadREADME(projectName string) ([]byte, error) { - actualName, err := db.GetRecord(db.DBName, projectName, pkg.ProjectAliasBucket) - if err == nil { - projectName = actualName - } path, err := db.GetRecord(db.DBName, projectName, pkg.ProjectPaths) if err != nil { - log.Printf("project: %v not a valid project\n", projectName) - return nil, errors.Join(ErrReadREADME, err) + actualName, err := db.GetRecord(db.DBName, projectName, pkg.ProjectAliasBucket) + if err != nil { + log.Printf("project: %v not a valid project\n", projectName) + return nil, errors.Join(ErrReadREADME, err) + } + projectName = actualName + path, err = db.GetRecord(db.DBName, projectName, pkg.ProjectPaths) + if err != nil { + log.Printf("project: %v not a valid project\n", projectName) + return nil, errors.Join(ErrReadREADME, err) + } } pPath := filepath.Join(path, "README.md") data, err := os.ReadFile(pPath)