Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
go.work

# End of https://www.toptal.com/developers/gitignore/api/go

pman
12 changes: 9 additions & 3 deletions cmd/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package cmd

import (
"fmt"
"github.com/spf13/cobra"
"log"
"pman/pkg"
"pman/pkg/db"
"pman/pkg/ui"

"github.com/spf13/cobra"
)

var lsCmd = &cobra.Command{
Expand All @@ -23,10 +25,14 @@ var lsCmd = &cobra.Command{
if filterFlag != "" {
fmt.Println("Filtering by status : ", filterFlag)
data := pkg.FilterByStatus(data, filterFlag)
pkg.PrintData(data)
_ = data
ui.RenderTable(data)
// ui.Pikachu()
return
}
pkg.PrintData(data)
ui.RenderTable(data)
// ui.Pikachu()

},
}

Expand Down
6 changes: 6 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
Expand All @@ -18,6 +19,10 @@ var rootCmd = &cobra.Command{
cmd.Help()
return
}
interactiveFlag, _ := cmd.Flags().GetBool("i") // TODO: Implement this
if interactiveFlag {
fmt.Println("Not implemented")
}
},
}

Expand All @@ -29,4 +34,5 @@ func Execute() {
}

func init() {
rootCmd.Flags().Bool("i", false, "Run pman interactively")
}
22 changes: 15 additions & 7 deletions cmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ var setCmd = &cobra.Command{
Usage:
pman set <project_name> <status>

Common statuses: Indexed (default) , Started , Paused , Completed , Aborted , Deleted , Ongoing , Not Started
Common statuses: Indexed (default) ,Idea , Started , Paused , Completed , Aborted , Ongoing , Not Started
`,
Run: func(cmd *cobra.Command, args []string) {
interactiveFlag, _ := cmd.Flags().GetBool("i")
Run: func(cmd *cobra.Command, args []string) { // BUG : cannot set the status using the alias.
interactiveFlag, _ := cmd.Flags().GetBool("i") // TODO: Implement this
if interactiveFlag {
fmt.Println("Not implemented yet")
return
Expand All @@ -26,14 +26,22 @@ var setCmd = &cobra.Command{
fmt.Println("Please provide a directory name")
return
}
project := args[0]
var pname string
alias := args[0]
status := args[1]
err := db.UpdateRec(project, status, StatusBucket)

project, err := db.GetRecord(alias, ProjectAliasBucket)
if err == nil {
pname = project
} else {
pname = alias
}
err = db.UpdateRec(pname, status, StatusBucket)
if err != nil {
fmt.Println("Error updating record")
fmt.Println("Error updating record : ", err)
return
}
fmt.Printf("Project %s set to status %s\n", project, status)
fmt.Printf("Project %s set to status %s\n", pname, status)
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ var statusCmd = &cobra.Command{
return
}
if alias != "" {
fmt.Printf("Status of %s (%s) : %s\n", projName, alias, pkg.Title(status))
fmt.Printf("Status of %s (%s) : %s\n", projName, alias, pkg.TitleCase(status))
} else {
fmt.Printf("Status of %s : %s\n", projName, pkg.Title(status))
fmt.Printf("Status of %s : %s\n", projName, pkg.TitleCase(status))
}
},
}
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module pman

go 1.22.1
go 1.22.2

require (
github.com/charmbracelet/glamour v0.7.0
github.com/charmbracelet/lipgloss v0.10.0
github.com/spf13/cobra v1.8.0
go.etcd.io/bbolt v1.3.9
golang.org/x/text v0.14.0
Expand All @@ -18,12 +19,12 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/microcosm-cc/bluemonday v1.0.26 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/yuin/goldmark v1.5.4 // indirect
github.com/yuin/goldmark-emoji v1.0.2 // indirect
Expand Down
11 changes: 8 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
github.com/alecthomas/assert/v2 v2.2.1 h1:XivOgYcduV98QCahG8T5XTezV5bylXe+lBxLG2K2ink=
github.com/alecthomas/assert/v2 v2.2.1/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ=
github.com/alecthomas/chroma/v2 v2.8.0 h1:w9WJUjFFmHHB2e8mRpL9jjy3alYDlU0QLDezj1xE264=
Expand All @@ -10,6 +12,8 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/charmbracelet/glamour v0.7.0 h1:2BtKGZ4iVJCDfMF229EzbeR1QRKLWztO9dMtjmqZSng=
github.com/charmbracelet/glamour v0.7.0/go.mod h1:jUMh5MeihljJPQbJ/wf4ldw2+yBP59+ctV36jASy7ps=
github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s=
github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -27,8 +31,8 @@ github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp9
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58=
github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs=
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
Expand All @@ -40,8 +44,9 @@ github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
Expand Down
6 changes: 1 addition & 5 deletions pkg/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ func DeleteFromDb(key string, bucketName string) error {
if bucket == nil {
return fmt.Errorf("bucket %s not found", bucketName)
}
// val := bucket.Get([]byte(key))
// if val == nil {
// return fmt.Errorf("%s does not exist inside the db", key)
// }
err := bucket.Delete([]byte(key))
if err != nil {
return err
Expand Down Expand Up @@ -87,7 +83,7 @@ func GetRecord(key string, bucketName string) (string, error) {
}
v := bucket.Get([]byte(key))
if v == nil {
return fmt.Errorf("Key not found")
return fmt.Errorf("Key not found in db\n")
}
rec = string(v)
return nil
Expand Down
68 changes: 68 additions & 0 deletions pkg/ui/statusTable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package ui

import (
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
"os"
"pman/pkg"
"pman/pkg/db"
"sort"
)

// RenderTable: renders the given data as a table
func RenderTable(data map[string]string) error {
var TableData [][]string
for p, status := range data {
alias, err := db.GetRecord(p, pkg.ProjectAliasBucket)
if err == nil {
pname := fmt.Sprintf("%s (%s)", p, alias)
row := []string{pkg.TitleCase(status), pname} // Status | prjectName (alias)
TableData = append(TableData, row)
} else {
row := []string{pkg.TitleCase(status), p} // Status | prjectName
TableData = append(TableData, row)
}
}
sort.Slice(TableData, func(i, j int) bool {
valI := TableData[i][1]
valJ := TableData[j][1]
return valI < valJ
})
re := lipgloss.NewRenderer(os.Stdout)
baseStyle := re.NewStyle().Padding(0, 1)
headerStyle := baseStyle.Copy().Foreground(lipgloss.Color("252")).Bold(true)
// selectedStyle := baseStyle.Copy().Foreground(lipgloss.Color("#01BE85")).Background(lipgloss.Color("#00432F"))
statusColors := map[string]lipgloss.Color{
"Idea": lipgloss.Color("#FF87D7"),
"Indexed": lipgloss.Color("#727272"),
"Not Started": lipgloss.Color("#D7FF87"),
"Ongoing": lipgloss.Color("#00E2C7"),
"Started": lipgloss.Color("#00E2C7"),
"Paused": lipgloss.Color("#7D5AFC"),
"Completed": lipgloss.Color("#75FBAB"),
"Aborted": lipgloss.Color("#FF875F"),
"Default": lipgloss.Color("#929292"),
}
headers := []string{"Project Name", "Status"}
t := table.New().
Border(lipgloss.NormalBorder()).
BorderStyle(re.NewStyle().Foreground(lipgloss.Color("238"))).
Headers(headers...).
Width(80).
Rows(TableData...).
StyleFunc(func(row, col int) lipgloss.Style {
if row == 0 {
return headerStyle
}
color, ok := statusColors[fmt.Sprint(TableData[row-1][0])]
if ok {
return baseStyle.Copy().Foreground(color)
} else {
color := statusColors["Default"]
return baseStyle.Copy().Foreground(color)
}
})
fmt.Println(t)
return nil
}
18 changes: 4 additions & 14 deletions pkg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,7 @@ import (
"pman/pkg/db"
)

var SupportedStatus = []string{
"Indexed",
"Started",
"Paused",
"Completed",
"Aborted",
"Deleted",
"Ongoing",
"Not Started",
}

func Title(s string) string {
func TitleCase(s string) string {
c := cases.Title(language.English)
return c.String(s)
}
Expand All @@ -33,13 +22,14 @@ func FilterByStatus(data map[string]string, status string) map[string]string {
return filteredData
}

// Deprecated: Use ui.RenderTable instead
func PrintData(data map[string]string) {
for k, v := range data {
alias, err := db.GetRecord(k, ProjectAliasBucket)
if err == nil {
fmt.Printf("%s : %s (%s) \n", Title(v), k, alias)
fmt.Printf("%s : %s (%s) \n", TitleCase(v), k, alias)
} else {
fmt.Printf("%s : %s \n", Title(v), k)
fmt.Printf("%s : %s \n", TitleCase(v), k)
}
}
}