Skip to content

Commit

Permalink
Merge pull request #33 from theredditbandit/dev
Browse files Browse the repository at this point in the history
fix bug in ReadREADME function
  • Loading branch information
theredditbandit authored May 15, 2024
2 parents 6277a63 + dcb1cef commit d36532d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmd/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <status>")
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")
}
9 changes: 7 additions & 2 deletions pkg/ui/interactiveTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package ui
import (
"fmt"
"sort"
"strings"

"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"

"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"
)

Expand Down Expand Up @@ -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
}
Expand Down
17 changes: 11 additions & 6 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d36532d

Please sign in to comment.