From c243209aff554bd4dcb99edc9561acf665a7372e Mon Sep 17 00:00:00 2001 From: vb Date: Thu, 5 Feb 2026 14:51:19 +0100 Subject: [PATCH 01/60] adding delete command in the file pkg/cli/commands/delete.go --- .beads/issues.jsonl | 3 +++ pkg/cli/commands/delete.go | 47 ++++++++++++++++++++++++++++++++++++++ pkg/cli/commands/root.go | 1 + 3 files changed, 51 insertions(+) create mode 100644 .beads/issues.jsonl create mode 100644 pkg/cli/commands/delete.go diff --git a/.beads/issues.jsonl b/.beads/issues.jsonl new file mode 100644 index 0000000..dc687ff --- /dev/null +++ b/.beads/issues.jsonl @@ -0,0 +1,3 @@ +{"id":"LazyPM-15e","title":"issue1","status":"tombstone","priority":2,"issue_type":"feature","owner":"viljarb@tutanota.com","created_at":"2026-02-05T12:54:47.980567399+01:00","created_by":"vb","updated_at":"2026-02-05T12:54:54.505284343+01:00","deleted_at":"2026-02-05T12:54:54.505284343+01:00","deleted_by":"batch delete","delete_reason":"batch delete","original_type":"feature"} +{"id":"LazyPM-5dx","title":"gergreerg","description":"rgkjioergioreg","status":"tombstone","priority":2,"issue_type":"feature","owner":"viljarb@tutanota.com","created_at":"2026-02-05T12:59:44.540301146+01:00","created_by":"vb","updated_at":"2026-02-05T14:14:33.565644925+01:00","deleted_at":"2026-02-05T14:14:33.565644925+01:00","deleted_by":"batch delete","delete_reason":"batch delete","original_type":"feature"} +{"id":"LazyPM-9qt","title":"asdf","description":"asjoidiajsoijodas","status":"tombstone","priority":2,"issue_type":"feature","owner":"viljarb@tutanota.com","created_at":"2026-02-05T12:59:28.40054283+01:00","created_by":"vb","updated_at":"2026-02-05T14:14:28.948203666+01:00","deleted_at":"2026-02-05T14:14:28.948203666+01:00","deleted_by":"batch delete","delete_reason":"batch delete","original_type":"feature"} diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go new file mode 100644 index 0000000..443bc58 --- /dev/null +++ b/pkg/cli/commands/delete.go @@ -0,0 +1,47 @@ +package commands + +import ( + "fmt" + "strings" + + "github.com/LazyBachelor/LazyPM/internal/models" + + "github.com/spf13/cobra" +) + +var deleteCmd = &cobra.Command{ + Use: "delete [id]", + Short: "Delete existing issue", + Long: `Delete an existing issue by its ID.`, + Example: `pm delete issue_id`, + RunE: runDeleteCmd, + Aliases: []string{"del"}, + Args: cobra.MinimumNArgs(1), +} + +func runDeleteCmd(cmd *cobra.Command, args []string) error { + deleteID := strings.Join(args, " ") + + if deleteID == "" { + return fmt.Errorf("issue title cannot be empty") + } + + issue := &models.Issue{ + ID: deleteID, + } + + err := svc.Beads.DeleteIssue(cmd.Context(), issue.ID) + if err != nil { + return fmt.Errorf("error deleting issue: %w", err) + } + + str := fmt.Sprintf("Deleted issue with ID: %s\n", issue.ID) + + if issue.Title != "" { + str += fmt.Sprintf("Title: %s\n", issue.Title) + } + + fmt.Print(str) + + return nil +} diff --git a/pkg/cli/commands/root.go b/pkg/cli/commands/root.go index ebe772f..75098e3 100644 --- a/pkg/cli/commands/root.go +++ b/pkg/cli/commands/root.go @@ -21,6 +21,7 @@ func Execute(services *service.Services) error { func init() { rootCmd.AddCommand(createCmd) + rootCmd.AddCommand(deleteCmd) rootCmd.CompletionOptions.DisableDefaultCmd = false rootCmd.AddGroup(&cobra.Group{ID: "other", Title: "Helping Commands"}) rootCmd.SetCompletionCommandGroupID("other") From 3ffe17ed08db1e19cdf1857782a86f9bf75cabc1 Mon Sep 17 00:00:00 2001 From: vb Date: Thu, 5 Feb 2026 14:52:44 +0100 Subject: [PATCH 02/60] removing redundant reference to issue title --- pkg/cli/commands/delete.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 443bc58..6d95498 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -37,10 +37,6 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error { str := fmt.Sprintf("Deleted issue with ID: %s\n", issue.ID) - if issue.Title != "" { - str += fmt.Sprintf("Title: %s\n", issue.Title) - } - fmt.Print(str) return nil From 2215b5ad34dc8273ddb0db2cc2146871f31741b9 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Thu, 5 Feb 2026 15:53:15 +0100 Subject: [PATCH 03/60] add promt to user to confirm initializaton in direcory --- internal/service/service.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/service/service.go b/internal/service/service.go index c6afc25..f36730e 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -2,10 +2,13 @@ package service import ( "context" + "fmt" + "os" "time" "github.com/LazyBachelor/LazyPM/internal/models" "github.com/LazyBachelor/LazyPM/internal/storage" + "github.com/charmbracelet/huh" "github.com/google/uuid" "github.com/steveyegge/beads" @@ -28,6 +31,11 @@ type Services struct { func NewServices(ctx context.Context, config Config) (*Services, func(), error) { var cleanupFuncs []func() + if !initialized(config.BeadsDBPath) { + fmt.Println("PM is not initialized") + os.Exit(0) + } + store, err := beads.NewSQLiteStorage(ctx, config.BeadsDBPath) if err != nil { return nil, nil, err @@ -63,3 +71,24 @@ func runCleanup(funcs []func()) { fn() } } + +func initialized(beadsPath string) bool { + _, err := os.Stat(beadsPath) + + if os.IsNotExist(err) { + var initialize bool + + huh.NewForm( + huh.NewGroup( + huh.NewConfirm().Title("PM is not initialized in this directory!"). + Description("Do you want to initialize it here?"). + Value(&initialize), + ), + ).WithTheme(huh.ThemeBase16()).WithAccessible(true).Run() + + if !initialize { + return false + } + } + return true +} From e62472951130ec61ae6ac7b41ff769866bc644ba Mon Sep 17 00:00:00 2001 From: viljarb Date: Thu, 5 Feb 2026 17:40:25 +0100 Subject: [PATCH 04/60] removing issues.json1 From fc10092bb25617826f0e79c84d6bb2508b4a463c Mon Sep 17 00:00:00 2001 From: viljarb0 <156418063+viljarb0@users.noreply.github.com> Date: Thu, 5 Feb 2026 17:41:28 +0100 Subject: [PATCH 05/60] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/cli/commands/delete.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 6d95498..1792776 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -23,7 +23,7 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error { deleteID := strings.Join(args, " ") if deleteID == "" { - return fmt.Errorf("issue title cannot be empty") + return fmt.Errorf("issue ID cannot be empty") } issue := &models.Issue{ From 9e7eb962272c879dbd419530e34dfae906f8ed46 Mon Sep 17 00:00:00 2001 From: viljarb0 <156418063+viljarb0@users.noreply.github.com> Date: Thu, 5 Feb 2026 17:41:40 +0100 Subject: [PATCH 06/60] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/cli/commands/delete.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 1792776..9c52d86 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -22,10 +22,6 @@ var deleteCmd = &cobra.Command{ func runDeleteCmd(cmd *cobra.Command, args []string) error { deleteID := strings.Join(args, " ") - if deleteID == "" { - return fmt.Errorf("issue ID cannot be empty") - } - issue := &models.Issue{ ID: deleteID, } From dbff78cb6b57e11fb69b1f258e3e983ed3706b1f Mon Sep 17 00:00:00 2001 From: viljarb Date: Thu, 5 Feb 2026 17:44:21 +0100 Subject: [PATCH 07/60] modified: pkg/cli/commands/delete.go --- pkg/cli/commands/delete.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 9c52d86..10045c9 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -11,7 +11,7 @@ import ( var deleteCmd = &cobra.Command{ Use: "delete [id]", - Short: "Delete existing issue", + Short: "Delete an existing issue", Long: `Delete an existing issue by its ID.`, Example: `pm delete issue_id`, RunE: runDeleteCmd, From 45e076aeb7e787a04bac2b0a91d8e6478fe08e1b Mon Sep 17 00:00:00 2001 From: viljarb Date: Thu, 5 Feb 2026 17:45:51 +0100 Subject: [PATCH 08/60] simplifying the code in pkg/cli/commands/delete.go --- pkg/cli/commands/delete.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 10045c9..2569332 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -4,8 +4,6 @@ import ( "fmt" "strings" - "github.com/LazyBachelor/LazyPM/internal/models" - "github.com/spf13/cobra" ) @@ -22,11 +20,7 @@ var deleteCmd = &cobra.Command{ func runDeleteCmd(cmd *cobra.Command, args []string) error { deleteID := strings.Join(args, " ") - issue := &models.Issue{ - ID: deleteID, - } - - err := svc.Beads.DeleteIssue(cmd.Context(), issue.ID) + err := svc.Beads.DeleteIssue(cmd.Context(), deleteID) if err != nil { return fmt.Errorf("error deleting issue: %w", err) } From 632ea19a1d5ca352a6948ffbb9a20e1dcdf8a10a Mon Sep 17 00:00:00 2001 From: viljarb Date: Thu, 5 Feb 2026 17:46:15 +0100 Subject: [PATCH 09/60] deleted: .beads/issues.jsonl From c762c9db32c61eb22d9b66f39c6922b1cb5dc33f Mon Sep 17 00:00:00 2001 From: viljarb Date: Thu, 5 Feb 2026 18:01:43 +0100 Subject: [PATCH 10/60] corrected non-existed variable name --- pkg/cli/commands/delete.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 2569332..68fce1b 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -25,7 +25,7 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error { return fmt.Errorf("error deleting issue: %w", err) } - str := fmt.Sprintf("Deleted issue with ID: %s\n", issue.ID) + str := fmt.Sprintf("Deleted issue with ID: %s\n", deleteID) fmt.Print(str) From 8a0e1c27eefa28d8b5c84ed0da8601123e95a849 Mon Sep 17 00:00:00 2001 From: Robin Olsen <129996395+Telikz@users.noreply.github.com> Date: Thu, 5 Feb 2026 18:12:55 +0100 Subject: [PATCH 11/60] Delete .beads directory --- .beads/issues.jsonl | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .beads/issues.jsonl diff --git a/.beads/issues.jsonl b/.beads/issues.jsonl deleted file mode 100644 index dc687ff..0000000 --- a/.beads/issues.jsonl +++ /dev/null @@ -1,3 +0,0 @@ -{"id":"LazyPM-15e","title":"issue1","status":"tombstone","priority":2,"issue_type":"feature","owner":"viljarb@tutanota.com","created_at":"2026-02-05T12:54:47.980567399+01:00","created_by":"vb","updated_at":"2026-02-05T12:54:54.505284343+01:00","deleted_at":"2026-02-05T12:54:54.505284343+01:00","deleted_by":"batch delete","delete_reason":"batch delete","original_type":"feature"} -{"id":"LazyPM-5dx","title":"gergreerg","description":"rgkjioergioreg","status":"tombstone","priority":2,"issue_type":"feature","owner":"viljarb@tutanota.com","created_at":"2026-02-05T12:59:44.540301146+01:00","created_by":"vb","updated_at":"2026-02-05T14:14:33.565644925+01:00","deleted_at":"2026-02-05T14:14:33.565644925+01:00","deleted_by":"batch delete","delete_reason":"batch delete","original_type":"feature"} -{"id":"LazyPM-9qt","title":"asdf","description":"asjoidiajsoijodas","status":"tombstone","priority":2,"issue_type":"feature","owner":"viljarb@tutanota.com","created_at":"2026-02-05T12:59:28.40054283+01:00","created_by":"vb","updated_at":"2026-02-05T14:14:28.948203666+01:00","deleted_at":"2026-02-05T14:14:28.948203666+01:00","deleted_by":"batch delete","delete_reason":"batch delete","original_type":"feature"} From bf1842b1f9af231a6dd045cf566f7fbce6122458 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Thu, 5 Feb 2026 18:18:16 +0100 Subject: [PATCH 12/60] add repl that tunnels pm and shell commands --- cmd/survey.go | 10 +- go.mod | 9 +- go.sum | 21 ++++ pkg/cli/commands/read.go | 24 ++-- pkg/cli/commands/root.go | 9 ++ pkg/cli/repl.go | 243 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 302 insertions(+), 14 deletions(-) create mode 100644 pkg/cli/repl.go diff --git a/cmd/survey.go b/cmd/survey.go index 47da94a..8b90fb8 100644 --- a/cmd/survey.go +++ b/cmd/survey.go @@ -1,17 +1,19 @@ package main import ( + "context" + "fmt" + "os" + "github.com/LazyBachelor/LazyPM/pkg" "github.com/LazyBachelor/LazyPM/pkg/cli" "github.com/LazyBachelor/LazyPM/pkg/tui" "github.com/LazyBachelor/LazyPM/pkg/web" - "context" - "fmt" - "os" ) func main() { config := pkg.SurveyConfig{ + RootCmd: "pm", WebAddress: "localhost:8080", IssuePrefix: "pm", BeadsDBPath: "./.pm/db.db", @@ -25,7 +27,7 @@ func main() { case "tui": err = tui.Run(ctx, config) case "cli": - err = cli.Run(ctx, config) + err = cli.RunREPL(ctx, config) case "web": err = web.Run(ctx, config) default: diff --git a/go.mod b/go.mod index abdfeb5..9304c7d 100644 --- a/go.mod +++ b/go.mod @@ -6,11 +6,15 @@ require ( github.com/Dicklesworthstone/beads_viewer v0.14.3 github.com/NYTimes/gziphandler v1.1.1 github.com/a-h/templ v0.3.977 + github.com/c-bata/go-prompt v0.2.6 github.com/charmbracelet/bubbletea v1.3.10 + github.com/charmbracelet/huh v0.8.0 github.com/google/uuid v1.6.0 + github.com/muesli/reflow v0.3.0 github.com/rs/cors v1.11.1 github.com/spf13/cobra v1.10.2 github.com/steveyegge/beads v0.49.3 + golang.org/x/term v0.39.0 ) require ( @@ -27,7 +31,6 @@ require ( github.com/charmbracelet/bubbles v0.21.1 // indirect github.com/charmbracelet/colorprofile v0.4.1 // indirect github.com/charmbracelet/glamour v0.10.0 // indirect - github.com/charmbracelet/huh v0.8.0 // indirect github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 // indirect github.com/charmbracelet/x/ansi v0.11.5 // indirect github.com/charmbracelet/x/cellbuf v0.0.15 // indirect @@ -54,17 +57,18 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-localereader v0.0.1 // indirect github.com/mattn/go-runewidth v0.0.19 // indirect + github.com/mattn/go-tty v0.0.3 // indirect github.com/microcosm-cc/bluemonday v1.0.27 // indirect github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect - github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.16.0 // indirect github.com/natefinch/atomic v1.0.1 // indirect github.com/ncruces/go-sqlite3 v0.30.5 // indirect github.com/ncruces/go-strftime v1.0.0 // indirect github.com/ncruces/julianday v1.0.0 // indirect github.com/pelletier/go-toml/v2 v2.2.4 // indirect + github.com/pkg/term v1.2.0-beta.2 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/sagikazarmark/locafero v0.12.0 // indirect @@ -85,7 +89,6 @@ require ( golang.org/x/net v0.49.0 // indirect golang.org/x/sync v0.19.0 // indirect golang.org/x/sys v0.40.0 // indirect - golang.org/x/term v0.39.0 // indirect golang.org/x/text v0.33.0 // indirect golang.org/x/tools v0.41.0 // indirect gonum.org/v1/gonum v0.17.0 // indirect diff --git a/go.sum b/go.sum index 0525f8e..9ec6f9e 100644 --- a/go.sum +++ b/go.sum @@ -33,6 +33,8 @@ github.com/aymanbagabas/go-udiff v0.3.1 h1:LV+qyBQ2pqe0u42ZsUEtPiCaUoqgA9gYRDs3v github.com/aymanbagabas/go-udiff v0.3.1/go.mod h1:G0fsKmG+P6ylD0r6N/KgQD/nWzgfnl8ZBcNLgcbrw8E= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= +github.com/c-bata/go-prompt v0.2.6 h1:POP+nrHE+DfLYx370bedwNhsqmpCUynWPxuHi0C5vZI= +github.com/c-bata/go-prompt v0.2.6/go.mod h1:/LMAke8wD2FsNu9EXNdHxNLbd9MedkPnCdfpU9wwHfY= github.com/catppuccin/go v0.3.0 h1:d+0/YicIq+hSTo5oPuRi5kOpqkVA5tAsU6dNhvRu+aY= github.com/catppuccin/go v0.3.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= @@ -127,15 +129,24 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag= github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE= github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= +github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= +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.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw= github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= +github.com/mattn/go-tty v0.0.3 h1:5OfyWorkyO7xP52Mq7tB36ajHDG5OHrmBGIS/DtakQI= +github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0= github.com/microcosm-cc/bluemonday v1.0.27 h1:MpEUotklkwCSLeH+Qdx1VJgNqLlpY2KXwXFM08ygZfk= github.com/microcosm-cc/bluemonday v1.0.27/go.mod h1:jFi9vgW+H7c3V0lb6nR74Ib/DIB5OBs92Dimizgw2cA= github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4= @@ -158,6 +169,8 @@ github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= +github.com/pkg/term v1.2.0-beta.2 h1:L3y/h2jkuBVFdWiJvNfYfKmzcCnILw7mJWm2JQuMppw= +github.com/pkg/term v1.2.0-beta.2/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= 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/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= @@ -223,11 +236,19 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o= golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200918174421-af09f7315aff/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/pkg/cli/commands/read.go b/pkg/cli/commands/read.go index eb054c0..a6ed216 100644 --- a/pkg/cli/commands/read.go +++ b/pkg/cli/commands/read.go @@ -1,18 +1,20 @@ package commands import ( + "context" "strings" + "github.com/LazyBachelor/LazyPM/internal/models" "github.com/spf13/cobra" ) var getIssueCmd = &cobra.Command{ Use: "describe [issue ID]", - Aliases: []string{"get", "read"}, Short: "Get issue details", Long: `Get issue details by ID`, - RunE: runGetCmd, + Aliases: []string{"get", "read"}, Args: cobra.ExactArgs(1), + RunE: runGetCmd, ValidArgsFunction: completeIssues, } @@ -43,22 +45,30 @@ func init() { } func completeIssues(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + issues, _ := GetIssueCompletions(cmd.Context(), toComplete) + var ids []string + for _, issue := range issues { + ids = append(ids, issue.ID) + } + return ids, cobra.ShellCompDirectiveNoFileComp +} + +func GetIssueCompletions(ctx context.Context, toComplete string) ([]models.Issue, cobra.ShellCompDirective) { if svc == nil { return nil, cobra.ShellCompDirectiveNoFileComp } - issues, err := svc.Beads.AllIssues(cmd.Context()) + issues, err := svc.Beads.AllIssues(ctx) if err != nil { return nil, cobra.ShellCompDirectiveNoFileComp } - var completions []string + var completions []models.Issue for _, issue := range issues { - if strings.HasPrefix(issue.ID, toComplete) { - completions = append(completions, issue.ID) + completions = append(completions, issue) } else if strings.HasPrefix(issue.Title, toComplete) { - completions = append(completions, issue.ID) + completions = append(completions, issue) } } diff --git a/pkg/cli/commands/root.go b/pkg/cli/commands/root.go index edee54c..9b86fd0 100644 --- a/pkg/cli/commands/root.go +++ b/pkg/cli/commands/root.go @@ -14,8 +14,17 @@ var rootCmd = &cobra.Command{ } func Execute(services *service.Services) error { + SetServices(services) + return rootCmd.Execute() +} + +func SetServices(services *service.Services) { svc = services rootCmd.Use = svc.Config.RootCmd +} + +func ExecuteWithArgs(args []string) error { + rootCmd.SetArgs(args) return rootCmd.Execute() } diff --git a/pkg/cli/repl.go b/pkg/cli/repl.go new file mode 100644 index 0000000..5455b16 --- /dev/null +++ b/pkg/cli/repl.go @@ -0,0 +1,243 @@ +package cli + +import ( + "context" + "fmt" + "os" + "os/exec" + "strings" + + "github.com/LazyBachelor/LazyPM/internal/service" + "github.com/LazyBachelor/LazyPM/pkg" + "github.com/LazyBachelor/LazyPM/pkg/cli/commands" + "github.com/c-bata/go-prompt" + "github.com/muesli/reflow/truncate" + "golang.org/x/term" +) + +func RunREPL(ctx context.Context, config pkg.SurveyConfig) error { + oldState, err := term.GetState(int(os.Stdin.Fd())) + if err != nil { + return fmt.Errorf("failed to get terminal state: %w", err) + } + + svc, cleanup, err := service.NewServices(ctx, config) + if err != nil { + return fmt.Errorf("failed to initialize services: %w", err) + } + defer cleanup() + + commands.SetServices(svc) + + fmt.Printf("Welcome to Project Management CLI! Type 'pm help' for available commands.\n") + fmt.Printf("You can also run shell commands directly. Type 'exit' or 'quit' to leave.\n") + + for { + input := prompt.Input( + "› ", + completer, + prompt.OptionMaxSuggestion(5), + prompt.OptionSuggestionBGColor(prompt.DefaultColor), + prompt.OptionSelectedSuggestionBGColor(prompt.DefaultColor), + prompt.OptionDescriptionBGColor(prompt.DefaultColor), + prompt.OptionSelectedDescriptionBGColor(prompt.DefaultColor), + prompt.OptionPreviewSuggestionBGColor(prompt.DefaultColor), + prompt.OptionScrollbarBGColor(prompt.DefaultColor), + ) + + input = strings.TrimSpace(input) + + if input == "" { + continue + } + + if input == "exit" || input == "quit" { + fmt.Println("Goodbye!") + break + } + + // Check if it's a PM command (starts with "pm ") + if after, ok := strings.CutPrefix(input, "pm "); ok { + // Strip "pm " prefix and execute as PM command + pmCmd := after + pmCmd = strings.TrimSpace(pmCmd) + + if pmCmd == "" { + continue + } + + args := strings.Fields(pmCmd) + if err := commands.ExecuteWithArgs(args); err != nil { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + } + } else { + // Execute as shell command + cmd := exec.Command("sh", "-c", input) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.Stdin = os.Stdin + + if err := cmd.Run(); err != nil { + continue + } + } + } + + // Restore terminal state + if err := term.Restore(int(os.Stdin.Fd()), oldState); err != nil { + return fmt.Errorf("failed to restore terminal state: %w", err) + } + + return nil +} + +func completer(d prompt.Document) []prompt.Suggest { + text := d.TextBeforeCursor() + words := strings.Fields(text) + + // Only provide PM command completions if input starts with "pm" + if len(words) == 0 { + return nil + } + + // If first word is "pm", provide PM command completions + if words[0] == "pm" { + // Remove "pm" from words to get the actual command + if len(words) == 1 || (len(words) == 2 && !strings.HasSuffix(text, " ")) { + return commandSuggestions(words[1:]) + } + + // Get the PM subcommand + if len(words) >= 2 { + cmd := words[1] + return flagSuggestions(cmd, words[1:], text) + } + } + + return nil +} + +func commandSuggestions(words []string) []prompt.Suggest { + suggestions := []prompt.Suggest{ + {Text: "help", Description: "Show help information"}, + {Text: "create", Description: "Create a new issue"}, + {Text: "describe", Description: "Get issue details by ID"}, + {Text: "list", Description: "List all issues"}, + {Text: "ls", Description: "List all issues"}, + {Text: "search", Description: "Alias for ls"}, + {Text: "get", Description: "Alias for describe"}, + {Text: "read", Description: "Alias for describe"}, + {Text: "add", Description: "Alias for create"}, + } + + if len(words) == 0 { + return suggestions + } + + var filtered []prompt.Suggest + for _, s := range suggestions { + if strings.HasPrefix(s.Text, words[0]) { + filtered = append(filtered, s) + } + } + return filtered +} + +func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { + var flagSuggests []prompt.Suggest + isCompleteWord := strings.HasSuffix(text, " ") + lastWord := "" + if len(words) > 0 && !isCompleteWord { + lastWord = words[len(words)-1] + } + + switch cmd { + case "create", "add": + flagSuggests = []prompt.Suggest{ + {Text: "--desc", Description: "Issue description"}, + {Text: "--status", Description: "Issue status (open, closed, in_progress)"}, + {Text: "--type", Description: "Issue type (bug, feature, task)"}, + {Text: "--priority", Description: "Issue priority (0-5)"}, + } + return filterAndCompleteFlags(flagSuggests, lastWord, words) + + case "ls", "list", "search": + flagSuggests = []prompt.Suggest{ + {Text: "--title", Description: "Filter by title"}, + {Text: "--desc", Description: "Filter by description"}, + {Text: "--status", Description: "Filter by status (open, closed, in_progress)"}, + {Text: "--type", Description: "Filter by type (bug, feature, task)"}, + {Text: "--priority", Description: "Filter by priority (0-5)"}, + {Text: "--limit", Description: "Limit number of results"}, + } + return filterAndCompleteFlags(flagSuggests, lastWord, words) + + case "describe", "get", "read": + return issueIdSuggestions(words) + } + + return nil +} + +func issueIdSuggestions(words []string) []prompt.Suggest { + if len(words) < 2 { + return nil + } + + // Get the partial ID being typed + partial := "" + if len(words) >= 2 { + partial = words[len(words)-1] + } + + issues, _ := commands.GetIssueCompletions(context.Background(), partial) + + var suggestions []prompt.Suggest + for _, issue := range issues { + suggestions = append(suggestions, prompt.Suggest{ + Text: issue.ID, Description: truncate.String(issue.Title, 20), + }) + } + return suggestions +} + +func filterAndCompleteFlags(suggestions []prompt.Suggest, lastWord string, words []string) []prompt.Suggest { + if len(words) >= 2 { + prevWord := words[len(words)-2] + switch prevWord { + case "-s", "--status": + return []prompt.Suggest{ + {Text: "open", Description: "Open status"}, + {Text: "closed", Description: "Closed status"}, + {Text: "in_progress", Description: "In progress status"}, + } + case "-t", "--type": + return []prompt.Suggest{ + {Text: "bug", Description: "Bug issue type"}, + {Text: "feature", Description: "Feature issue type"}, + {Text: "task", Description: "Task issue type"}, + } + case "-p", "--priority": + return []prompt.Suggest{ + {Text: "0", Description: "Lowest priority"}, + {Text: "1", Description: "Low priority"}, + {Text: "2", Description: "Medium-low priority"}, + {Text: "3", Description: "Medium priority"}, + {Text: "4", Description: "High priority"}, + {Text: "5", Description: "Highest priority"}, + } + } + } + + if lastWord == "" { + return suggestions + } + + var filtered []prompt.Suggest + for _, s := range suggestions { + if strings.HasPrefix(s.Text, lastWord) { + filtered = append(filtered, s) + } + } + return filtered +} From 7cf02a758dabfb8647411a58101b9ec1328390ef Mon Sep 17 00:00:00 2001 From: vb Date: Thu, 5 Feb 2026 14:51:19 +0100 Subject: [PATCH 13/60] adding delete command in the file pkg/cli/commands/delete.go --- pkg/cli/commands/delete.go | 47 ++++++++++++++++++++++++++++++++++++++ pkg/cli/commands/root.go | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 pkg/cli/commands/delete.go diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go new file mode 100644 index 0000000..443bc58 --- /dev/null +++ b/pkg/cli/commands/delete.go @@ -0,0 +1,47 @@ +package commands + +import ( + "fmt" + "strings" + + "github.com/LazyBachelor/LazyPM/internal/models" + + "github.com/spf13/cobra" +) + +var deleteCmd = &cobra.Command{ + Use: "delete [id]", + Short: "Delete existing issue", + Long: `Delete an existing issue by its ID.`, + Example: `pm delete issue_id`, + RunE: runDeleteCmd, + Aliases: []string{"del"}, + Args: cobra.MinimumNArgs(1), +} + +func runDeleteCmd(cmd *cobra.Command, args []string) error { + deleteID := strings.Join(args, " ") + + if deleteID == "" { + return fmt.Errorf("issue title cannot be empty") + } + + issue := &models.Issue{ + ID: deleteID, + } + + err := svc.Beads.DeleteIssue(cmd.Context(), issue.ID) + if err != nil { + return fmt.Errorf("error deleting issue: %w", err) + } + + str := fmt.Sprintf("Deleted issue with ID: %s\n", issue.ID) + + if issue.Title != "" { + str += fmt.Sprintf("Title: %s\n", issue.Title) + } + + fmt.Print(str) + + return nil +} diff --git a/pkg/cli/commands/root.go b/pkg/cli/commands/root.go index 9b86fd0..e6a2efb 100644 --- a/pkg/cli/commands/root.go +++ b/pkg/cli/commands/root.go @@ -30,7 +30,7 @@ func ExecuteWithArgs(args []string) error { func init() { rootCmd.AddCommand(createCmd) - + rootCmd.AddCommand(deleteCmd) rootCmd.CompletionOptions.DisableDefaultCmd = false rootCmd.AddGroup(&cobra.Group{ID: "help", Title: "Helping Commands"}) rootCmd.SetCompletionCommandGroupID("help") From cd7f238994b9e6639139c5eaec43829c616fb420 Mon Sep 17 00:00:00 2001 From: vb Date: Thu, 5 Feb 2026 14:52:44 +0100 Subject: [PATCH 14/60] removing redundant reference to issue title --- pkg/cli/commands/delete.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 443bc58..6d95498 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -37,10 +37,6 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error { str := fmt.Sprintf("Deleted issue with ID: %s\n", issue.ID) - if issue.Title != "" { - str += fmt.Sprintf("Title: %s\n", issue.Title) - } - fmt.Print(str) return nil From 268d27ab4e2d28945ff7f1d11d6269b8a28b8a14 Mon Sep 17 00:00:00 2001 From: viljarb Date: Thu, 5 Feb 2026 17:40:25 +0100 Subject: [PATCH 15/60] removing issues.json1 From 5763a26e0a2bc98bd994b4c6357c31c0e4a5aff4 Mon Sep 17 00:00:00 2001 From: viljarb0 <156418063+viljarb0@users.noreply.github.com> Date: Thu, 5 Feb 2026 17:41:28 +0100 Subject: [PATCH 16/60] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/cli/commands/delete.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 6d95498..1792776 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -23,7 +23,7 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error { deleteID := strings.Join(args, " ") if deleteID == "" { - return fmt.Errorf("issue title cannot be empty") + return fmt.Errorf("issue ID cannot be empty") } issue := &models.Issue{ From a0cb60c3ed343b5b34bbf2073e14cad82070d5ed Mon Sep 17 00:00:00 2001 From: viljarb0 <156418063+viljarb0@users.noreply.github.com> Date: Thu, 5 Feb 2026 17:41:40 +0100 Subject: [PATCH 17/60] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/cli/commands/delete.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 1792776..9c52d86 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -22,10 +22,6 @@ var deleteCmd = &cobra.Command{ func runDeleteCmd(cmd *cobra.Command, args []string) error { deleteID := strings.Join(args, " ") - if deleteID == "" { - return fmt.Errorf("issue ID cannot be empty") - } - issue := &models.Issue{ ID: deleteID, } From 74ac39df2107b4cba97f82549b895405aaeb2086 Mon Sep 17 00:00:00 2001 From: viljarb Date: Thu, 5 Feb 2026 17:44:21 +0100 Subject: [PATCH 18/60] modified: pkg/cli/commands/delete.go --- pkg/cli/commands/delete.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 9c52d86..10045c9 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -11,7 +11,7 @@ import ( var deleteCmd = &cobra.Command{ Use: "delete [id]", - Short: "Delete existing issue", + Short: "Delete an existing issue", Long: `Delete an existing issue by its ID.`, Example: `pm delete issue_id`, RunE: runDeleteCmd, From 8ec03bb32093707d38a04b3978a0f0802e077585 Mon Sep 17 00:00:00 2001 From: viljarb Date: Thu, 5 Feb 2026 17:45:51 +0100 Subject: [PATCH 19/60] simplifying the code in pkg/cli/commands/delete.go --- pkg/cli/commands/delete.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 10045c9..2569332 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -4,8 +4,6 @@ import ( "fmt" "strings" - "github.com/LazyBachelor/LazyPM/internal/models" - "github.com/spf13/cobra" ) @@ -22,11 +20,7 @@ var deleteCmd = &cobra.Command{ func runDeleteCmd(cmd *cobra.Command, args []string) error { deleteID := strings.Join(args, " ") - issue := &models.Issue{ - ID: deleteID, - } - - err := svc.Beads.DeleteIssue(cmd.Context(), issue.ID) + err := svc.Beads.DeleteIssue(cmd.Context(), deleteID) if err != nil { return fmt.Errorf("error deleting issue: %w", err) } From 9fceca50338b077f5de6f33192537b4cd7580f26 Mon Sep 17 00:00:00 2001 From: viljarb Date: Thu, 5 Feb 2026 17:46:15 +0100 Subject: [PATCH 20/60] deleted: .beads/issues.jsonl From 80741e0cf5fd0d0d13b1248ed73ae1acffb8633e Mon Sep 17 00:00:00 2001 From: viljarb Date: Thu, 5 Feb 2026 18:01:43 +0100 Subject: [PATCH 21/60] corrected non-existed variable name --- pkg/cli/commands/delete.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 2569332..68fce1b 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -25,7 +25,7 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error { return fmt.Errorf("error deleting issue: %w", err) } - str := fmt.Sprintf("Deleted issue with ID: %s\n", issue.ID) + str := fmt.Sprintf("Deleted issue with ID: %s\n", deleteID) fmt.Print(str) From fbcc929cb992835388fa3b04a369d5c9ecffa0af Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Fri, 6 Feb 2026 13:26:26 +0100 Subject: [PATCH 22/60] add fang --- pkg/cli/commands/root.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/cli/commands/root.go b/pkg/cli/commands/root.go index e6a2efb..f58b224 100644 --- a/pkg/cli/commands/root.go +++ b/pkg/cli/commands/root.go @@ -1,7 +1,11 @@ package commands import ( + "context" + "os" + "github.com/LazyBachelor/LazyPM/internal/service" + "github.com/charmbracelet/fang" "github.com/spf13/cobra" ) @@ -15,7 +19,9 @@ var rootCmd = &cobra.Command{ func Execute(services *service.Services) error { SetServices(services) - return rootCmd.Execute() + return fang.Execute(context.Background(), rootCmd, + fang.WithColorSchemeFunc(fang.AnsiColorScheme), + fang.WithNotifySignal(os.Interrupt, os.Kill)) } func SetServices(services *service.Services) { @@ -25,7 +31,8 @@ func SetServices(services *service.Services) { func ExecuteWithArgs(args []string) error { rootCmd.SetArgs(args) - return rootCmd.Execute() + return fang.Execute(context.Background(), rootCmd, + fang.WithColorSchemeFunc(fang.AnsiColorScheme)) } func init() { From 583fb6be45b8ed175bdf8c90c31178c3b0846664 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Fri, 6 Feb 2026 13:27:07 +0100 Subject: [PATCH 23/60] make the repl experience better --- go.mod | 12 +++++++- go.sum | 22 +++++++++++++-- pkg/cli/repl.go | 75 +++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 97 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 9304c7d..04c7cad 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,9 @@ require ( github.com/a-h/templ v0.3.977 github.com/c-bata/go-prompt v0.2.6 github.com/charmbracelet/bubbletea v1.3.10 + github.com/charmbracelet/fang v0.4.4 github.com/charmbracelet/huh v0.8.0 + github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 github.com/google/uuid v1.6.0 github.com/muesli/reflow v0.3.0 github.com/rs/cors v1.11.1 @@ -18,6 +20,7 @@ require ( ) require ( + charm.land/lipgloss/v2 v2.0.0-beta.3.0.20251106193318-19329a3e8410 // indirect git.sr.ht/~sbinet/gg v0.7.0 // indirect github.com/a-h/parse v0.0.0-20250122154542-74294addb73e // indirect github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b // indirect @@ -31,12 +34,15 @@ require ( github.com/charmbracelet/bubbles v0.21.1 // indirect github.com/charmbracelet/colorprofile v0.4.1 // indirect github.com/charmbracelet/glamour v0.10.0 // indirect - github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 // indirect + github.com/charmbracelet/ultraviolet v0.0.0-20251106190538-99ea45596692 // indirect github.com/charmbracelet/x/ansi v0.11.5 // indirect github.com/charmbracelet/x/cellbuf v0.0.15 // indirect + github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444 // indirect github.com/charmbracelet/x/exp/slice v0.0.0-20260203065841-a1c614051099 // indirect github.com/charmbracelet/x/exp/strings v0.1.0 // indirect github.com/charmbracelet/x/term v0.2.2 // indirect + github.com/charmbracelet/x/termios v0.1.1 // indirect + github.com/charmbracelet/x/windows v0.2.2 // indirect github.com/cli/browser v1.3.0 // indirect github.com/clipperhouse/displaywidth v0.9.0 // indirect github.com/clipperhouse/stringish v0.1.1 // indirect @@ -62,6 +68,10 @@ require ( github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect + github.com/muesli/mango v0.1.0 // indirect + github.com/muesli/mango-cobra v1.2.0 // indirect + github.com/muesli/mango-pflag v0.1.0 // indirect + github.com/muesli/roff v0.1.0 // indirect github.com/muesli/termenv v0.16.0 // indirect github.com/natefinch/atomic v1.0.1 // indirect github.com/ncruces/go-sqlite3 v0.30.5 // indirect diff --git a/go.sum b/go.sum index 9ec6f9e..dba30f8 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +charm.land/lipgloss/v2 v2.0.0-beta.3.0.20251106193318-19329a3e8410 h1:D9PbaszZYpB4nj+d6HTWr1onlmlyuGVNfL9gAi8iB3k= +charm.land/lipgloss/v2 v2.0.0-beta.3.0.20251106193318-19329a3e8410/go.mod h1:1qZyvvVCenJO2M1ac2mX0yyiIZJoZmDM4DG4s0udJkU= git.sr.ht/~sbinet/cmpimg v0.1.0 h1:E0zPRk2muWuCqSKSVZIWsgtU9pjsw3eKHi8VmQeScxo= git.sr.ht/~sbinet/cmpimg v0.1.0/go.mod h1:FU12psLbF4TfNXkKH2ZZQ29crIqoiqTZmeQ7dkp/pxE= git.sr.ht/~sbinet/gg v0.7.0 h1:YmNf7YKd7diDMTPm86hZa1EM3pbkOyD/zzjl0LZUdNM= @@ -45,12 +47,16 @@ github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlv github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4= github.com/charmbracelet/colorprofile v0.4.1 h1:a1lO03qTrSIRaK8c3JRxJDZOvhvIeSco3ej+ngLk1kk= github.com/charmbracelet/colorprofile v0.4.1/go.mod h1:U1d9Dljmdf9DLegaJ0nGZNJvoXAhayhmidOdcBwAvKk= +github.com/charmbracelet/fang v0.4.4 h1:G4qKxF6or/eTPgmAolwPuRNyuci3hTUGGX1rj1YkHJY= +github.com/charmbracelet/fang v0.4.4/go.mod h1:P5/DNb9DddQ0Z0dbc0P3ol4/ix5Po7Ofr2KMBfAqoCo= github.com/charmbracelet/glamour v0.10.0 h1:MtZvfwsYCx8jEPFJm3rIBFIMZUfUJ765oX8V6kXldcY= github.com/charmbracelet/glamour v0.10.0/go.mod h1:f+uf+I/ChNmqo087elLnVdCiVgjSKWuXa/l6NU2ndYk= github.com/charmbracelet/huh v0.8.0 h1:Xz/Pm2h64cXQZn/Jvele4J3r7DDiqFCNIVteYukxDvY= github.com/charmbracelet/huh v0.8.0/go.mod h1:5YVc+SlZ1IhQALxRPpkGwwEKftN/+OlJlnJYlDRFqN4= github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834 h1:ZR7e0ro+SZZiIZD7msJyA+NjkCNNavuiPBLgerbOziE= github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834/go.mod h1:aKC/t2arECF6rNOnaKaVU6y4t4ZeHQzqfxedE/VkVhA= +github.com/charmbracelet/ultraviolet v0.0.0-20251106190538-99ea45596692 h1:r/3jQZ1LjWW6ybp8HHfhrKrwHIWiJhUuY7wwYIWZulQ= +github.com/charmbracelet/ultraviolet v0.0.0-20251106190538-99ea45596692/go.mod h1:Y8B4DzWeTb0ama8l3+KyopZtkE8fZjwRQ3aEAPEXHE0= github.com/charmbracelet/x/ansi v0.11.5 h1:NBWeBpj/lJPE3Q5l+Lusa4+mH6v7487OP8K0r1IhRg4= github.com/charmbracelet/x/ansi v0.11.5/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ= github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI= @@ -59,8 +65,10 @@ github.com/charmbracelet/x/conpty v0.1.0 h1:4zc8KaIcbiL4mghEON8D72agYtSeIgq8FSTh github.com/charmbracelet/x/conpty v0.1.0/go.mod h1:rMFsDJoDwVmiYM10aD4bH2XiRgwI7NYJtQgl5yskjEQ= github.com/charmbracelet/x/errors v0.0.0-20240508181413-e8d8b6e2de86 h1:JSt3B+U9iqk37QUU2Rvb6DSBYRLtWqFqfxf8l5hOZUA= github.com/charmbracelet/x/errors v0.0.0-20240508181413-e8d8b6e2de86/go.mod h1:2P0UgXMEa6TsToMSuFqKFQR+fZTO9CNGUNokkPatT/0= -github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91 h1:payRxjMjKgx2PaCWLZ4p3ro9y97+TVLZNaRZgJwSVDQ= -github.com/charmbracelet/x/exp/golden v0.0.0-20241011142426-46044092ad91/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U= +github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444 h1:IJDiTgVE56gkAGfq0lBEloWgkXMk4hl/bmuPoicI4R0= +github.com/charmbracelet/x/exp/charmtone v0.0.0-20250603201427-c31516f43444/go.mod h1:T9jr8CzFpjhFVHjNjKwbAD7KwBNyFnj2pntAO7F2zw0= +github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f h1:pk6gmGpCE7F3FcjaOEKYriCvpmIN4+6OS/RD0vm4uIA= +github.com/charmbracelet/x/exp/golden v0.0.0-20250806222409-83e3a29d542f/go.mod h1:IfZAMTHB6XkZSeXUqriemErjAWCCzT0LwjKFYCZyw0I= github.com/charmbracelet/x/exp/slice v0.0.0-20260203065841-a1c614051099 h1:H09krOypYvXsPG4kYl+9J3tCRhST8WI3WEpXJELw+eg= github.com/charmbracelet/x/exp/slice v0.0.0-20260203065841-a1c614051099/go.mod h1:vqEfX6xzqW1pKKZUUiFOKg0OQ7bCh54Q2vR/tserrRA= github.com/charmbracelet/x/exp/strings v0.1.0 h1:i69S2XI7uG1u4NLGeJPSYU++Nmjvpo9nwd6aoEm7gkA= @@ -69,6 +77,8 @@ github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSg github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI= github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8JawjaNZY= github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo= +github.com/charmbracelet/x/windows v0.2.2 h1:IofanmuvaxnKHuV04sC0eBy/smG6kIKrWG2/jYn2GuM= +github.com/charmbracelet/x/windows v0.2.2/go.mod h1:/8XtdKZzedat74NQFn0NGlGL4soHB0YQZrETF96h75k= github.com/charmbracelet/x/xpty v0.1.2 h1:Pqmu4TEJ8KeA9uSkISKMU3f+C1F6OGBn8ABuGlqCbtI= github.com/charmbracelet/x/xpty v0.1.2/go.mod h1:XK2Z0id5rtLWcpeNiMYBccNNBrP2IJnzHI0Lq13Xzq4= github.com/cli/browser v1.3.0 h1:LejqCrpWr+1pRqmEPDGnTZOjsMe7sehifLynZJuqJpo= @@ -155,8 +165,16 @@ github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= +github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI= +github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4= +github.com/muesli/mango-cobra v1.2.0 h1:DQvjzAM0PMZr85Iv9LIMaYISpTOliMEg+uMFtNbYvWg= +github.com/muesli/mango-cobra v1.2.0/go.mod h1:vMJL54QytZAJhCT13LPVDfkvCUJ5/4jNUKF/8NC2UjA= +github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg= +github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0= github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= +github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8= +github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig= github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= github.com/natefinch/atomic v1.0.1 h1:ZPYKxkqQOx3KZ+RsbnP/YsgvxWQPGxjC0oBt2AhwV0A= diff --git a/pkg/cli/repl.go b/pkg/cli/repl.go index 5455b16..1858f38 100644 --- a/pkg/cli/repl.go +++ b/pkg/cli/repl.go @@ -11,6 +11,7 @@ import ( "github.com/LazyBachelor/LazyPM/pkg" "github.com/LazyBachelor/LazyPM/pkg/cli/commands" "github.com/c-bata/go-prompt" + "github.com/charmbracelet/lipgloss" "github.com/muesli/reflow/truncate" "golang.org/x/term" ) @@ -29,13 +30,22 @@ func RunREPL(ctx context.Context, config pkg.SurveyConfig) error { commands.SetServices(svc) - fmt.Printf("Welcome to Project Management CLI! Type 'pm help' for available commands.\n") - fmt.Printf("You can also run shell commands directly. Type 'exit' or 'quit' to leave.\n") + titleStyle := lipgloss.NewStyle().Align(lipgloss.Center).Bold(true).Border(lipgloss.RoundedBorder()).Padding(1).Foreground(lipgloss.Color("6")) + + title := `Welcome to Project Management CLI! Type 'pm help' for available commands. +You can also run shell commands directly. Type 'exit' or 'quit' to leave.` + + fmt.Print("") + fmt.Println(titleStyle.Render(title)) + + // Create persistent history + var history []string for { input := prompt.Input( "› ", completer, + prompt.OptionPrefixTextColor(prompt.Cyan), prompt.OptionMaxSuggestion(5), prompt.OptionSuggestionBGColor(prompt.DefaultColor), prompt.OptionSelectedSuggestionBGColor(prompt.DefaultColor), @@ -43,6 +53,7 @@ func RunREPL(ctx context.Context, config pkg.SurveyConfig) error { prompt.OptionSelectedDescriptionBGColor(prompt.DefaultColor), prompt.OptionPreviewSuggestionBGColor(prompt.DefaultColor), prompt.OptionScrollbarBGColor(prompt.DefaultColor), + prompt.OptionHistory(history), ) input = strings.TrimSpace(input) @@ -56,6 +67,19 @@ func RunREPL(ctx context.Context, config pkg.SurveyConfig) error { break } + if input == "help" { + fmt.Println("Type 'pm help' for available PM commands.\nYou can also run shell commands directly. Type 'exit' or 'quit' to leave.") + continue + } + + if input == "title" { + fmt.Println(titleStyle.Render(title)) + continue + } + + // Add to history + history = append(history, input) + // Check if it's a PM command (starts with "pm ") if after, ok := strings.CutPrefix(input, "pm "); ok { // Strip "pm " prefix and execute as PM command @@ -72,14 +96,26 @@ func RunREPL(ctx context.Context, config pkg.SurveyConfig) error { } } else { // Execute as shell command + // Save terminal state before shell command + state, _ := term.GetState(int(os.Stdin.Fd())) + cmd := exec.Command("sh", "-c", input) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr cmd.Stdin = os.Stdin if err := cmd.Run(); err != nil { + // Restore terminal state even on error + if state != nil { + term.Restore(int(os.Stdin.Fd()), state) + } continue } + + // Restore terminal state for go-prompt + if state != nil { + term.Restore(int(os.Stdin.Fd()), state) + } } } @@ -95,11 +131,33 @@ func completer(d prompt.Document) []prompt.Suggest { text := d.TextBeforeCursor() words := strings.Fields(text) - // Only provide PM command completions if input starts with "pm" if len(words) == 0 { return nil } + if words[0] != "pm" { + suggestions := []prompt.Suggest{ + {Text: "pm", Description: "Project Management System"}, + {Text: "exit", Description: "Exit pm CLI"}, + {Text: "help", Description: "Show help information"}, + {Text: "title", Description: "Print the welcome title"}, + {Text: "git", Description: "Version control system"}, + } + + if len(words) == 0 { + return suggestions + } + + var filtered []prompt.Suggest + for _, s := range suggestions { + if strings.HasPrefix(s.Text, words[0]) { + filtered = append(filtered, s) + } + } + + return filtered + } + // If first word is "pm", provide PM command completions if words[0] == "pm" { // Remove "pm" from words to get the actual command @@ -120,14 +178,10 @@ func completer(d prompt.Document) []prompt.Suggest { func commandSuggestions(words []string) []prompt.Suggest { suggestions := []prompt.Suggest{ {Text: "help", Description: "Show help information"}, - {Text: "create", Description: "Create a new issue"}, + {Text: "delete", Description: "Delete an issue by ID"}, + {Text: "create", Description: "Create a new issue with title"}, {Text: "describe", Description: "Get issue details by ID"}, {Text: "list", Description: "List all issues"}, - {Text: "ls", Description: "List all issues"}, - {Text: "search", Description: "Alias for ls"}, - {Text: "get", Description: "Alias for describe"}, - {Text: "read", Description: "Alias for describe"}, - {Text: "add", Description: "Alias for create"}, } if len(words) == 0 { @@ -174,6 +228,9 @@ func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { case "describe", "get", "read": return issueIdSuggestions(words) + + case "delete": + return issueIdSuggestions(words) } return nil From 5a89526dadb6554a1a0f4f1fac61f8c69d241a3d Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Fri, 6 Feb 2026 23:29:58 +0100 Subject: [PATCH 24/60] style repl better better usability to repl --- pkg/cli/repl/repl.go | 290 +++++++++++++++++++++++++++++++++++++++ pkg/cli/styles/styles.go | 12 ++ 2 files changed, 302 insertions(+) create mode 100644 pkg/cli/repl/repl.go create mode 100644 pkg/cli/styles/styles.go diff --git a/pkg/cli/repl/repl.go b/pkg/cli/repl/repl.go new file mode 100644 index 0000000..796f4fb --- /dev/null +++ b/pkg/cli/repl/repl.go @@ -0,0 +1,290 @@ +package repl + +import ( + "context" + "fmt" + "os" + "os/exec" + "strings" + + "github.com/LazyBachelor/LazyPM/internal/service" + "github.com/LazyBachelor/LazyPM/pkg/cli" + "github.com/LazyBachelor/LazyPM/pkg/cli/commands" + "github.com/LazyBachelor/LazyPM/pkg/cli/styles" + "github.com/c-bata/go-prompt" + "github.com/muesli/reflow/truncate" + "golang.org/x/term" +) + +const ( + ReplHelp = `Type 'pm help' for available PM commands. +You can also run shell commands directly. Type 'exit' or 'quit' to leave.` + + ReplTitle = "Welcome to Project Management CLI! " + ReplHelp +) + +func RunREPL(ctx context.Context, config cli.CLIConfig) error { + oldState, err := term.GetState(int(os.Stdin.Fd())) + if err != nil { + return fmt.Errorf("failed to get terminal state: %w", err) + } + + svc, cleanup, err := service.NewServices(ctx, config) + if err != nil { + return fmt.Errorf("failed to initialize services: %w", err) + } + defer cleanup() + + commands.SetServices(svc) + + fmt.Println("\n" + styles.TitleStyle.Render(ReplTitle)) + + var history []string + + for { + input := prompt.Input( + "› ", + completer, + prompt.OptionPrefixTextColor(prompt.Cyan), + prompt.OptionMaxSuggestion(5), + prompt.OptionSuggestionBGColor(prompt.DefaultColor), + prompt.OptionSelectedSuggestionBGColor(prompt.DefaultColor), + prompt.OptionDescriptionBGColor(prompt.DefaultColor), + prompt.OptionSelectedDescriptionBGColor(prompt.DefaultColor), + prompt.OptionPreviewSuggestionBGColor(prompt.DefaultColor), + prompt.OptionScrollbarBGColor(prompt.DefaultColor), + prompt.OptionHistory(history), + ) + + input = strings.TrimSpace(input) + + if input == "" { + continue + } + + if input == "exit" || input == "quit" { + fmt.Println("Goodbye!") + break + } + + if input == "help" { + fmt.Println(ReplHelp) + continue + } + + if input == "title" { + fmt.Println(styles.TitleStyle.Render(ReplTitle)) + continue + } + + history = append(history, input) + + if after, ok := strings.CutPrefix(input, "pm "); ok { + pmCmd := strings.TrimSpace(after) + if pmCmd == "" { + continue + } + + args := strings.Fields(pmCmd) + + output, err := commands.ExecuteArgsString(args) + if err != nil { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + } + + if output != "" { + fmt.Println(styles.CommandStyle.Render(output)) + } + + } else { + cmd := exec.Command("sh", "-c", input) + out, err := cmd.CombinedOutput() + + if len(out) > 0 { + fmt.Println(styles.CommandStyle.Render(string(out))) + } + + if err != nil && len(out) == 0 { + fmt.Fprintf(os.Stderr, "%s", fmt.Sprintf("Error: %v", err)) + } + } + } + + if err := term.Restore(int(os.Stdin.Fd()), oldState); err != nil { + return fmt.Errorf("failed to restore terminal state: %w", err) + } + + return nil +} + +func completer(d prompt.Document) []prompt.Suggest { + text := d.TextBeforeCursor() + words := strings.Fields(text) + + if len(words) == 0 { + return nil + } + + if words[0] != "pm" { + suggestions := []prompt.Suggest{ + {Text: "pm", Description: "Project Management System"}, + {Text: "exit", Description: "Exit pm CLI"}, + {Text: "help", Description: "Show help information"}, + {Text: "title", Description: "Print the welcome title"}, + {Text: "git", Description: "Version control system"}, + } + + if len(words) == 0 { + return suggestions + } + + var filtered []prompt.Suggest + for _, s := range suggestions { + if strings.HasPrefix(s.Text, words[0]) { + filtered = append(filtered, s) + } + } + + return filtered + } + + // If first word is "pm", provide PM command completions + if words[0] == "pm" { + // Remove "pm" from words to get the actual command + if len(words) == 1 || (len(words) == 2 && !strings.HasSuffix(text, " ")) { + return commandSuggestions(words[1:]) + } + + // Get the PM subcommand + if len(words) >= 2 { + cmd := words[1] + return flagSuggestions(cmd, words[1:], text) + } + } + + return nil +} + +func commandSuggestions(words []string) []prompt.Suggest { + suggestions := []prompt.Suggest{ + {Text: "help", Description: "Show help information"}, + {Text: "delete", Description: "Delete an issue by ID"}, + {Text: "create", Description: "Create a new issue with title"}, + {Text: "describe", Description: "Get issue details by ID"}, + {Text: "list", Description: "List all issues"}, + } + + if len(words) == 0 { + return suggestions + } + + var filtered []prompt.Suggest + for _, s := range suggestions { + if strings.HasPrefix(s.Text, words[0]) { + filtered = append(filtered, s) + } + } + return filtered +} + +func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { + var flagSuggests []prompt.Suggest + isCompleteWord := strings.HasSuffix(text, " ") + lastWord := "" + if len(words) > 0 && !isCompleteWord { + lastWord = words[len(words)-1] + } + + switch cmd { + case "create", "add": + flagSuggests = []prompt.Suggest{ + {Text: "--desc", Description: "Issue description"}, + {Text: "--status", Description: "Issue status (open, closed, in_progress)"}, + {Text: "--type", Description: "Issue type (bug, feature, task)"}, + {Text: "--priority", Description: "Issue priority (0-5)"}, + } + return filterAndCompleteFlags(flagSuggests, lastWord, words) + + case "ls", "list", "search": + flagSuggests = []prompt.Suggest{ + {Text: "--title", Description: "Filter by title"}, + {Text: "--desc", Description: "Filter by description"}, + {Text: "--status", Description: "Filter by status (open, closed, in_progress)"}, + {Text: "--type", Description: "Filter by type (bug, feature, task)"}, + {Text: "--priority", Description: "Filter by priority (0-5)"}, + {Text: "--limit", Description: "Limit number of results"}, + } + return filterAndCompleteFlags(flagSuggests, lastWord, words) + + case "describe", "get", "read": + return issueIdSuggestions(words) + + case "delete": + return issueIdSuggestions(words) + } + + return nil +} + +func issueIdSuggestions(words []string) []prompt.Suggest { + if len(words) < 2 { + return nil + } + + // Get the partial ID being typed + partial := "" + if len(words) >= 2 { + partial = words[len(words)-1] + } + + issues, _ := commands.GetIssueCompletions(context.Background(), partial) + + var suggestions []prompt.Suggest + for _, issue := range issues { + suggestions = append(suggestions, prompt.Suggest{ + Text: issue.ID, Description: truncate.String(issue.Title, 20), + }) + } + return suggestions +} + +func filterAndCompleteFlags(suggestions []prompt.Suggest, lastWord string, words []string) []prompt.Suggest { + if len(words) >= 2 { + prevWord := words[len(words)-2] + switch prevWord { + case "-s", "--status": + return []prompt.Suggest{ + {Text: "open", Description: "Open status"}, + {Text: "closed", Description: "Closed status"}, + {Text: "in_progress", Description: "In progress status"}, + } + case "-t", "--type": + return []prompt.Suggest{ + {Text: "bug", Description: "Bug issue type"}, + {Text: "feature", Description: "Feature issue type"}, + {Text: "task", Description: "Task issue type"}, + } + case "-p", "--priority": + return []prompt.Suggest{ + {Text: "0", Description: "Lowest priority"}, + {Text: "1", Description: "Low priority"}, + {Text: "2", Description: "Medium-low priority"}, + {Text: "3", Description: "Medium priority"}, + {Text: "4", Description: "High priority"}, + {Text: "5", Description: "Highest priority"}, + } + } + } + + if lastWord == "" { + return suggestions + } + + var filtered []prompt.Suggest + for _, s := range suggestions { + if strings.HasPrefix(s.Text, lastWord) { + filtered = append(filtered, s) + } + } + return filtered +} diff --git a/pkg/cli/styles/styles.go b/pkg/cli/styles/styles.go new file mode 100644 index 0000000..067534b --- /dev/null +++ b/pkg/cli/styles/styles.go @@ -0,0 +1,12 @@ +package styles + +import "github.com/charmbracelet/lipgloss" + +var ( + TitleStyle = lipgloss.NewStyle(). + Foreground(lipgloss.Color("6")). + Bold(true).Border(lipgloss.RoundedBorder()). + BorderForeground(lipgloss.Color("12")).Padding(1) + + CommandStyle = lipgloss.NewStyle().Padding(1) +) From ac6928f167f4806086d499d84c60e0c0cdbb11ba Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Fri, 6 Feb 2026 23:30:13 +0100 Subject: [PATCH 25/60] add repl and cli to survey --- cmd/survey.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/survey.go b/cmd/survey.go index 8b90fb8..a6a9922 100644 --- a/cmd/survey.go +++ b/cmd/survey.go @@ -7,6 +7,7 @@ import ( "github.com/LazyBachelor/LazyPM/pkg" "github.com/LazyBachelor/LazyPM/pkg/cli" + "github.com/LazyBachelor/LazyPM/pkg/cli/repl" "github.com/LazyBachelor/LazyPM/pkg/tui" "github.com/LazyBachelor/LazyPM/pkg/web" ) @@ -27,7 +28,9 @@ func main() { case "tui": err = tui.Run(ctx, config) case "cli": - err = cli.RunREPL(ctx, config) + err = cli.RunWithArgs(ctx, config, os.Args[2:]) + case "repl": + err = repl.RunREPL(ctx, config) case "web": err = web.Run(ctx, config) default: From d962ab93140acd8c2607915cca1ceb15209918f0 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Fri, 6 Feb 2026 23:30:59 +0100 Subject: [PATCH 26/60] add run with args for running as sub command --- pkg/cli/cli.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 13b0161..e26ef0f 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -1,23 +1,42 @@ package cli import ( + "context" + "github.com/LazyBachelor/LazyPM/internal/service" "github.com/LazyBachelor/LazyPM/pkg/cli/commands" - "context" ) type CLIConfig = service.Config func Run(ctx context.Context, config CLIConfig) error { svc, cleanup, err := service.NewServices(ctx, config) - if err != nil { return err } defer cleanup() - if err := commands.Execute(svc); err != nil { + commands.SetServices(svc) + + if err := commands.Execute(); err != nil { + return err + } + + return nil +} + +func RunWithArgs(ctx context.Context, config CLIConfig, args []string) error { + svc, cleanup, err := service.NewServices(ctx, config) + if err != nil { + return err + } + + defer cleanup() + + commands.SetServices(svc) + + if err := commands.ExecuteArgs(args); err != nil { return err } From 3d2c522ce8df4dc5cbdaa99b2e8dd2293179452a Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Fri, 6 Feb 2026 23:31:51 +0100 Subject: [PATCH 27/60] document root command and add different execute options --- pkg/cli/commands/root.go | 42 ++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/pkg/cli/commands/root.go b/pkg/cli/commands/root.go index f58b224..418d7ae 100644 --- a/pkg/cli/commands/root.go +++ b/pkg/cli/commands/root.go @@ -1,8 +1,8 @@ package commands import ( + "bytes" "context" - "os" "github.com/LazyBachelor/LazyPM/internal/service" "github.com/charmbracelet/fang" @@ -10,35 +10,53 @@ import ( "github.com/spf13/cobra" ) +// svc is a global variable that holds beads, config and stats services. +// Must be called before executing any commands to ensure services are available. var svc *service.Services +// rootCmd is the base command for the CLI application. var rootCmd = &cobra.Command{ Short: "Project Management CLI", Long: `Project Management CLI for managing issues and tasks.`, } -func Execute(services *service.Services) error { - SetServices(services) - return fang.Execute(context.Background(), rootCmd, - fang.WithColorSchemeFunc(fang.AnsiColorScheme), - fang.WithNotifySignal(os.Interrupt, os.Kill)) -} - +// SetServices sets the global services variable for use in command execution. +// Must be called before executing any commands to ensure services are available. func SetServices(services *service.Services) { svc = services rootCmd.Use = svc.Config.RootCmd } -func ExecuteWithArgs(args []string) error { +// Execute executes the root command using the fang library. +func Execute() error { + return fang.Execute(context.Background(), rootCmd, + fang.WithColorSchemeFunc(fang.AnsiColorScheme)) +} + +// ExecuteArgs executes the command with the given arguments using the fang library. +func ExecuteArgs(args []string) error { rootCmd.SetArgs(args) return fang.Execute(context.Background(), rootCmd, fang.WithColorSchemeFunc(fang.AnsiColorScheme)) } +// ExecuteArgsString executes the command with the given arguments and returns the output as a string. +// This is useful for testing command outputs and used in the REPL +func ExecuteArgsString(args []string) (string, error) { + buf := new(bytes.Buffer) + + rootCmd.SetOut(buf) + rootCmd.SetErr(buf) + rootCmd.SetArgs(args) + + err := rootCmd.Execute() + + return buf.String(), err +} + +// init function to set up the command hierarchy and options. func init() { - rootCmd.AddCommand(createCmd) - rootCmd.AddCommand(deleteCmd) - rootCmd.CompletionOptions.DisableDefaultCmd = false + rootCmd.CompletionOptions.DisableDefaultCmd = true rootCmd.AddGroup(&cobra.Group{ID: "help", Title: "Helping Commands"}) rootCmd.SetCompletionCommandGroupID("help") rootCmd.SetHelpCommandGroupID("help") From 3cb211f8985c79a75b9e4025e14a749f428cfadc Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Fri, 6 Feb 2026 23:32:17 +0100 Subject: [PATCH 28/60] refactor create command for better readability --- pkg/cli/commands/create.go | 57 +++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/pkg/cli/commands/create.go b/pkg/cli/commands/create.go index ea2e529..6f95f00 100644 --- a/pkg/cli/commands/create.go +++ b/pkg/cli/commands/create.go @@ -16,34 +16,20 @@ var ( createPriority int ) +const ( + createCmdExample = `pm create New issue -d "Description" -s open -t task -p 3 +pm create Fix bug --desc "Bug description" --status in_progress --type bug --priority 5` +) + var createCmd = &cobra.Command{ - Use: "create [title]", - Short: "Create a new issue", - Long: `Create a new issue with the specified details.`, - Example: `pm create New issue -d "Description" -s open -t task -p 3 -pm create Fix bug --desc "Bug description" --status in_progress --type bug --priority 5`, - RunE: runCreateCmd, + Use: "create [title]", + Short: "Create a new issue", + Long: `Create a new issue with the specified details.`, + Example: createCmdExample, + Aliases: []string{"add"}, Args: cobra.MinimumNArgs(1), -} - -func init() { - createCmd.Flags().StringVarP(&createDescription, "desc", "d", "", "Issue description") - createCmd.Flags().StringVarP(&createStatus, "status", "s", "open", "Issue status(open, closed, in_progress)") - createCmd.Flags().StringVarP(&createType, "type", "t", "task", "Issue type(bug, feature, task)") - createCmd.Flags().IntVarP(&createPriority, "priority", "p", 0, "Issue priority(0-5)") - - createCmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"bug", "feature", "task"}, cobra.ShellCompDirectiveDefault - }) - - createCmd.RegisterFlagCompletionFunc("status", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"open", "closed", "in_progress"}, cobra.ShellCompDirectiveDefault - }) - - createCmd.RegisterFlagCompletionFunc("priority", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"0", "1", "2", "3", "4", "5"}, cobra.ShellCompDirectiveDefault - }) + RunE: runCreateCmd, } func runCreateCmd(cmd *cobra.Command, args []string) error { @@ -92,3 +78,24 @@ func runCreateCmd(cmd *cobra.Command, args []string) error { return nil } + +func init() { + createCmd.Flags().StringVarP(&createDescription, "desc", "d", "", "Issue description") + createCmd.Flags().StringVarP(&createStatus, "status", "s", "open", "Issue status(open, closed, in_progress)") + createCmd.Flags().StringVarP(&createType, "type", "t", "task", "Issue type(bug, feature, task)") + createCmd.Flags().IntVarP(&createPriority, "priority", "p", 0, "Issue priority(0-5)") + + createCmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"bug", "feature", "task"}, cobra.ShellCompDirectiveDefault + }) + + createCmd.RegisterFlagCompletionFunc("status", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"open", "closed", "in_progress"}, cobra.ShellCompDirectiveDefault + }) + + createCmd.RegisterFlagCompletionFunc("priority", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"0", "1", "2", "3", "4", "5"}, cobra.ShellCompDirectiveDefault + }) + + rootCmd.AddCommand(createCmd) +} From 33ac4c8eaa297a7e48e96ab8e7715651a965b4bf Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Fri, 6 Feb 2026 23:32:40 +0100 Subject: [PATCH 29/60] move repl file --- pkg/cli/repl.go | 300 ------------------------------------------------ 1 file changed, 300 deletions(-) delete mode 100644 pkg/cli/repl.go diff --git a/pkg/cli/repl.go b/pkg/cli/repl.go deleted file mode 100644 index 1858f38..0000000 --- a/pkg/cli/repl.go +++ /dev/null @@ -1,300 +0,0 @@ -package cli - -import ( - "context" - "fmt" - "os" - "os/exec" - "strings" - - "github.com/LazyBachelor/LazyPM/internal/service" - "github.com/LazyBachelor/LazyPM/pkg" - "github.com/LazyBachelor/LazyPM/pkg/cli/commands" - "github.com/c-bata/go-prompt" - "github.com/charmbracelet/lipgloss" - "github.com/muesli/reflow/truncate" - "golang.org/x/term" -) - -func RunREPL(ctx context.Context, config pkg.SurveyConfig) error { - oldState, err := term.GetState(int(os.Stdin.Fd())) - if err != nil { - return fmt.Errorf("failed to get terminal state: %w", err) - } - - svc, cleanup, err := service.NewServices(ctx, config) - if err != nil { - return fmt.Errorf("failed to initialize services: %w", err) - } - defer cleanup() - - commands.SetServices(svc) - - titleStyle := lipgloss.NewStyle().Align(lipgloss.Center).Bold(true).Border(lipgloss.RoundedBorder()).Padding(1).Foreground(lipgloss.Color("6")) - - title := `Welcome to Project Management CLI! Type 'pm help' for available commands. -You can also run shell commands directly. Type 'exit' or 'quit' to leave.` - - fmt.Print("") - fmt.Println(titleStyle.Render(title)) - - // Create persistent history - var history []string - - for { - input := prompt.Input( - "› ", - completer, - prompt.OptionPrefixTextColor(prompt.Cyan), - prompt.OptionMaxSuggestion(5), - prompt.OptionSuggestionBGColor(prompt.DefaultColor), - prompt.OptionSelectedSuggestionBGColor(prompt.DefaultColor), - prompt.OptionDescriptionBGColor(prompt.DefaultColor), - prompt.OptionSelectedDescriptionBGColor(prompt.DefaultColor), - prompt.OptionPreviewSuggestionBGColor(prompt.DefaultColor), - prompt.OptionScrollbarBGColor(prompt.DefaultColor), - prompt.OptionHistory(history), - ) - - input = strings.TrimSpace(input) - - if input == "" { - continue - } - - if input == "exit" || input == "quit" { - fmt.Println("Goodbye!") - break - } - - if input == "help" { - fmt.Println("Type 'pm help' for available PM commands.\nYou can also run shell commands directly. Type 'exit' or 'quit' to leave.") - continue - } - - if input == "title" { - fmt.Println(titleStyle.Render(title)) - continue - } - - // Add to history - history = append(history, input) - - // Check if it's a PM command (starts with "pm ") - if after, ok := strings.CutPrefix(input, "pm "); ok { - // Strip "pm " prefix and execute as PM command - pmCmd := after - pmCmd = strings.TrimSpace(pmCmd) - - if pmCmd == "" { - continue - } - - args := strings.Fields(pmCmd) - if err := commands.ExecuteWithArgs(args); err != nil { - fmt.Fprintf(os.Stderr, "Error: %v\n", err) - } - } else { - // Execute as shell command - // Save terminal state before shell command - state, _ := term.GetState(int(os.Stdin.Fd())) - - cmd := exec.Command("sh", "-c", input) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - cmd.Stdin = os.Stdin - - if err := cmd.Run(); err != nil { - // Restore terminal state even on error - if state != nil { - term.Restore(int(os.Stdin.Fd()), state) - } - continue - } - - // Restore terminal state for go-prompt - if state != nil { - term.Restore(int(os.Stdin.Fd()), state) - } - } - } - - // Restore terminal state - if err := term.Restore(int(os.Stdin.Fd()), oldState); err != nil { - return fmt.Errorf("failed to restore terminal state: %w", err) - } - - return nil -} - -func completer(d prompt.Document) []prompt.Suggest { - text := d.TextBeforeCursor() - words := strings.Fields(text) - - if len(words) == 0 { - return nil - } - - if words[0] != "pm" { - suggestions := []prompt.Suggest{ - {Text: "pm", Description: "Project Management System"}, - {Text: "exit", Description: "Exit pm CLI"}, - {Text: "help", Description: "Show help information"}, - {Text: "title", Description: "Print the welcome title"}, - {Text: "git", Description: "Version control system"}, - } - - if len(words) == 0 { - return suggestions - } - - var filtered []prompt.Suggest - for _, s := range suggestions { - if strings.HasPrefix(s.Text, words[0]) { - filtered = append(filtered, s) - } - } - - return filtered - } - - // If first word is "pm", provide PM command completions - if words[0] == "pm" { - // Remove "pm" from words to get the actual command - if len(words) == 1 || (len(words) == 2 && !strings.HasSuffix(text, " ")) { - return commandSuggestions(words[1:]) - } - - // Get the PM subcommand - if len(words) >= 2 { - cmd := words[1] - return flagSuggestions(cmd, words[1:], text) - } - } - - return nil -} - -func commandSuggestions(words []string) []prompt.Suggest { - suggestions := []prompt.Suggest{ - {Text: "help", Description: "Show help information"}, - {Text: "delete", Description: "Delete an issue by ID"}, - {Text: "create", Description: "Create a new issue with title"}, - {Text: "describe", Description: "Get issue details by ID"}, - {Text: "list", Description: "List all issues"}, - } - - if len(words) == 0 { - return suggestions - } - - var filtered []prompt.Suggest - for _, s := range suggestions { - if strings.HasPrefix(s.Text, words[0]) { - filtered = append(filtered, s) - } - } - return filtered -} - -func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { - var flagSuggests []prompt.Suggest - isCompleteWord := strings.HasSuffix(text, " ") - lastWord := "" - if len(words) > 0 && !isCompleteWord { - lastWord = words[len(words)-1] - } - - switch cmd { - case "create", "add": - flagSuggests = []prompt.Suggest{ - {Text: "--desc", Description: "Issue description"}, - {Text: "--status", Description: "Issue status (open, closed, in_progress)"}, - {Text: "--type", Description: "Issue type (bug, feature, task)"}, - {Text: "--priority", Description: "Issue priority (0-5)"}, - } - return filterAndCompleteFlags(flagSuggests, lastWord, words) - - case "ls", "list", "search": - flagSuggests = []prompt.Suggest{ - {Text: "--title", Description: "Filter by title"}, - {Text: "--desc", Description: "Filter by description"}, - {Text: "--status", Description: "Filter by status (open, closed, in_progress)"}, - {Text: "--type", Description: "Filter by type (bug, feature, task)"}, - {Text: "--priority", Description: "Filter by priority (0-5)"}, - {Text: "--limit", Description: "Limit number of results"}, - } - return filterAndCompleteFlags(flagSuggests, lastWord, words) - - case "describe", "get", "read": - return issueIdSuggestions(words) - - case "delete": - return issueIdSuggestions(words) - } - - return nil -} - -func issueIdSuggestions(words []string) []prompt.Suggest { - if len(words) < 2 { - return nil - } - - // Get the partial ID being typed - partial := "" - if len(words) >= 2 { - partial = words[len(words)-1] - } - - issues, _ := commands.GetIssueCompletions(context.Background(), partial) - - var suggestions []prompt.Suggest - for _, issue := range issues { - suggestions = append(suggestions, prompt.Suggest{ - Text: issue.ID, Description: truncate.String(issue.Title, 20), - }) - } - return suggestions -} - -func filterAndCompleteFlags(suggestions []prompt.Suggest, lastWord string, words []string) []prompt.Suggest { - if len(words) >= 2 { - prevWord := words[len(words)-2] - switch prevWord { - case "-s", "--status": - return []prompt.Suggest{ - {Text: "open", Description: "Open status"}, - {Text: "closed", Description: "Closed status"}, - {Text: "in_progress", Description: "In progress status"}, - } - case "-t", "--type": - return []prompt.Suggest{ - {Text: "bug", Description: "Bug issue type"}, - {Text: "feature", Description: "Feature issue type"}, - {Text: "task", Description: "Task issue type"}, - } - case "-p", "--priority": - return []prompt.Suggest{ - {Text: "0", Description: "Lowest priority"}, - {Text: "1", Description: "Low priority"}, - {Text: "2", Description: "Medium-low priority"}, - {Text: "3", Description: "Medium priority"}, - {Text: "4", Description: "High priority"}, - {Text: "5", Description: "Highest priority"}, - } - } - } - - if lastWord == "" { - return suggestions - } - - var filtered []prompt.Suggest - for _, s := range suggestions { - if strings.HasPrefix(s.Text, lastWord) { - filtered = append(filtered, s) - } - } - return filtered -} From eafd8df583958a643338af52195d528d5e9ec1f1 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sat, 7 Feb 2026 12:12:43 +0100 Subject: [PATCH 30/60] defer terminal restoration add delete aliases --- pkg/cli/repl/repl.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/pkg/cli/repl/repl.go b/pkg/cli/repl/repl.go index 796f4fb..994404c 100644 --- a/pkg/cli/repl/repl.go +++ b/pkg/cli/repl/repl.go @@ -29,6 +29,8 @@ func RunREPL(ctx context.Context, config cli.CLIConfig) error { return fmt.Errorf("failed to get terminal state: %w", err) } + defer term.Restore(int(os.Stdin.Fd()), oldState) + svc, cleanup, err := service.NewServices(ctx, config) if err != nil { return fmt.Errorf("failed to initialize services: %w", err) @@ -87,10 +89,7 @@ func RunREPL(ctx context.Context, config cli.CLIConfig) error { args := strings.Fields(pmCmd) - output, err := commands.ExecuteArgsString(args) - if err != nil { - fmt.Fprintf(os.Stderr, "Error: %v\n", err) - } + output, _ := commands.ExecuteArgsString(args) if output != "" { fmt.Println(styles.CommandStyle.Render(output)) @@ -110,10 +109,6 @@ func RunREPL(ctx context.Context, config cli.CLIConfig) error { } } - if err := term.Restore(int(os.Stdin.Fd()), oldState); err != nil { - return fmt.Errorf("failed to restore terminal state: %w", err) - } - return nil } @@ -219,7 +214,7 @@ func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { case "describe", "get", "read": return issueIdSuggestions(words) - case "delete": + case "delete", "del", "rm", "remove": return issueIdSuggestions(words) } From 9baedea9b5d354a097e31eb4a1d317e16d0a171e Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sat, 7 Feb 2026 12:12:55 +0100 Subject: [PATCH 31/60] add issue print func --- internal/models/beads.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/models/beads.go b/internal/models/beads.go index bae490a..4f98234 100644 --- a/internal/models/beads.go +++ b/internal/models/beads.go @@ -79,6 +79,18 @@ const ( EventCompacted = beads.EventCompacted ) +func IssueString(issue Issue) string { + return fmt.Sprintf( + "ID: %s\nTitle: %s\nDescription: %s\nStatus: %s\nType: %s\nPriority: %d", + issue.ID, + issue.Title, + issue.Description, + issue.Status, + issue.IssueType, + issue.Priority, + ) +} + func IssuesPtrToIssues(issuePtr []*Issue) []Issue { issues := make([]Issue, 0, len(issuePtr)) for _, issuePtr := range issuePtr { From 6bf8b76aab82e0385440a2f46ecf7efed6aaf403 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sat, 7 Feb 2026 12:15:09 +0100 Subject: [PATCH 32/60] add descriptive comment to variour commands move completions to its own class --- pkg/cli/cli.go | 3 ++ pkg/cli/commands/completion.go | 42 +++++++++++++++++++++ pkg/cli/commands/create.go | 8 +++- pkg/cli/commands/ls.go | 14 +++++-- pkg/cli/commands/read.go | 67 ++++++++++------------------------ 5 files changed, 82 insertions(+), 52 deletions(-) create mode 100644 pkg/cli/commands/completion.go diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index e26ef0f..c85a988 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -7,8 +7,10 @@ import ( "github.com/LazyBachelor/LazyPM/pkg/cli/commands" ) +// CLIConfig is an alias for service.Config, which contains all the necessary type CLIConfig = service.Config +// Run initializes the services and executes the CLI commands. func Run(ctx context.Context, config CLIConfig) error { svc, cleanup, err := service.NewServices(ctx, config) if err != nil { @@ -26,6 +28,7 @@ func Run(ctx context.Context, config CLIConfig) error { return nil } +// RunWithArgs initializes the services and executes the CLI commands with the provided arguments. func RunWithArgs(ctx context.Context, config CLIConfig, args []string) error { svc, cleanup, err := service.NewServices(ctx, config) if err != nil { diff --git a/pkg/cli/commands/completion.go b/pkg/cli/commands/completion.go new file mode 100644 index 0000000..ff13107 --- /dev/null +++ b/pkg/cli/commands/completion.go @@ -0,0 +1,42 @@ +package commands + +import ( + "context" + "strings" + + "github.com/LazyBachelor/LazyPM/internal/models" + "github.com/spf13/cobra" +) + +// completeIssues provides shell completion for issue IDs and titles. +func completeIssues(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + issues, _ := GetIssueCompletions(cmd.Context(), toComplete) + var ids []string + for _, issue := range issues { + ids = append(ids, issue.ID) + } + return ids, cobra.ShellCompDirectiveNoFileComp +} + +// GetIssueCompletions fetches issues matching the toComplete string for shell completion. +func GetIssueCompletions(ctx context.Context, toComplete string) ([]models.Issue, cobra.ShellCompDirective) { + if svc == nil { + return nil, cobra.ShellCompDirectiveNoFileComp + } + + issues, err := svc.Beads.AllIssues(ctx) + if err != nil { + return nil, cobra.ShellCompDirectiveNoFileComp + } + + var completions []models.Issue + for _, issue := range issues { + if strings.HasPrefix(issue.ID, toComplete) { + completions = append(completions, issue) + } else if strings.HasPrefix(issue.Title, toComplete) { + completions = append(completions, issue) + } + } + + return completions, cobra.ShellCompDirectiveNoFileComp +} diff --git a/pkg/cli/commands/create.go b/pkg/cli/commands/create.go index 6f95f00..289c72f 100644 --- a/pkg/cli/commands/create.go +++ b/pkg/cli/commands/create.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" ) +// Variables to hold flag values for the create command. var ( createDescription string createStatus string @@ -21,6 +22,7 @@ const ( pm create Fix bug --desc "Bug description" --status in_progress --type bug --priority 5` ) +// createCmd represents the create command, which allows users to create a new issue with specified details. var createCmd = &cobra.Command{ Use: "create [title]", Short: "Create a new issue", @@ -32,6 +34,7 @@ var createCmd = &cobra.Command{ RunE: runCreateCmd, } +// runCreateCmd executes the create command logic, func runCreateCmd(cmd *cobra.Command, args []string) error { createTitle := strings.Join(args, " ") @@ -47,11 +50,13 @@ func runCreateCmd(cmd *cobra.Command, args []string) error { Priority: createPriority, } + // Create the issue using the service layer. err := svc.Beads.CreateIssue(cmd.Context(), issue, "test_actor") if err != nil { return fmt.Errorf("error creating issue: %w", err) } + // Build the output string with the created issue details. str := fmt.Sprintf("Created issue with ID: %s\n", issue.ID) if issue.Title != "" { @@ -74,11 +79,12 @@ func runCreateCmd(cmd *cobra.Command, args []string) error { str += fmt.Sprintf("Priority: %d\n", issue.Priority) } - fmt.Print(str) + cmd.Print(str) return nil } +// init function to set up the create command and its flags. func init() { createCmd.Flags().StringVarP(&createDescription, "desc", "d", "", "Issue description") createCmd.Flags().StringVarP(&createStatus, "status", "s", "open", "Issue status(open, closed, in_progress)") diff --git a/pkg/cli/commands/ls.go b/pkg/cli/commands/ls.go index 76e68aa..5bd841c 100644 --- a/pkg/cli/commands/ls.go +++ b/pkg/cli/commands/ls.go @@ -7,6 +7,7 @@ import ( "github.com/spf13/cobra" ) +// Variables for get-issues command flags. var ( titleFlag string descriptionFlag string @@ -23,18 +24,21 @@ pm ls --title "New feature" --desc "feature description" pm ls -p 1 -l 10` ) +// getIssuesCmd represents the get issues command. var getIssuesCmd = &cobra.Command{ Use: "ls [search query]", Short: "List all issues", Long: `List all issues in the project management system.`, - Aliases: []string{"list", "search"}, Example: lsExamples, + + Aliases: []string{"list", "search"}, Args: cobra.MinimumNArgs(0), RunE: runGetIssuesCmd, } +// runGetIssuesCmd executes the get issues command logic, +// which retrieves and displays a list of issues based on the provided search query and filters. func runGetIssuesCmd(cmd *cobra.Command, args []string) error { - queryArg := strings.Join(args, " ") filter := models.IssueFilter{ @@ -43,6 +47,8 @@ func runGetIssuesCmd(cmd *cobra.Command, args []string) error { Limit: limit, } + // Only set filter fields if the corresponding flags + // were explicitly provided by the user. if cmd.Flags().Changed("status") { s := models.Status(statusFlag) filter.Status = &s @@ -55,18 +61,20 @@ func runGetIssuesCmd(cmd *cobra.Command, args []string) error { filter.Priority = &priorityFlag } + // Fetch issues based on the search query and filters. issuesPtr, err := svc.Beads.SearchIssues(cmd.Context(), queryArg, filter) if err != nil { return err } + // Convert the returned issue pointers to issue values and print them. issues := models.IssuesPtrToIssues(issuesPtr) - models.PrintIssues(issues) return nil } +// init function to set up the get issues command and its flags. func init() { getIssuesCmd.Flags().StringVar(&titleFlag, "title", "", "Filter issues by title") getIssuesCmd.Flags().StringVarP(&descriptionFlag, "desc", "d", "", "Filter issues by description") diff --git a/pkg/cli/commands/read.go b/pkg/cli/commands/read.go index a6ed216..4ea6a54 100644 --- a/pkg/cli/commands/read.go +++ b/pkg/cli/commands/read.go @@ -1,76 +1,47 @@ package commands import ( - "context" - "strings" - "github.com/LazyBachelor/LazyPM/internal/models" "github.com/spf13/cobra" ) +// getIssueCmd represents the get issue command. var getIssueCmd = &cobra.Command{ - Use: "describe [issue ID]", - Short: "Get issue details", - Long: `Get issue details by ID`, - Aliases: []string{"get", "read"}, - Args: cobra.ExactArgs(1), - RunE: runGetCmd, + Use: "describe [issue ID]", + Short: "Get issue details", + Long: `Get issue details by ID`, + ValidArgsFunction: completeIssues, + + Aliases: []string{"get", "read"}, + Args: cobra.ExactArgs(1), + RunE: runGetCmd, } +// runGetCmd executes the get issue command logic, +// which retrieves and displays issue details by its ID. func runGetCmd(cmd *cobra.Command, args []string) error { issueID := args[0] - issue, err := svc.Beads.GetIssue(cmd.Context(), issueID) + // Fetch the issue details using the service layer. + issuePtr, err := svc.Beads.GetIssue(cmd.Context(), issueID) if err != nil { return err } - if issue == nil { - cmd.Printf("Issue with ID '%s' not found\n", issueID) + // If the issue is not found, inform the user. + if issuePtr == nil { + cmd.Printf("Issue with ID %s not found\n", issueID) return nil } - cmd.Printf("Title: %s\n", issue.Title) - cmd.Printf("Description: %s\n", issue.Description) - cmd.Printf("Status: %s\n", issue.Status) - cmd.Printf("Type: %s\n", issue.IssueType) - cmd.Printf("Priority: %d\n", issue.Priority) + // Display the issue details to the user. + cmd.Println(models.IssueString(*issuePtr)) return nil } +// init function to set up the get issue command. func init() { rootCmd.AddCommand(getIssueCmd) } - -func completeIssues(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - issues, _ := GetIssueCompletions(cmd.Context(), toComplete) - var ids []string - for _, issue := range issues { - ids = append(ids, issue.ID) - } - return ids, cobra.ShellCompDirectiveNoFileComp -} - -func GetIssueCompletions(ctx context.Context, toComplete string) ([]models.Issue, cobra.ShellCompDirective) { - if svc == nil { - return nil, cobra.ShellCompDirectiveNoFileComp - } - - issues, err := svc.Beads.AllIssues(ctx) - if err != nil { - return nil, cobra.ShellCompDirectiveNoFileComp - } - - var completions []models.Issue - for _, issue := range issues { - if strings.HasPrefix(issue.ID, toComplete) { - completions = append(completions, issue) - } else if strings.HasPrefix(issue.Title, toComplete) { - completions = append(completions, issue) - } - } - - return completions, cobra.ShellCompDirectiveNoFileComp -} From 317feadde23f385b9e071f54042ee20d26f4b2b3 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sat, 7 Feb 2026 12:15:34 +0100 Subject: [PATCH 33/60] add confirmation and comments to delete command --- pkg/cli/commands/delete.go | 51 ++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 68fce1b..ce2cc40 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -4,30 +4,67 @@ import ( "fmt" "strings" + "github.com/charmbracelet/huh" "github.com/spf13/cobra" ) +// Variables for delete command flag. +var confirmDelete bool + +// deleteCmd represents the delete command. var deleteCmd = &cobra.Command{ Use: "delete [id]", Short: "Delete an existing issue", Long: `Delete an existing issue by its ID.`, - Example: `pm delete issue_id`, + Example: `pm delete pm-abc`, + + Aliases: []string{"del", "remove", "rm"}, + Args: cobra.ExactArgs(1), RunE: runDeleteCmd, - Aliases: []string{"del"}, - Args: cobra.MinimumNArgs(1), } +// runDeleteCmd executes the delete command logic, +// which deletes an issue by its ID after confirming with the user. func runDeleteCmd(cmd *cobra.Command, args []string) error { deleteID := strings.Join(args, " ") - err := svc.Beads.DeleteIssue(cmd.Context(), deleteID) + // Fetch the issue to ensure it exists before deletion. + issue, err := svc.Beads.GetIssue(cmd.Context(), deleteID) + if err != nil { + return fmt.Errorf("error fetching issue: %w", err) + } + + if issue == nil { + return fmt.Errorf("issue with ID %s not found", deleteID) + } + + // Prompt for confirmation if not already confirmed via flag. + if !cmd.Flags().Changed("yes") { + huh.NewConfirm().Value(&confirmDelete). + Title("You want to delete this issue?"). + Inline(true).WithTheme(huh.ThemeBase()).Run() + } + + // If user did not confirm, cancel deletion. + if !confirmDelete { + cmd.Println("Deletion cancelled.") + return nil + } + + // Delete the issue. + err = svc.Beads.DeleteIssue(cmd.Context(), deleteID) if err != nil { return fmt.Errorf("error deleting issue: %w", err) } - str := fmt.Sprintf("Deleted issue with ID: %s\n", deleteID) - - fmt.Print(str) + cmd.Println("Deleted issue with ID:", deleteID) return nil } + +// init function to set up the delete command and its flags. +func init() { + deleteCmd.Flags().BoolVarP(&confirmDelete, "yes", "y", true, "Confirm deletion without prompt") + + rootCmd.AddCommand(deleteCmd) +} From 419fcfaaa35b39db9862f30d254b4b3a71de4fe1 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sat, 7 Feb 2026 13:40:59 +0100 Subject: [PATCH 34/60] refactor reple into separete files --- pkg/cli/repl/completer.go | 31 +++++ pkg/cli/repl/executor.go | 48 ++++++++ pkg/cli/repl/options.go | 27 ++++ pkg/cli/repl/repl.go | 238 +----------------------------------- pkg/cli/repl/suggestions.go | 152 +++++++++++++++++++++++ pkg/cli/styles/styles.go | 4 +- 6 files changed, 265 insertions(+), 235 deletions(-) create mode 100644 pkg/cli/repl/completer.go create mode 100644 pkg/cli/repl/executor.go create mode 100644 pkg/cli/repl/options.go create mode 100644 pkg/cli/repl/suggestions.go diff --git a/pkg/cli/repl/completer.go b/pkg/cli/repl/completer.go new file mode 100644 index 0000000..9cb119a --- /dev/null +++ b/pkg/cli/repl/completer.go @@ -0,0 +1,31 @@ +package repl + +import ( + "strings" + + "github.com/c-bata/go-prompt" +) + +func completer(d prompt.Document) []prompt.Suggest { + text := d.TextBeforeCursor() + words := strings.Fields(text) + + if len(words) == 0 { + return nil + } + + if words[0] != "pm" { + return filterByPrefix(rootSuggestions, words[0]) + } + + pmWords := words[1:] + if len(words) == 1 || (len(pmWords) == 1 && !strings.HasSuffix(text, " ")) { + return commandSuggestions(pmWords) + } + + if len(pmWords) >= 1 { + return flagSuggestions(pmWords[0], pmWords, text) + } + + return nil +} diff --git a/pkg/cli/repl/executor.go b/pkg/cli/repl/executor.go new file mode 100644 index 0000000..0ec939f --- /dev/null +++ b/pkg/cli/repl/executor.go @@ -0,0 +1,48 @@ +package repl + +import ( + "os/exec" + "strings" + + "github.com/LazyBachelor/LazyPM/pkg/cli/commands" +) + +func execute(input string) (string, error) { + if input == "" { + return "", nil + } + + if input == "help" { + return ReplHelp, nil + } + + if input == "title" { + return ReplTitle, nil + } + + if after, ok := strings.CutPrefix(input, "pm"); ok { + return executePMCommand(after) + } + return executeShellCommand(input) +} + +func executeShellCommand(input string) (string, error) { + parts := strings.Fields(input) + if len(parts) == 0 { + return "", nil + } + + cmd := exec.Command(parts[0], parts[1:]...) + output, err := cmd.CombinedOutput() + return string(output), err +} + +func executePMCommand(input string) (string, error) { + parts := strings.Fields(input) + if len(parts) == 0 { + return "", nil + } + + output, err := commands.ExecuteArgsString(parts) + return output, err +} diff --git a/pkg/cli/repl/options.go b/pkg/cli/repl/options.go new file mode 100644 index 0000000..7ba4e63 --- /dev/null +++ b/pkg/cli/repl/options.go @@ -0,0 +1,27 @@ +package repl + +import "github.com/c-bata/go-prompt" + +const PromptPrefix = "> " +const OptionMaxSuggestions = 5 + +const ( + ReplHelp = `Type 'pm help' for available PM commands. +You can also run shell commands directly. Type 'exit' or 'quit' to leave.` + + ReplTitle = "Welcome to Project Management CLI! " + ReplHelp +) + +func promptOptions(history []string) []prompt.Option { + return []prompt.Option{ + prompt.OptionPrefixTextColor(prompt.Cyan), + prompt.OptionMaxSuggestion(OptionMaxSuggestions), + prompt.OptionSuggestionBGColor(prompt.DefaultColor), + prompt.OptionSelectedSuggestionBGColor(prompt.DefaultColor), + prompt.OptionDescriptionBGColor(prompt.DefaultColor), + prompt.OptionSelectedDescriptionBGColor(prompt.DefaultColor), + prompt.OptionPreviewSuggestionBGColor(prompt.DefaultColor), + prompt.OptionScrollbarBGColor(prompt.DefaultColor), + prompt.OptionHistory(history), + } +} diff --git a/pkg/cli/repl/repl.go b/pkg/cli/repl/repl.go index 994404c..b00fa75 100644 --- a/pkg/cli/repl/repl.go +++ b/pkg/cli/repl/repl.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "os" - "os/exec" "strings" "github.com/LazyBachelor/LazyPM/internal/service" @@ -12,23 +11,14 @@ import ( "github.com/LazyBachelor/LazyPM/pkg/cli/commands" "github.com/LazyBachelor/LazyPM/pkg/cli/styles" "github.com/c-bata/go-prompt" - "github.com/muesli/reflow/truncate" "golang.org/x/term" ) -const ( - ReplHelp = `Type 'pm help' for available PM commands. -You can also run shell commands directly. Type 'exit' or 'quit' to leave.` - - ReplTitle = "Welcome to Project Management CLI! " + ReplHelp -) - func RunREPL(ctx context.Context, config cli.CLIConfig) error { oldState, err := term.GetState(int(os.Stdin.Fd())) if err != nil { return fmt.Errorf("failed to get terminal state: %w", err) } - defer term.Restore(int(os.Stdin.Fd()), oldState) svc, cleanup, err := service.NewServices(ctx, config) @@ -39,247 +29,31 @@ func RunREPL(ctx context.Context, config cli.CLIConfig) error { commands.SetServices(svc) - fmt.Println("\n" + styles.TitleStyle.Render(ReplTitle)) + fmt.Println(styles.TitleStyle.Render(ReplTitle)) var history []string for { input := prompt.Input( - "› ", + PromptPrefix, completer, - prompt.OptionPrefixTextColor(prompt.Cyan), - prompt.OptionMaxSuggestion(5), - prompt.OptionSuggestionBGColor(prompt.DefaultColor), - prompt.OptionSelectedSuggestionBGColor(prompt.DefaultColor), - prompt.OptionDescriptionBGColor(prompt.DefaultColor), - prompt.OptionSelectedDescriptionBGColor(prompt.DefaultColor), - prompt.OptionPreviewSuggestionBGColor(prompt.DefaultColor), - prompt.OptionScrollbarBGColor(prompt.DefaultColor), - prompt.OptionHistory(history), + promptOptions(history)..., ) input = strings.TrimSpace(input) - if input == "" { - continue - } - if input == "exit" || input == "quit" { fmt.Println("Goodbye!") break } - if input == "help" { - fmt.Println(ReplHelp) - continue - } - - if input == "title" { - fmt.Println(styles.TitleStyle.Render(ReplTitle)) - continue - } - history = append(history, input) - if after, ok := strings.CutPrefix(input, "pm "); ok { - pmCmd := strings.TrimSpace(after) - if pmCmd == "" { - continue - } + // Ignore errors for now, gives better ux + output, _ := execute(input) - args := strings.Fields(pmCmd) - - output, _ := commands.ExecuteArgsString(args) - - if output != "" { - fmt.Println(styles.CommandStyle.Render(output)) - } - - } else { - cmd := exec.Command("sh", "-c", input) - out, err := cmd.CombinedOutput() - - if len(out) > 0 { - fmt.Println(styles.CommandStyle.Render(string(out))) - } - - if err != nil && len(out) == 0 { - fmt.Fprintf(os.Stderr, "%s", fmt.Sprintf("Error: %v", err)) - } - } + fmt.Println(styles.CommandStyle.Render(output)) } return nil } - -func completer(d prompt.Document) []prompt.Suggest { - text := d.TextBeforeCursor() - words := strings.Fields(text) - - if len(words) == 0 { - return nil - } - - if words[0] != "pm" { - suggestions := []prompt.Suggest{ - {Text: "pm", Description: "Project Management System"}, - {Text: "exit", Description: "Exit pm CLI"}, - {Text: "help", Description: "Show help information"}, - {Text: "title", Description: "Print the welcome title"}, - {Text: "git", Description: "Version control system"}, - } - - if len(words) == 0 { - return suggestions - } - - var filtered []prompt.Suggest - for _, s := range suggestions { - if strings.HasPrefix(s.Text, words[0]) { - filtered = append(filtered, s) - } - } - - return filtered - } - - // If first word is "pm", provide PM command completions - if words[0] == "pm" { - // Remove "pm" from words to get the actual command - if len(words) == 1 || (len(words) == 2 && !strings.HasSuffix(text, " ")) { - return commandSuggestions(words[1:]) - } - - // Get the PM subcommand - if len(words) >= 2 { - cmd := words[1] - return flagSuggestions(cmd, words[1:], text) - } - } - - return nil -} - -func commandSuggestions(words []string) []prompt.Suggest { - suggestions := []prompt.Suggest{ - {Text: "help", Description: "Show help information"}, - {Text: "delete", Description: "Delete an issue by ID"}, - {Text: "create", Description: "Create a new issue with title"}, - {Text: "describe", Description: "Get issue details by ID"}, - {Text: "list", Description: "List all issues"}, - } - - if len(words) == 0 { - return suggestions - } - - var filtered []prompt.Suggest - for _, s := range suggestions { - if strings.HasPrefix(s.Text, words[0]) { - filtered = append(filtered, s) - } - } - return filtered -} - -func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { - var flagSuggests []prompt.Suggest - isCompleteWord := strings.HasSuffix(text, " ") - lastWord := "" - if len(words) > 0 && !isCompleteWord { - lastWord = words[len(words)-1] - } - - switch cmd { - case "create", "add": - flagSuggests = []prompt.Suggest{ - {Text: "--desc", Description: "Issue description"}, - {Text: "--status", Description: "Issue status (open, closed, in_progress)"}, - {Text: "--type", Description: "Issue type (bug, feature, task)"}, - {Text: "--priority", Description: "Issue priority (0-5)"}, - } - return filterAndCompleteFlags(flagSuggests, lastWord, words) - - case "ls", "list", "search": - flagSuggests = []prompt.Suggest{ - {Text: "--title", Description: "Filter by title"}, - {Text: "--desc", Description: "Filter by description"}, - {Text: "--status", Description: "Filter by status (open, closed, in_progress)"}, - {Text: "--type", Description: "Filter by type (bug, feature, task)"}, - {Text: "--priority", Description: "Filter by priority (0-5)"}, - {Text: "--limit", Description: "Limit number of results"}, - } - return filterAndCompleteFlags(flagSuggests, lastWord, words) - - case "describe", "get", "read": - return issueIdSuggestions(words) - - case "delete", "del", "rm", "remove": - return issueIdSuggestions(words) - } - - return nil -} - -func issueIdSuggestions(words []string) []prompt.Suggest { - if len(words) < 2 { - return nil - } - - // Get the partial ID being typed - partial := "" - if len(words) >= 2 { - partial = words[len(words)-1] - } - - issues, _ := commands.GetIssueCompletions(context.Background(), partial) - - var suggestions []prompt.Suggest - for _, issue := range issues { - suggestions = append(suggestions, prompt.Suggest{ - Text: issue.ID, Description: truncate.String(issue.Title, 20), - }) - } - return suggestions -} - -func filterAndCompleteFlags(suggestions []prompt.Suggest, lastWord string, words []string) []prompt.Suggest { - if len(words) >= 2 { - prevWord := words[len(words)-2] - switch prevWord { - case "-s", "--status": - return []prompt.Suggest{ - {Text: "open", Description: "Open status"}, - {Text: "closed", Description: "Closed status"}, - {Text: "in_progress", Description: "In progress status"}, - } - case "-t", "--type": - return []prompt.Suggest{ - {Text: "bug", Description: "Bug issue type"}, - {Text: "feature", Description: "Feature issue type"}, - {Text: "task", Description: "Task issue type"}, - } - case "-p", "--priority": - return []prompt.Suggest{ - {Text: "0", Description: "Lowest priority"}, - {Text: "1", Description: "Low priority"}, - {Text: "2", Description: "Medium-low priority"}, - {Text: "3", Description: "Medium priority"}, - {Text: "4", Description: "High priority"}, - {Text: "5", Description: "Highest priority"}, - } - } - } - - if lastWord == "" { - return suggestions - } - - var filtered []prompt.Suggest - for _, s := range suggestions { - if strings.HasPrefix(s.Text, lastWord) { - filtered = append(filtered, s) - } - } - return filtered -} diff --git a/pkg/cli/repl/suggestions.go b/pkg/cli/repl/suggestions.go new file mode 100644 index 0000000..806e1e1 --- /dev/null +++ b/pkg/cli/repl/suggestions.go @@ -0,0 +1,152 @@ +package repl + +import ( + "context" + "strings" + + "github.com/LazyBachelor/LazyPM/pkg/cli/commands" + "github.com/c-bata/go-prompt" + "github.com/muesli/reflow/truncate" +) + +var rootSuggestions = []prompt.Suggest{ + {Text: "pm", Description: "Project Management System"}, + {Text: "exit", Description: "Exit pm CLI"}, + {Text: "help", Description: "Show help information"}, + {Text: "title", Description: "Print the welcome title"}, + {Text: "git", Description: "Version control system"}, +} + +var baseSuggestions = []prompt.Suggest{ + {Text: "help", Description: "Show help information"}, + {Text: "delete", Description: "Delete an issue by ID"}, + {Text: "create", Description: "Create a new issue with title"}, + {Text: "describe", Description: "Get issue details by ID"}, + {Text: "list", Description: "List all issues"}, +} + +var createFlags = []prompt.Suggest{ + {Text: "--desc", Description: "Issue description"}, + {Text: "--status", Description: "Issue status (open, closed, in_progress)"}, + {Text: "--type", Description: "Issue type (bug, feature, task)"}, + {Text: "--priority", Description: "Issue priority (0-5)"}, +} + +var listFlags = []prompt.Suggest{ + {Text: "--title", Description: "Filter by title"}, + {Text: "--desc", Description: "Filter by description"}, + {Text: "--status", Description: "Filter by status (open, closed, in_progress)"}, + {Text: "--type", Description: "Filter by type (bug, feature, task)"}, + {Text: "--priority", Description: "Filter by priority (0-5)"}, + {Text: "--limit", Description: "Limit number of results"}, +} + +var statusValues = []prompt.Suggest{ + {Text: "open", Description: "Open status"}, + {Text: "closed", Description: "Closed status"}, + {Text: "in_progress", Description: "In progress status"}, +} + +var typeValues = []prompt.Suggest{ + {Text: "bug", Description: "Bug issue type"}, + {Text: "feature", Description: "Feature issue type"}, + {Text: "task", Description: "Task issue type"}, +} + +var priorityValues = []prompt.Suggest{ + {Text: "0", Description: "Lowest priority"}, + {Text: "1", Description: "Low priority"}, + {Text: "2", Description: "Medium-low priority"}, + {Text: "3", Description: "Medium priority"}, + {Text: "4", Description: "High priority"}, + {Text: "5", Description: "Highest priority"}, +} + +func commandSuggestions(words []string) []prompt.Suggest { + if len(words) == 0 { + return baseSuggestions + } + return filterByPrefix(baseSuggestions, words[0]) +} + +func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { + lastWord, prevWord := parseWords(words, text) + + if values := getFlagValues(prevWord); values != nil { + return filterByPrefix(values, lastWord) + } + + if cmd == "describe" || cmd == "delete" || cmd == "del" || cmd == "rm" || cmd == "remove" || cmd == "get" || cmd == "read" { + return issueIDSuggestions(words) + } + + var flags []prompt.Suggest + switch cmd { + case "create", "add": + flags = createFlags + case "list", "ls", "search": + flags = listFlags + default: + return nil + } + + if lastWord == "" { + return flags + } + return filterByPrefix(flags, lastWord) +} + +func issueIDSuggestions(words []string) []prompt.Suggest { + if len(words) < 2 { + return nil + } + + partial := words[len(words)-1] + issues, _ := commands.GetIssueCompletions(context.Background(), partial) + + var suggestions []prompt.Suggest + for _, issue := range issues { + suggestions = append(suggestions, prompt.Suggest{ + Text: issue.ID, + Description: truncate.String(issue.Title, 20), + }) + } + return suggestions +} + +func parseWords(words []string, text string) (lastWord, prevWord string) { + if len(words) > 0 && !strings.HasSuffix(text, " ") { + lastWord = words[len(words)-1] + if len(words) >= 2 { + prevWord = words[len(words)-2] + } + } else if len(words) >= 1 { + prevWord = words[len(words)-1] + } + return +} + +func getFlagValues(flag string) []prompt.Suggest { + switch flag { + case "-s", "--status": + return statusValues + case "-t", "--type": + return typeValues + case "-p", "--priority": + return priorityValues + } + return nil +} + +func filterByPrefix(suggestions []prompt.Suggest, prefix string) []prompt.Suggest { + if prefix == "" { + return suggestions + } + var filtered []prompt.Suggest + for _, s := range suggestions { + if strings.HasPrefix(s.Text, prefix) { + filtered = append(filtered, s) + } + } + return filtered +} diff --git a/pkg/cli/styles/styles.go b/pkg/cli/styles/styles.go index b080dcc..65a9261 100644 --- a/pkg/cli/styles/styles.go +++ b/pkg/cli/styles/styles.go @@ -5,9 +5,7 @@ import "github.com/charmbracelet/lipgloss" var ( TitleStyle = lipgloss.NewStyle(). - Foreground(lipgloss.Color("6")). - Bold(true).Border(lipgloss.RoundedBorder()). - BorderForeground(lipgloss.Color("12")).Padding(1) + Bold(true).Padding(1) CommandStyle = lipgloss.NewStyle().Padding(1) ) From 927e787ca71e657a836335b85f4adfa669b5bdec Mon Sep 17 00:00:00 2001 From: Robin Olsen <129996395+Telikz@users.noreply.github.com> Date: Sat, 7 Feb 2026 13:52:47 +0100 Subject: [PATCH 35/60] Update pkg/cli/styles/styles.go remve linebreak Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/cli/styles/styles.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/cli/styles/styles.go b/pkg/cli/styles/styles.go index 65a9261..e4bf744 100644 --- a/pkg/cli/styles/styles.go +++ b/pkg/cli/styles/styles.go @@ -4,8 +4,7 @@ package styles import "github.com/charmbracelet/lipgloss" var ( - TitleStyle = lipgloss.NewStyle(). - Bold(true).Padding(1) + TitleStyle = lipgloss.NewStyle().Bold(true).Padding(1) CommandStyle = lipgloss.NewStyle().Padding(1) ) From f8f65a345110d39a908b87c155d0f660b0e4ba0a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Feb 2026 12:56:54 +0000 Subject: [PATCH 36/60] Initial plan From 50a0cf7d89e3a3c1ec700091d7f08dd1fa4915c6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Feb 2026 12:59:38 +0000 Subject: [PATCH 37/60] Refactor issueIDSuggestions to accept lastWord directly Co-authored-by: Telikz <129996395+Telikz@users.noreply.github.com> --- pkg/cli/repl/suggestions.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/cli/repl/suggestions.go b/pkg/cli/repl/suggestions.go index 806e1e1..defefe2 100644 --- a/pkg/cli/repl/suggestions.go +++ b/pkg/cli/repl/suggestions.go @@ -77,7 +77,10 @@ func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { } if cmd == "describe" || cmd == "delete" || cmd == "del" || cmd == "rm" || cmd == "remove" || cmd == "get" || cmd == "read" { - return issueIDSuggestions(words) + // For ID-oriented commands, pass the current partial argument (lastWord) + // so issueIDSuggestions can distinguish between completing the command + // name and completing the ID itself. + return issueIDSuggestions(lastWord, len(words) >= 2) } var flags []prompt.Suggest @@ -96,12 +99,12 @@ func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { return filterByPrefix(flags, lastWord) } -func issueIDSuggestions(words []string) []prompt.Suggest { - if len(words) < 2 { +func issueIDSuggestions(partial string, hasCommand bool) []prompt.Suggest { + // Only show suggestions if we've typed the command already + if !hasCommand { return nil } - partial := words[len(words)-1] issues, _ := commands.GetIssueCompletions(context.Background(), partial) var suggestions []prompt.Suggest From c331ad20010dbdaad0386319603dc9148d25a9cb Mon Sep 17 00:00:00 2001 From: vb Date: Sat, 7 Feb 2026 15:33:09 +0100 Subject: [PATCH 38/60] adding update feature to cli --- pkg/cli/commands/update.go | 126 ++++++++++++++++++++++++++++++++++++ pkg/cli/repl/suggestions.go | 22 +++++++ 2 files changed, 148 insertions(+) create mode 100644 pkg/cli/commands/update.go diff --git a/pkg/cli/commands/update.go b/pkg/cli/commands/update.go new file mode 100644 index 0000000..6a262d6 --- /dev/null +++ b/pkg/cli/commands/update.go @@ -0,0 +1,126 @@ +package commands + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var ( + updateDescription string + updateStatus string + updateType string + updatePriority int + updateTitle string +) + +var updateCmd = &cobra.Command{ + Use: "update [issue ID]", + Short: "Update an existing issue", + Long: `Update an existing issue by its ID with the specified details.`, + Example: `pm update pm-001 --title "New title" -d "Description" -s in_progress --type task -p 3`, + RunE: runUpdateCmd, + Aliases: []string{"edit"}, + Args: cobra.ExactArgs(1), + ValidArgsFunction: completeIssues, +} + +func init() { + updateCmd.Flags().StringVar(&updateTitle, "title", "", "New issue title") + updateCmd.Flags().StringVarP(&updateDescription, "desc", "d", "", "New issue description") + updateCmd.Flags().StringVarP(&updateStatus, "status", "s", "", "New issue status(open, closed, in_progress)") + updateCmd.Flags().StringVarP(&updateType, "type", "", "", "New issue type(bug, feature, task)") + updateCmd.Flags().IntVarP(&updatePriority, "priority", "p", -1, "New issue priority(0-5)") + + updateCmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"bug", "feature", "task"}, cobra.ShellCompDirectiveDefault + }) + + updateCmd.RegisterFlagCompletionFunc("status", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"open", "closed", "in_progress"}, cobra.ShellCompDirectiveDefault + }) + + updateCmd.RegisterFlagCompletionFunc("priority", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"0", "1", "2", "3", "4", "5"}, cobra.ShellCompDirectiveDefault + }) + + rootCmd.AddCommand(updateCmd) +} + +func runUpdateCmd(cmd *cobra.Command, args []string) error { + issueID := args[0] + + updates := make(map[string]interface{}) + + if cmd.Flags().Changed("title") { + if updateTitle == "" { + return fmt.Errorf("issue title cannot be empty") + } + updates["title"] = updateTitle + } + + if cmd.Flags().Changed("desc") { + updates["description"] = updateDescription + } + + if cmd.Flags().Changed("status") { + updates["status"] = updateStatus + } + + if cmd.Flags().Changed("type") { + updates["issue_type"] = updateType + } + + if cmd.Flags().Changed("priority") { + updates["priority"] = updatePriority + } + + if len(updates) == 0 { + return fmt.Errorf("no updates specified") + } + + issue, err := svc.Beads.GetIssue(cmd.Context(), issueID) + if err != nil { + return fmt.Errorf("error getting issue: %w", err) + } + + if issue == nil { + return fmt.Errorf("issue with ID '%s' not found", issueID) + } + + err = svc.Beads.UpdateIssue(cmd.Context(), issueID, updates, "test_actor") + if err != nil { + return fmt.Errorf("error updating issue: %w", err) + } + + updatedIssue, err := svc.Beads.GetIssue(cmd.Context(), issueID) + if err != nil { + return fmt.Errorf("error getting updated issue: %w", err) + } + + str := fmt.Sprintf("Updated issue with ID: %s\n", issueID) + + if updatedIssue.Title != "" { + str += fmt.Sprintf("Title: %s\n", updatedIssue.Title) + } + + if updatedIssue.Description != "" { + str += fmt.Sprintf("Description: %s\n", updatedIssue.Description) + } + + if updatedIssue.Status != "" { + str += fmt.Sprintf("Status: %s\n", updatedIssue.Status) + } + + if updatedIssue.IssueType != "" { + str += fmt.Sprintf("Type: %s\n", updatedIssue.IssueType) + } + + if updatedIssue.Priority != 0 { + str += fmt.Sprintf("Priority: %d\n", updatedIssue.Priority) + } + + fmt.Print(str) + + return nil +} diff --git a/pkg/cli/repl/suggestions.go b/pkg/cli/repl/suggestions.go index defefe2..0d081cc 100644 --- a/pkg/cli/repl/suggestions.go +++ b/pkg/cli/repl/suggestions.go @@ -21,6 +21,7 @@ var baseSuggestions = []prompt.Suggest{ {Text: "help", Description: "Show help information"}, {Text: "delete", Description: "Delete an issue by ID"}, {Text: "create", Description: "Create a new issue with title"}, + {Text: "update", Description: "Update an existing issue by ID"}, {Text: "describe", Description: "Get issue details by ID"}, {Text: "list", Description: "List all issues"}, } @@ -32,6 +33,14 @@ var createFlags = []prompt.Suggest{ {Text: "--priority", Description: "Issue priority (0-5)"}, } +var updateFlags = []prompt.Suggest{ + {Text: "--title", Description: "New issue title"}, + {Text: "--desc", Description: "New issue description"}, + {Text: "--status", Description: "New issue status (open, closed, in_progress)"}, + {Text: "--type", Description: "New issue type (bug, feature, task)"}, + {Text: "--priority", Description: "New issue priority (0-5)"}, +} + var listFlags = []prompt.Suggest{ {Text: "--title", Description: "Filter by title"}, {Text: "--desc", Description: "Filter by description"}, @@ -83,6 +92,19 @@ func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { return issueIDSuggestions(lastWord, len(words) >= 2) } + // Update/edit: suggest issue IDs when typing the ID, flags after ID is provided + if cmd == "update" || cmd == "edit" { + if len(words) >= 2 && (lastWord == "" || strings.HasPrefix(lastWord, "-")) { + // ID already provided (trailing space) or typing a flag - suggest flags + flags := updateFlags + if lastWord == "" { + return flags + } + return filterByPrefix(flags, lastWord) + } + return issueIDSuggestions(lastWord, len(words) >= 2) + } + var flags []prompt.Suggest switch cmd { case "create", "add": From 6bcff202b44ffa9eea3a3b25a391a59e72fd86c3 Mon Sep 17 00:00:00 2001 From: vb Date: Sat, 7 Feb 2026 15:39:05 +0100 Subject: [PATCH 39/60] fix --- pkg/cli/repl/suggestions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/repl/suggestions.go b/pkg/cli/repl/suggestions.go index 0d081cc..cc8b5d6 100644 --- a/pkg/cli/repl/suggestions.go +++ b/pkg/cli/repl/suggestions.go @@ -95,7 +95,7 @@ func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { // Update/edit: suggest issue IDs when typing the ID, flags after ID is provided if cmd == "update" || cmd == "edit" { if len(words) >= 2 && (lastWord == "" || strings.HasPrefix(lastWord, "-")) { - // ID already provided (trailing space) or typing a flag - suggest flags + // ID already provided (trailing space) or typing a flag -> suggest update flags flags := updateFlags if lastWord == "" { return flags From 232243926278326483f8f30ca6f3b93e3c66be5f Mon Sep 17 00:00:00 2001 From: viljarb0 <156418063+viljarb0@users.noreply.github.com> Date: Sun, 8 Feb 2026 09:43:54 +0100 Subject: [PATCH 40/60] Update pkg/cli/commands/update.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/cli/commands/update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/commands/update.go b/pkg/cli/commands/update.go index 6a262d6..03f5754 100644 --- a/pkg/cli/commands/update.go +++ b/pkg/cli/commands/update.go @@ -116,7 +116,7 @@ func runUpdateCmd(cmd *cobra.Command, args []string) error { str += fmt.Sprintf("Type: %s\n", updatedIssue.IssueType) } - if updatedIssue.Priority != 0 { + if cmd.Flags().Changed("priority") { str += fmt.Sprintf("Priority: %d\n", updatedIssue.Priority) } From 910fad83dc86874e614b53e1f148d8f9037a513d Mon Sep 17 00:00:00 2001 From: viljarb0 <156418063+viljarb0@users.noreply.github.com> Date: Sun, 8 Feb 2026 09:44:12 +0100 Subject: [PATCH 41/60] Update pkg/cli/commands/update.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/cli/commands/update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/commands/update.go b/pkg/cli/commands/update.go index 03f5754..81c8cec 100644 --- a/pkg/cli/commands/update.go +++ b/pkg/cli/commands/update.go @@ -120,7 +120,7 @@ func runUpdateCmd(cmd *cobra.Command, args []string) error { str += fmt.Sprintf("Priority: %d\n", updatedIssue.Priority) } - fmt.Print(str) + cmd.Print(str) return nil } From 228ffa3cdb8eee833bbb0bc9e2184952555a2646 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sun, 8 Feb 2026 12:28:26 +0100 Subject: [PATCH 42/60] fix path in makefile for cli --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2e82291..203455b 100644 --- a/Makefile +++ b/Makefile @@ -7,12 +7,12 @@ clean: go clean build: - go build -o ./bin/cli ./cmd/cli + go build -o ./bin/pm ./cmd/pm go build -o ./bin/tui ./cmd/tui go build -o ./bin/web ./cmd/web cli: - go run ./cmd/cli + go run ./cmd/pm tui: go run ./cmd/tui From 0b9dd86c7395c7d5562a2ed64951de21c26dc3bd Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sun, 8 Feb 2026 12:28:39 +0100 Subject: [PATCH 43/60] add close command --- pkg/cli/commands/close.go | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 pkg/cli/commands/close.go diff --git a/pkg/cli/commands/close.go b/pkg/cli/commands/close.go new file mode 100644 index 0000000..4bfecaa --- /dev/null +++ b/pkg/cli/commands/close.go @@ -0,0 +1,60 @@ +package commands + +import ( + "fmt" + "strings" + + "github.com/charmbracelet/huh" + "github.com/spf13/cobra" +) + +// closeCmd represents the close command, +// which allows users to close an existing issue by its ID. +var closeCmd = &cobra.Command{ + Use: "close [id]", + Short: "Close an existing issue", + Long: `Close an existing issue by its ID.`, + Example: `pm close pm-abc`, + ValidArgsFunction: completeIssues, + + RunE: runCloseCmd, +} + +// runCloseCmd executes the close command logic, +// which closes an issue by its ID after confirming with the user. +func runCloseCmd(cmd *cobra.Command, args []string) error { + closeID := strings.Join(args, " ") + + if closeID == "" { + return fmt.Errorf("issue ID cannot be empty") + } + + // Fetch the issue to ensure it exists before closing. + issue, err := svc.Beads.GetIssue(cmd.Context(), closeID) + if err != nil { + return fmt.Errorf("error fetching issue: %w", err) + } + + if issue == nil { + return fmt.Errorf("issue with ID %s not found", closeID) + } + + // Ask for closing reason + huh.NewInput().Value(&issue.CloseReason). + Title("Reason for closing the issue?").WithTheme(huh.ThemeBase()).Run() + + // Close the issue. + err = svc.Beads.CloseIssue(cmd.Context(), closeID, issue.CloseReason, "", "") + if err != nil { + return fmt.Errorf("error closing issue: %w", err) + } + + cmd.Println("Closed issue with ID:", closeID) + + return nil +} + +// init function to set up the close command and its flags. +func init() { + rootCmd.AddCommand(closeCmd) +} From 84c0ad22862a91b79c2031976fd8f3764adaa0ae Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sun, 8 Feb 2026 12:29:06 +0100 Subject: [PATCH 44/60] add completionFunc for reducing boilerplate for command implementatinos --- pkg/cli/commands/completion.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/cli/commands/completion.go b/pkg/cli/commands/completion.go index ff13107..af34c20 100644 --- a/pkg/cli/commands/completion.go +++ b/pkg/cli/commands/completion.go @@ -8,6 +8,19 @@ import ( "github.com/spf13/cobra" ) +var ( + typeOptions = []string{"bug", "feature", "task"} + statusOptions = []string{"open", "closed", "in_progress"} + priorityRange = []string{"0", "1", "2", "3", "4"} +) + +// completionFunc returns a function that provides shell completion for the given options. +func completionFunc(options []string) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) { + return func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { + return options, cobra.ShellCompDirectiveDefault + } +} + // completeIssues provides shell completion for issue IDs and titles. func completeIssues(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { issues, _ := GetIssueCompletions(cmd.Context(), toComplete) From 59b912325b252a47592fec79f3211450ace1f684 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sun, 8 Feb 2026 12:29:50 +0100 Subject: [PATCH 45/60] add close issue to repl completions --- pkg/cli/repl/suggestions.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/cli/repl/suggestions.go b/pkg/cli/repl/suggestions.go index defefe2..cf8b925 100644 --- a/pkg/cli/repl/suggestions.go +++ b/pkg/cli/repl/suggestions.go @@ -20,6 +20,7 @@ var rootSuggestions = []prompt.Suggest{ var baseSuggestions = []prompt.Suggest{ {Text: "help", Description: "Show help information"}, {Text: "delete", Description: "Delete an issue by ID"}, + {Text: "close", Description: "Close an issue by ID"}, {Text: "create", Description: "Create a new issue with title"}, {Text: "describe", Description: "Get issue details by ID"}, {Text: "list", Description: "List all issues"}, @@ -76,7 +77,8 @@ func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { return filterByPrefix(values, lastWord) } - if cmd == "describe" || cmd == "delete" || cmd == "del" || cmd == "rm" || cmd == "remove" || cmd == "get" || cmd == "read" { + if cmd == "describe" || cmd == "delete" || cmd == "del" || + cmd == "rm" || cmd == "remove" || cmd == "get" || cmd == "read" || cmd == "close" { // For ID-oriented commands, pass the current partial argument (lastWord) // so issueIDSuggestions can distinguish between completing the command // name and completing the ID itself. From 0e5e22619be3c25faff03ce580ba239303d35238 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sun, 8 Feb 2026 12:30:24 +0100 Subject: [PATCH 46/60] add a flags struct other commands can impelemt enable completion command --- pkg/cli/commands/root.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/cli/commands/root.go b/pkg/cli/commands/root.go index 418d7ae..296d029 100644 --- a/pkg/cli/commands/root.go +++ b/pkg/cli/commands/root.go @@ -14,6 +14,15 @@ import ( // Must be called before executing any commands to ensure services are available. var svc *service.Services +type Flags struct { + interactive bool + title string + description string + status string + issueType string + priority int +} + // rootCmd is the base command for the CLI application. var rootCmd = &cobra.Command{ Short: "Project Management CLI", @@ -56,7 +65,7 @@ func ExecuteArgsString(args []string) (string, error) { // init function to set up the command hierarchy and options. func init() { - rootCmd.CompletionOptions.DisableDefaultCmd = true + rootCmd.CompletionOptions.DisableDefaultCmd = false rootCmd.AddGroup(&cobra.Group{ID: "help", Title: "Helping Commands"}) rootCmd.SetCompletionCommandGroupID("help") rootCmd.SetHelpCommandGroupID("help") From f403c9b79d1a8f6c8849afd902cd84a23ad87f08 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sun, 8 Feb 2026 12:33:43 +0100 Subject: [PATCH 47/60] use flag struct rename usage to list --- pkg/cli/commands/ls.go | 58 ++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/pkg/cli/commands/ls.go b/pkg/cli/commands/ls.go index 5bd841c..bd65899 100644 --- a/pkg/cli/commands/ls.go +++ b/pkg/cli/commands/ls.go @@ -8,30 +8,23 @@ import ( ) // Variables for get-issues command flags. -var ( - titleFlag string - descriptionFlag string - statusFlag string - typeFlag string - priorityFlag int - limit int = 25 -) +var listFlags Flags const ( - lsExamples = `pm ls [id|title|description] -pm ls --status open --type bug -pm ls --title "New feature" --desc "feature description" -pm ls -p 1 -l 10` + lsExamples = `pm list [id|title|description] +pm list --status open --type bug +pm list --title "New feature" --desc "feature description" +pm list -p 1 -l 10` ) // getIssuesCmd represents the get issues command. var getIssuesCmd = &cobra.Command{ - Use: "ls [search query]", + Use: "list [search query]", Short: "List all issues", Long: `List all issues in the project management system.`, Example: lsExamples, - Aliases: []string{"list", "search"}, + Aliases: []string{"ls", "search"}, Args: cobra.MinimumNArgs(0), RunE: runGetIssuesCmd, } @@ -42,23 +35,23 @@ func runGetIssuesCmd(cmd *cobra.Command, args []string) error { queryArg := strings.Join(args, " ") filter := models.IssueFilter{ - TitleSearch: titleFlag, - DescriptionContains: descriptionFlag, - Limit: limit, + TitleSearch: listFlags.title, + DescriptionContains: listFlags.description, + Limit: listFlags.limit, } // Only set filter fields if the corresponding flags // were explicitly provided by the user. if cmd.Flags().Changed("status") { - s := models.Status(statusFlag) + s := models.Status(listFlags.status) filter.Status = &s } if cmd.Flags().Changed("type") { - t := models.IssueType(typeFlag) + t := models.IssueType(listFlags.issueType) filter.IssueType = &t } if cmd.Flags().Changed("priority") { - filter.Priority = &priorityFlag + filter.Priority = &listFlags.priority } // Fetch issues based on the search query and filters. @@ -76,24 +69,17 @@ func runGetIssuesCmd(cmd *cobra.Command, args []string) error { // init function to set up the get issues command and its flags. func init() { - getIssuesCmd.Flags().StringVar(&titleFlag, "title", "", "Filter issues by title") - getIssuesCmd.Flags().StringVarP(&descriptionFlag, "desc", "d", "", "Filter issues by description") - getIssuesCmd.Flags().StringVarP(&statusFlag, "status", "s", "", "Filter issues by status (open, closed, in_progress)") - getIssuesCmd.Flags().StringVarP(&typeFlag, "type", "t", "", "Filter issues by type (bug, feature, task)") - getIssuesCmd.Flags().IntVarP(&priorityFlag, "priority", "p", 0, "Filter issues by priority (0-5)") - getIssuesCmd.Flags().IntVarP(&limit, "limit", "l", 25, "Limit the number of issues returned") + getIssuesCmd.Flags().StringVar(&listFlags.title, "title", "", "Filter issues by title") + getIssuesCmd.Flags().StringVarP(&listFlags.description, "desc", "d", "", "Filter issues by description") + getIssuesCmd.Flags().StringVarP(&listFlags.status, "status", "s", "", "Filter issues by status (open, closed, in_progress)") + getIssuesCmd.Flags().StringVarP(&listFlags.issueType, "type", "t", "", "Filter issues by type (bug, feature, task)") + getIssuesCmd.Flags().IntVarP(&listFlags.priority, "priority", "p", 0, "Filter issues by priority (0-4)") - getIssuesCmd.RegisterFlagCompletionFunc("status", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"open", "closed", "in_progress"}, cobra.ShellCompDirectiveDefault - }) + getIssuesCmd.Flags().IntVarP(&listFlags.limit, "limit", "l", 25, "Limit the number of issues returned") - getIssuesCmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"bug", "feature", "task"}, cobra.ShellCompDirectiveDefault - }) - - getIssuesCmd.RegisterFlagCompletionFunc("priority", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"0", "1", "2", "3", "4", "5"}, cobra.ShellCompDirectiveDefault - }) + getIssuesCmd.RegisterFlagCompletionFunc("status", completionFunc(statusOptions)) + getIssuesCmd.RegisterFlagCompletionFunc("type", completionFunc(typeOptions)) + getIssuesCmd.RegisterFlagCompletionFunc("priority", completionFunc(priorityRange)) rootCmd.AddCommand(getIssuesCmd) } From a24c658473f8d676e54012237612a091a9da120f Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sun, 8 Feb 2026 12:34:51 +0100 Subject: [PATCH 48/60] refactor for simplicity change to use createFlags var add interactive mode --- pkg/cli/commands/create.go | 120 ++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 54 deletions(-) diff --git a/pkg/cli/commands/create.go b/pkg/cli/commands/create.go index 289c72f..95e9d53 100644 --- a/pkg/cli/commands/create.go +++ b/pkg/cli/commands/create.go @@ -5,17 +5,13 @@ import ( "strings" "github.com/LazyBachelor/LazyPM/internal/models" + "github.com/charmbracelet/huh" "github.com/spf13/cobra" ) -// Variables to hold flag values for the create command. -var ( - createDescription string - createStatus string - createType string - createPriority int -) +// createFlags holds the flag values for the create command +var createFlags Flags const ( createCmdExample = `pm create New issue -d "Description" -s open -t task -p 3 @@ -29,25 +25,32 @@ var createCmd = &cobra.Command{ Long: `Create a new issue with the specified details.`, Example: createCmdExample, + Args: cobra.MinimumNArgs(0), Aliases: []string{"add"}, - Args: cobra.MinimumNArgs(1), RunE: runCreateCmd, } // runCreateCmd executes the create command logic, func runCreateCmd(cmd *cobra.Command, args []string) error { - createTitle := strings.Join(args, " ") + createFlags.title = strings.Join(args, " ") - if createTitle == "" { + // Run interactive if flag is set + if createFlags.interactive { + if err := runCreateInteractive(); err != nil { + return err + } + } + + if createFlags.title == "" { return fmt.Errorf("issue title cannot be empty") } issue := &models.Issue{ - Title: createTitle, - Description: createDescription, - Status: models.Status(createStatus), - IssueType: models.IssueType(createType), - Priority: createPriority, + Title: createFlags.title, + Description: createFlags.description, + Status: models.Status(createFlags.status), + IssueType: models.IssueType(createFlags.issueType), + Priority: createFlags.priority, } // Create the issue using the service layer. @@ -56,52 +59,61 @@ func runCreateCmd(cmd *cobra.Command, args []string) error { return fmt.Errorf("error creating issue: %w", err) } - // Build the output string with the created issue details. - str := fmt.Sprintf("Created issue with ID: %s\n", issue.ID) - - if issue.Title != "" { - str += fmt.Sprintf("Title: %s\n", issue.Title) - } - - if issue.Description != "" { - str += fmt.Sprintf("Description: %s\n", issue.Description) - } - - if issue.Status != "" { - str += fmt.Sprintf("Status: %s\n", issue.Status) - } - - if issue.IssueType != "" { - str += fmt.Sprintf("Type: %s\n", issue.IssueType) - } - - if issue.Priority != 0 { - str += fmt.Sprintf("Priority: %d\n", issue.Priority) - } - - cmd.Print(str) + // Display the created issue details to the user. + cmd.Printf("Created issue:\n%s", models.IssueString(*issue)) return nil } +func runCreateInteractive() error { + form := huh.NewForm( + + huh.NewGroup( + huh.NewInput().Value(&createFlags.title).Title("Title"), + huh.NewText().Value(&createFlags.description).Title("Description"), + ).Title("Issue Details"), + + huh.NewGroup( + huh.NewSelect[string](). + Options( + huh.NewOption("Open", "open"), + huh.NewOption("Closed", "closed"), + huh.NewOption("In Progress", "in_progress"), + ).Value(&createFlags.status).Title("Status"), + + huh.NewSelect[string](). + Options( + huh.NewOption("Bug", "bug"), + huh.NewOption("Feature", "feature"), + huh.NewOption("Task", "task"), + ).Value(&createFlags.issueType).Title("Type"), + + huh.NewSelect[int](). + Options( + huh.NewOption("0", 0), + huh.NewOption("1", 1), + huh.NewOption("2", 2), + huh.NewOption("3", 3), + huh.NewOption("4", 4), + huh.NewOption("5", 5), + ).Value(&createFlags.priority).Title("Priority"), + ).Title("Create New Issue").WithTheme(huh.ThemeBase()), + ) + + return form.Run() +} + // init function to set up the create command and its flags. func init() { - createCmd.Flags().StringVarP(&createDescription, "desc", "d", "", "Issue description") - createCmd.Flags().StringVarP(&createStatus, "status", "s", "open", "Issue status(open, closed, in_progress)") - createCmd.Flags().StringVarP(&createType, "type", "t", "task", "Issue type(bug, feature, task)") - createCmd.Flags().IntVarP(&createPriority, "priority", "p", 0, "Issue priority(0-5)") + createCmd.Flags().BoolVarP(&createFlags.interactive, "interactive", "i", false, "Create issue interactively") + createCmd.Flags().StringVarP(&createFlags.description, "desc", "d", "", "Issue description") + createCmd.Flags().StringVarP(&createFlags.status, "status", "s", "open", "Issue status(open, closed, in_progress)") + createCmd.Flags().StringVarP(&createFlags.issueType, "type", "t", "task", "Issue type(bug, feature, task)") + createCmd.Flags().IntVarP(&createFlags.priority, "priority", "p", 0, "Issue priority(0-5)") - createCmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"bug", "feature", "task"}, cobra.ShellCompDirectiveDefault - }) - - createCmd.RegisterFlagCompletionFunc("status", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"open", "closed", "in_progress"}, cobra.ShellCompDirectiveDefault - }) - - createCmd.RegisterFlagCompletionFunc("priority", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"0", "1", "2", "3", "4", "5"}, cobra.ShellCompDirectiveDefault - }) + createCmd.RegisterFlagCompletionFunc("type", completionFunc(typeOptions)) + createCmd.RegisterFlagCompletionFunc("status", completionFunc(statusOptions)) + createCmd.RegisterFlagCompletionFunc("priority", completionFunc(priorityRange)) rootCmd.AddCommand(createCmd) } From 33ea5c70d8fb880bdb8ed3c0fcf4ee69ddcd68fd Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sun, 8 Feb 2026 12:35:13 +0100 Subject: [PATCH 49/60] add interactive mode --- pkg/cli/commands/delete.go | 57 +++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index ce2cc40..4884464 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -1,15 +1,19 @@ package commands import ( + "context" "fmt" "strings" + "github.com/LazyBachelor/LazyPM/internal/models" "github.com/charmbracelet/huh" "github.com/spf13/cobra" ) // Variables for delete command flag. var confirmDelete bool +var deleteIDs []string +var deleteInteractive bool // deleteCmd represents the delete command. var deleteCmd = &cobra.Command{ @@ -18,8 +22,9 @@ var deleteCmd = &cobra.Command{ Long: `Delete an existing issue by its ID.`, Example: `pm delete pm-abc`, + ValidArgsFunction: completeIssues, + Aliases: []string{"del", "remove", "rm"}, - Args: cobra.ExactArgs(1), RunE: runDeleteCmd, } @@ -28,6 +33,17 @@ var deleteCmd = &cobra.Command{ func runDeleteCmd(cmd *cobra.Command, args []string) error { deleteID := strings.Join(args, " ") + if deleteInteractive { + if err := runDeleteInteractive(); err != nil { + return err + } + return nil + } + + if deleteID == "" { + return fmt.Errorf("issue ID cannot be empty") + } + // Fetch the issue to ensure it exists before deletion. issue, err := svc.Beads.GetIssue(cmd.Context(), deleteID) if err != nil { @@ -62,8 +78,47 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error { return nil } +func runDeleteInteractive() error { + options := []huh.Option[string]{} + + issues, err := svc.Beads.SearchIssues(context.Background(), "", models.IssueFilter{}) + if err != nil { + return fmt.Errorf("error fetching issues: %w", err) + } + + for _, issue := range issues { + desc := fmt.Sprintf("%s: %s", issue.ID, issue.Title) + options = append(options, huh.NewOption(desc, issue.ID)) + } + + form := huh.NewForm( + huh.NewGroup( + huh.NewMultiSelect[string]().Value(&deleteIDs). + Options(options...).Value(&deleteIDs). + Title("Select issues to delete"))).WithTheme(huh.ThemeBase()) + + if err := form.Run(); err != nil { + return fmt.Errorf("error running interactive form: %w", err) + } + + if len(deleteIDs) == 0 { + return fmt.Errorf("no issues selected for deletion") + } + + for _, id := range deleteIDs { + err := svc.Beads.DeleteIssue(context.Background(), id) + if err != nil { + return fmt.Errorf("error deleting issue with ID %s: %w", id, err) + } + fmt.Printf("Deleted issue with ID: %s\n", id) + } + + return nil +} + // init function to set up the delete command and its flags. func init() { + deleteCmd.Flags().BoolVarP(&deleteInteractive, "interactive", "i", false, "Delete issues interactively") deleteCmd.Flags().BoolVarP(&confirmDelete, "yes", "y", true, "Confirm deletion without prompt") rootCmd.AddCommand(deleteCmd) From 38faee631fa21d82db8d026827b2f473f3d4e7a9 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sun, 8 Feb 2026 12:35:29 +0100 Subject: [PATCH 50/60] add limit to flags --- pkg/cli/commands/root.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/cli/commands/root.go b/pkg/cli/commands/root.go index 296d029..2115fc1 100644 --- a/pkg/cli/commands/root.go +++ b/pkg/cli/commands/root.go @@ -16,6 +16,8 @@ var svc *service.Services type Flags struct { interactive bool + limit int + title string description string status string From 3bf80ba85940fd7993b6c5fe5fb87e5ac0546bcf Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Sun, 8 Feb 2026 12:56:09 +0100 Subject: [PATCH 51/60] add comments to the repl package --- pkg/cli/cli.go | 3 ++- pkg/cli/repl/completer.go | 9 +++++++-- pkg/cli/repl/executor.go | 7 +++++++ pkg/cli/repl/options.go | 9 ++------- pkg/cli/repl/repl.go | 29 ++++++++++++++++++++++++----- pkg/cli/repl/suggestions.go | 29 ++++++++++++++++++++++++++--- 6 files changed, 68 insertions(+), 18 deletions(-) diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index c85a988..c3f515c 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -1,3 +1,4 @@ +// Package cli provides the command-line interface for the PM System. package cli import ( @@ -7,7 +8,7 @@ import ( "github.com/LazyBachelor/LazyPM/pkg/cli/commands" ) -// CLIConfig is an alias for service.Config, which contains all the necessary +// CLIConfig is an alias for service.Config, used to configure the CLI. type CLIConfig = service.Config // Run initializes the services and executes the CLI commands. diff --git a/pkg/cli/repl/completer.go b/pkg/cli/repl/completer.go index 9cb119a..99d1b21 100644 --- a/pkg/cli/repl/completer.go +++ b/pkg/cli/repl/completer.go @@ -6,23 +6,28 @@ import ( "github.com/c-bata/go-prompt" ) +// completer provides suggestions for the REPL input based on the current input text. func completer(d prompt.Document) []prompt.Suggest { - text := d.TextBeforeCursor() - words := strings.Fields(text) + text := d.TextBeforeCursor() // Gets the text before the cursor as a string. + words := strings.Fields(text) // Split the string into words as []string. + // If there are no words, return no suggestions. if len(words) == 0 { return nil } + // If the first word is not "pm", only provide root-level suggestions. if words[0] != "pm" { return filterByPrefix(rootSuggestions, words[0]) } + // If the first word is "pm", provide command and flag suggestions based on the context. pmWords := words[1:] if len(words) == 1 || (len(pmWords) == 1 && !strings.HasSuffix(text, " ")) { return commandSuggestions(pmWords) } + // If the last word starts with a "-", provide flag suggestions for the current command. if len(pmWords) >= 1 { return flagSuggestions(pmWords[0], pmWords, text) } diff --git a/pkg/cli/repl/executor.go b/pkg/cli/repl/executor.go index 0ec939f..c0c50a7 100644 --- a/pkg/cli/repl/executor.go +++ b/pkg/cli/repl/executor.go @@ -7,6 +7,9 @@ import ( "github.com/LazyBachelor/LazyPM/pkg/cli/commands" ) +// execute processes the input command and returns the output +// or an error if it occurs. It handles what type of command is being executed, +// whether it's a PM command or a shell command, and routes it accordingly. func execute(input string) (string, error) { if input == "" { return "", nil @@ -26,6 +29,8 @@ func execute(input string) (string, error) { return executeShellCommand(input) } +// executeShellCommand executes a shell command +// and returns its output or an error if it occurs. func executeShellCommand(input string) (string, error) { parts := strings.Fields(input) if len(parts) == 0 { @@ -37,6 +42,8 @@ func executeShellCommand(input string) (string, error) { return string(output), err } +// executePMCommand executes a PM command using the commands package +// and returns its output or an error if it occurs. func executePMCommand(input string) (string, error) { parts := strings.Fields(input) if len(parts) == 0 { diff --git a/pkg/cli/repl/options.go b/pkg/cli/repl/options.go index 7ba4e63..0d0918c 100644 --- a/pkg/cli/repl/options.go +++ b/pkg/cli/repl/options.go @@ -5,13 +5,8 @@ import "github.com/c-bata/go-prompt" const PromptPrefix = "> " const OptionMaxSuggestions = 5 -const ( - ReplHelp = `Type 'pm help' for available PM commands. -You can also run shell commands directly. Type 'exit' or 'quit' to leave.` - - ReplTitle = "Welcome to Project Management CLI! " + ReplHelp -) - +// promptOptions returns a slice of prompt.Option +// to configure the behavior and appearance of the REPL prompt. func promptOptions(history []string) []prompt.Option { return []prompt.Option{ prompt.OptionPrefixTextColor(prompt.Cyan), diff --git a/pkg/cli/repl/repl.go b/pkg/cli/repl/repl.go index b00fa75..cba9569 100644 --- a/pkg/cli/repl/repl.go +++ b/pkg/cli/repl/repl.go @@ -1,3 +1,4 @@ +// Package repl implements the Read-Eval-Print Loop (REPL) for the PM CLI. package repl import ( @@ -14,45 +15,63 @@ import ( "golang.org/x/term" ) +const ( + ReplHelp = `Type 'pm help' for available PM commands. +You can also run shell commands directly. Type 'exit' or 'quit' to leave.` + + ReplTitle = "Welcome to Project Management CLI! " + ReplHelp +) + +// RunREPL starts the interactive Read-Eval-Print Loop for the PM CLI. func RunREPL(ctx context.Context, config cli.CLIConfig) error { + // Set terminal to raw mode to capture input properly in the REPL. + // This allows us to handle input character by character and provide a better user experience. + // We also ensure that the terminal state is restored when the REPL exits, even if an error occurs. oldState, err := term.GetState(int(os.Stdin.Fd())) if err != nil { return fmt.Errorf("failed to get terminal state: %w", err) } defer term.Restore(int(os.Stdin.Fd()), oldState) + // Initialize services for beads, config and stats. svc, cleanup, err := service.NewServices(ctx, config) if err != nil { return fmt.Errorf("failed to initialize services: %w", err) } defer cleanup() + // Make sure to set services, to ensure they are available. commands.SetServices(svc) - fmt.Println(styles.TitleStyle.Render(ReplTitle)) + fmt.Println(styles.TitleStyle.Render(ReplTitle)) // Print REPL title. + // history keeps track of command history. + // This enables navigating through previous commands. var history []string + // Start the REPL loop, which continues until the user types "exit" or "quit". for { + // Prompt the user for input, and provide suggestions. input := prompt.Input( PromptPrefix, completer, promptOptions(history)..., ) + // Trim whitespace from the input to ensure consistent command processing. input = strings.TrimSpace(input) + // If the user types "exit" or "quit", break the loop and exit the REPL. if input == "exit" || input == "quit" { fmt.Println("Goodbye!") break } + // Add the input to the history for future navigation. history = append(history, input) - // Ignore errors for now, gives better ux - output, _ := execute(input) - - fmt.Println(styles.CommandStyle.Render(output)) + output, _ := execute(input) // Ignore errors for now, gives better ux + fmt.Println(styles.CommandStyle.Render(output)) // Print the output of the command in a styled format. } return nil diff --git a/pkg/cli/repl/suggestions.go b/pkg/cli/repl/suggestions.go index cf8b925..bc347b2 100644 --- a/pkg/cli/repl/suggestions.go +++ b/pkg/cli/repl/suggestions.go @@ -9,6 +9,7 @@ import ( "github.com/muesli/reflow/truncate" ) +// rootSuggestions is a list of prompt suggestions for root-level commands. var rootSuggestions = []prompt.Suggest{ {Text: "pm", Description: "Project Management System"}, {Text: "exit", Description: "Exit pm CLI"}, @@ -17,6 +18,7 @@ var rootSuggestions = []prompt.Suggest{ {Text: "git", Description: "Version control system"}, } +// commandSuggestions is a list of prompt suggestions for PM commands. var baseSuggestions = []prompt.Suggest{ {Text: "help", Description: "Show help information"}, {Text: "delete", Description: "Delete an issue by ID"}, @@ -26,6 +28,7 @@ var baseSuggestions = []prompt.Suggest{ {Text: "list", Description: "List all issues"}, } +// createFlags is a list of prompt suggestions for the create command flags. var createFlags = []prompt.Suggest{ {Text: "--desc", Description: "Issue description"}, {Text: "--status", Description: "Issue status (open, closed, in_progress)"}, @@ -33,6 +36,7 @@ var createFlags = []prompt.Suggest{ {Text: "--priority", Description: "Issue priority (0-5)"}, } +// listFlags is a list of prompt suggestions for the list command flags. var listFlags = []prompt.Suggest{ {Text: "--title", Description: "Filter by title"}, {Text: "--desc", Description: "Filter by description"}, @@ -42,27 +46,42 @@ var listFlags = []prompt.Suggest{ {Text: "--limit", Description: "Limit number of results"}, } +// statusValues is a list of prompt suggestions for status types var statusValues = []prompt.Suggest{ {Text: "open", Description: "Open status"}, {Text: "closed", Description: "Closed status"}, {Text: "in_progress", Description: "In progress status"}, } +// typeValues is a list of prompt suggestions for issue types var typeValues = []prompt.Suggest{ {Text: "bug", Description: "Bug issue type"}, {Text: "feature", Description: "Feature issue type"}, {Text: "task", Description: "Task issue type"}, } +// priorityValues is a list of prompt suggestions for issue priority levels var priorityValues = []prompt.Suggest{ {Text: "0", Description: "Lowest priority"}, {Text: "1", Description: "Low priority"}, {Text: "2", Description: "Medium-low priority"}, {Text: "3", Description: "Medium priority"}, {Text: "4", Description: "High priority"}, - {Text: "5", Description: "Highest priority"}, } +// isIDCommand maps command names to a boolean indicating whether they expect an issue ID as an argument. +var isIDCommand = map[string]bool{ + "describe": true, + "delete": true, + "del": true, + "rm": true, + "remove": true, + "get": true, + "read": true, + "close": true, +} + +// commandSuggestions returns a list of prompt suggestions based on the current input words. func commandSuggestions(words []string) []prompt.Suggest { if len(words) == 0 { return baseSuggestions @@ -70,6 +89,7 @@ func commandSuggestions(words []string) []prompt.Suggest { return filterByPrefix(baseSuggestions, words[0]) } +// flagSuggestions returns a list of prompt suggestions for command flags based on the current input. func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { lastWord, prevWord := parseWords(words, text) @@ -77,8 +97,7 @@ func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { return filterByPrefix(values, lastWord) } - if cmd == "describe" || cmd == "delete" || cmd == "del" || - cmd == "rm" || cmd == "remove" || cmd == "get" || cmd == "read" || cmd == "close" { + if isIDCommand[cmd] { // For ID-oriented commands, pass the current partial argument (lastWord) // so issueIDSuggestions can distinguish between completing the command // name and completing the ID itself. @@ -101,6 +120,7 @@ func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { return filterByPrefix(flags, lastWord) } +// issueIDSuggestions returns a list of prompt suggestions for issue IDs based on the current partial input. func issueIDSuggestions(partial string, hasCommand bool) []prompt.Suggest { // Only show suggestions if we've typed the command already if !hasCommand { @@ -119,6 +139,7 @@ func issueIDSuggestions(partial string, hasCommand bool) []prompt.Suggest { return suggestions } +// parseWords extracts the last and previous words from the input for flag suggestion logic. func parseWords(words []string, text string) (lastWord, prevWord string) { if len(words) > 0 && !strings.HasSuffix(text, " ") { lastWord = words[len(words)-1] @@ -131,6 +152,7 @@ func parseWords(words []string, text string) (lastWord, prevWord string) { return } +// getFlagValues returns a list of prompt suggestions for flag values based on the given flag. func getFlagValues(flag string) []prompt.Suggest { switch flag { case "-s", "--status": @@ -143,6 +165,7 @@ func getFlagValues(flag string) []prompt.Suggest { return nil } +// filterByPrefix filters a list of prompt suggestions based on a given prefix. func filterByPrefix(suggestions []prompt.Suggest, prefix string) []prompt.Suggest { if prefix == "" { return suggestions From 431f9e4f5d1969da300e70d0df22ff51b3e81803 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Mon, 9 Feb 2026 19:13:46 +0100 Subject: [PATCH 52/60] add comments to fuctions. make sure priority ranges form 0-4 --- pkg/cli/commands/completion.go | 1 + pkg/cli/commands/create.go | 5 +++-- pkg/cli/commands/delete.go | 10 +++++++--- pkg/cli/commands/root.go | 1 + 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/cli/commands/completion.go b/pkg/cli/commands/completion.go index af34c20..77d3fcf 100644 --- a/pkg/cli/commands/completion.go +++ b/pkg/cli/commands/completion.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/cobra" ) +// Variables for completion options and functions. var ( typeOptions = []string{"bug", "feature", "task"} statusOptions = []string{"open", "closed", "in_progress"} diff --git a/pkg/cli/commands/create.go b/pkg/cli/commands/create.go index 95e9d53..84504db 100644 --- a/pkg/cli/commands/create.go +++ b/pkg/cli/commands/create.go @@ -65,6 +65,8 @@ func runCreateCmd(cmd *cobra.Command, args []string) error { return nil } +// runCreateInteractive runs the interactive mode for creating issues, +// allowing users to input issue details through a form. func runCreateInteractive() error { form := huh.NewForm( @@ -95,7 +97,6 @@ func runCreateInteractive() error { huh.NewOption("2", 2), huh.NewOption("3", 3), huh.NewOption("4", 4), - huh.NewOption("5", 5), ).Value(&createFlags.priority).Title("Priority"), ).Title("Create New Issue").WithTheme(huh.ThemeBase()), ) @@ -109,7 +110,7 @@ func init() { createCmd.Flags().StringVarP(&createFlags.description, "desc", "d", "", "Issue description") createCmd.Flags().StringVarP(&createFlags.status, "status", "s", "open", "Issue status(open, closed, in_progress)") createCmd.Flags().StringVarP(&createFlags.issueType, "type", "t", "task", "Issue type(bug, feature, task)") - createCmd.Flags().IntVarP(&createFlags.priority, "priority", "p", 0, "Issue priority(0-5)") + createCmd.Flags().IntVarP(&createFlags.priority, "priority", "p", 0, "Issue priority(0-4)") createCmd.RegisterFlagCompletionFunc("type", completionFunc(typeOptions)) createCmd.RegisterFlagCompletionFunc("status", completionFunc(statusOptions)) diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index 4884464..a684e53 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -11,9 +11,11 @@ import ( ) // Variables for delete command flag. -var confirmDelete bool -var deleteIDs []string -var deleteInteractive bool +var ( + confirmDelete bool + deleteIDs []string + deleteInteractive bool +) // deleteCmd represents the delete command. var deleteCmd = &cobra.Command{ @@ -78,6 +80,8 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error { return nil } +// runDeleteInteractive runs the interactive mode for deleting issues, +// allowing users to select multiple issues for deletion. func runDeleteInteractive() error { options := []huh.Option[string]{} diff --git a/pkg/cli/commands/root.go b/pkg/cli/commands/root.go index 2115fc1..9e18856 100644 --- a/pkg/cli/commands/root.go +++ b/pkg/cli/commands/root.go @@ -14,6 +14,7 @@ import ( // Must be called before executing any commands to ensure services are available. var svc *service.Services +// Flags struct to hold command-line flag values for issues. type Flags struct { interactive bool limit int From 9d6c3fe797e2b0234b723197d969b943a2f16301 Mon Sep 17 00:00:00 2001 From: vb Date: Sat, 7 Feb 2026 15:33:09 +0100 Subject: [PATCH 53/60] adding update feature to cli --- pkg/cli/commands/update.go | 126 ++++++++++++++++++++++++++++++++++++ pkg/cli/repl/suggestions.go | 22 +++++++ 2 files changed, 148 insertions(+) create mode 100644 pkg/cli/commands/update.go diff --git a/pkg/cli/commands/update.go b/pkg/cli/commands/update.go new file mode 100644 index 0000000..6a262d6 --- /dev/null +++ b/pkg/cli/commands/update.go @@ -0,0 +1,126 @@ +package commands + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +var ( + updateDescription string + updateStatus string + updateType string + updatePriority int + updateTitle string +) + +var updateCmd = &cobra.Command{ + Use: "update [issue ID]", + Short: "Update an existing issue", + Long: `Update an existing issue by its ID with the specified details.`, + Example: `pm update pm-001 --title "New title" -d "Description" -s in_progress --type task -p 3`, + RunE: runUpdateCmd, + Aliases: []string{"edit"}, + Args: cobra.ExactArgs(1), + ValidArgsFunction: completeIssues, +} + +func init() { + updateCmd.Flags().StringVar(&updateTitle, "title", "", "New issue title") + updateCmd.Flags().StringVarP(&updateDescription, "desc", "d", "", "New issue description") + updateCmd.Flags().StringVarP(&updateStatus, "status", "s", "", "New issue status(open, closed, in_progress)") + updateCmd.Flags().StringVarP(&updateType, "type", "", "", "New issue type(bug, feature, task)") + updateCmd.Flags().IntVarP(&updatePriority, "priority", "p", -1, "New issue priority(0-5)") + + updateCmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"bug", "feature", "task"}, cobra.ShellCompDirectiveDefault + }) + + updateCmd.RegisterFlagCompletionFunc("status", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"open", "closed", "in_progress"}, cobra.ShellCompDirectiveDefault + }) + + updateCmd.RegisterFlagCompletionFunc("priority", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + return []string{"0", "1", "2", "3", "4", "5"}, cobra.ShellCompDirectiveDefault + }) + + rootCmd.AddCommand(updateCmd) +} + +func runUpdateCmd(cmd *cobra.Command, args []string) error { + issueID := args[0] + + updates := make(map[string]interface{}) + + if cmd.Flags().Changed("title") { + if updateTitle == "" { + return fmt.Errorf("issue title cannot be empty") + } + updates["title"] = updateTitle + } + + if cmd.Flags().Changed("desc") { + updates["description"] = updateDescription + } + + if cmd.Flags().Changed("status") { + updates["status"] = updateStatus + } + + if cmd.Flags().Changed("type") { + updates["issue_type"] = updateType + } + + if cmd.Flags().Changed("priority") { + updates["priority"] = updatePriority + } + + if len(updates) == 0 { + return fmt.Errorf("no updates specified") + } + + issue, err := svc.Beads.GetIssue(cmd.Context(), issueID) + if err != nil { + return fmt.Errorf("error getting issue: %w", err) + } + + if issue == nil { + return fmt.Errorf("issue with ID '%s' not found", issueID) + } + + err = svc.Beads.UpdateIssue(cmd.Context(), issueID, updates, "test_actor") + if err != nil { + return fmt.Errorf("error updating issue: %w", err) + } + + updatedIssue, err := svc.Beads.GetIssue(cmd.Context(), issueID) + if err != nil { + return fmt.Errorf("error getting updated issue: %w", err) + } + + str := fmt.Sprintf("Updated issue with ID: %s\n", issueID) + + if updatedIssue.Title != "" { + str += fmt.Sprintf("Title: %s\n", updatedIssue.Title) + } + + if updatedIssue.Description != "" { + str += fmt.Sprintf("Description: %s\n", updatedIssue.Description) + } + + if updatedIssue.Status != "" { + str += fmt.Sprintf("Status: %s\n", updatedIssue.Status) + } + + if updatedIssue.IssueType != "" { + str += fmt.Sprintf("Type: %s\n", updatedIssue.IssueType) + } + + if updatedIssue.Priority != 0 { + str += fmt.Sprintf("Priority: %d\n", updatedIssue.Priority) + } + + fmt.Print(str) + + return nil +} diff --git a/pkg/cli/repl/suggestions.go b/pkg/cli/repl/suggestions.go index bc347b2..4c38f8a 100644 --- a/pkg/cli/repl/suggestions.go +++ b/pkg/cli/repl/suggestions.go @@ -24,6 +24,7 @@ var baseSuggestions = []prompt.Suggest{ {Text: "delete", Description: "Delete an issue by ID"}, {Text: "close", Description: "Close an issue by ID"}, {Text: "create", Description: "Create a new issue with title"}, + {Text: "update", Description: "Update an existing issue by ID"}, {Text: "describe", Description: "Get issue details by ID"}, {Text: "list", Description: "List all issues"}, } @@ -36,6 +37,14 @@ var createFlags = []prompt.Suggest{ {Text: "--priority", Description: "Issue priority (0-5)"}, } +var updateFlags = []prompt.Suggest{ + {Text: "--title", Description: "New issue title"}, + {Text: "--desc", Description: "New issue description"}, + {Text: "--status", Description: "New issue status (open, closed, in_progress)"}, + {Text: "--type", Description: "New issue type (bug, feature, task)"}, + {Text: "--priority", Description: "New issue priority (0-5)"}, +} + // listFlags is a list of prompt suggestions for the list command flags. var listFlags = []prompt.Suggest{ {Text: "--title", Description: "Filter by title"}, @@ -104,6 +113,19 @@ func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { return issueIDSuggestions(lastWord, len(words) >= 2) } + // Update/edit: suggest issue IDs when typing the ID, flags after ID is provided + if cmd == "update" || cmd == "edit" { + if len(words) >= 2 && (lastWord == "" || strings.HasPrefix(lastWord, "-")) { + // ID already provided (trailing space) or typing a flag - suggest flags + flags := updateFlags + if lastWord == "" { + return flags + } + return filterByPrefix(flags, lastWord) + } + return issueIDSuggestions(lastWord, len(words) >= 2) + } + var flags []prompt.Suggest switch cmd { case "create", "add": From 7d0877dfb00d3a7dd22b63dcbdf12a8987b1c561 Mon Sep 17 00:00:00 2001 From: vb Date: Sat, 7 Feb 2026 15:39:05 +0100 Subject: [PATCH 54/60] fix --- pkg/cli/repl/suggestions.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/repl/suggestions.go b/pkg/cli/repl/suggestions.go index 4c38f8a..c62e499 100644 --- a/pkg/cli/repl/suggestions.go +++ b/pkg/cli/repl/suggestions.go @@ -116,7 +116,7 @@ func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { // Update/edit: suggest issue IDs when typing the ID, flags after ID is provided if cmd == "update" || cmd == "edit" { if len(words) >= 2 && (lastWord == "" || strings.HasPrefix(lastWord, "-")) { - // ID already provided (trailing space) or typing a flag - suggest flags + // ID already provided (trailing space) or typing a flag -> suggest update flags flags := updateFlags if lastWord == "" { return flags From 742daef89268e6309005daafa2eec1e3b007a75f Mon Sep 17 00:00:00 2001 From: viljarb0 <156418063+viljarb0@users.noreply.github.com> Date: Sun, 8 Feb 2026 09:43:54 +0100 Subject: [PATCH 55/60] Update pkg/cli/commands/update.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/cli/commands/update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/commands/update.go b/pkg/cli/commands/update.go index 6a262d6..03f5754 100644 --- a/pkg/cli/commands/update.go +++ b/pkg/cli/commands/update.go @@ -116,7 +116,7 @@ func runUpdateCmd(cmd *cobra.Command, args []string) error { str += fmt.Sprintf("Type: %s\n", updatedIssue.IssueType) } - if updatedIssue.Priority != 0 { + if cmd.Flags().Changed("priority") { str += fmt.Sprintf("Priority: %d\n", updatedIssue.Priority) } From c6f5363ae8f56afa1a85a65bfadfca816bd9a654 Mon Sep 17 00:00:00 2001 From: viljarb0 <156418063+viljarb0@users.noreply.github.com> Date: Sun, 8 Feb 2026 09:44:12 +0100 Subject: [PATCH 56/60] Update pkg/cli/commands/update.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/cli/commands/update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cli/commands/update.go b/pkg/cli/commands/update.go index 03f5754..81c8cec 100644 --- a/pkg/cli/commands/update.go +++ b/pkg/cli/commands/update.go @@ -120,7 +120,7 @@ func runUpdateCmd(cmd *cobra.Command, args []string) error { str += fmt.Sprintf("Priority: %d\n", updatedIssue.Priority) } - fmt.Print(str) + cmd.Print(str) return nil } From fa6b57e6c0b706e61a8b0089fff904e49caabe55 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Mon, 9 Feb 2026 20:28:32 +0100 Subject: [PATCH 57/60] refactor and clean up update command --- pkg/cli/commands/update.go | 138 +++++++++++++++---------------------- 1 file changed, 54 insertions(+), 84 deletions(-) diff --git a/pkg/cli/commands/update.go b/pkg/cli/commands/update.go index 81c8cec..a93bc36 100644 --- a/pkg/cli/commands/update.go +++ b/pkg/cli/commands/update.go @@ -3,16 +3,11 @@ package commands import ( "fmt" + "github.com/LazyBachelor/LazyPM/internal/models" "github.com/spf13/cobra" ) -var ( - updateDescription string - updateStatus string - updateType string - updatePriority int - updateTitle string -) +var updateFlags Flags var updateCmd = &cobra.Command{ Use: "update [issue ID]", @@ -25,67 +20,17 @@ var updateCmd = &cobra.Command{ ValidArgsFunction: completeIssues, } -func init() { - updateCmd.Flags().StringVar(&updateTitle, "title", "", "New issue title") - updateCmd.Flags().StringVarP(&updateDescription, "desc", "d", "", "New issue description") - updateCmd.Flags().StringVarP(&updateStatus, "status", "s", "", "New issue status(open, closed, in_progress)") - updateCmd.Flags().StringVarP(&updateType, "type", "", "", "New issue type(bug, feature, task)") - updateCmd.Flags().IntVarP(&updatePriority, "priority", "p", -1, "New issue priority(0-5)") - - updateCmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"bug", "feature", "task"}, cobra.ShellCompDirectiveDefault - }) - - updateCmd.RegisterFlagCompletionFunc("status", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"open", "closed", "in_progress"}, cobra.ShellCompDirectiveDefault - }) - - updateCmd.RegisterFlagCompletionFunc("priority", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"0", "1", "2", "3", "4", "5"}, cobra.ShellCompDirectiveDefault - }) - - rootCmd.AddCommand(updateCmd) -} - func runUpdateCmd(cmd *cobra.Command, args []string) error { issueID := args[0] - updates := make(map[string]interface{}) - - if cmd.Flags().Changed("title") { - if updateTitle == "" { - return fmt.Errorf("issue title cannot be empty") - } - updates["title"] = updateTitle - } - - if cmd.Flags().Changed("desc") { - updates["description"] = updateDescription - } - - if cmd.Flags().Changed("status") { - updates["status"] = updateStatus - } - - if cmd.Flags().Changed("type") { - updates["issue_type"] = updateType - } - - if cmd.Flags().Changed("priority") { - updates["priority"] = updatePriority - } - - if len(updates) == 0 { - return fmt.Errorf("no updates specified") - } - issue, err := svc.Beads.GetIssue(cmd.Context(), issueID) - if err != nil { + if err != nil || issue == nil { return fmt.Errorf("error getting issue: %w", err) } - if issue == nil { - return fmt.Errorf("issue with ID '%s' not found", issueID) + updates, err := getUpdateValues(cmd) + if err != nil { + return fmt.Errorf("error getting update values: %w", err) } err = svc.Beads.UpdateIssue(cmd.Context(), issueID, updates, "test_actor") @@ -98,29 +43,54 @@ func runUpdateCmd(cmd *cobra.Command, args []string) error { return fmt.Errorf("error getting updated issue: %w", err) } - str := fmt.Sprintf("Updated issue with ID: %s\n", issueID) - - if updatedIssue.Title != "" { - str += fmt.Sprintf("Title: %s\n", updatedIssue.Title) - } - - if updatedIssue.Description != "" { - str += fmt.Sprintf("Description: %s\n", updatedIssue.Description) - } - - if updatedIssue.Status != "" { - str += fmt.Sprintf("Status: %s\n", updatedIssue.Status) - } - - if updatedIssue.IssueType != "" { - str += fmt.Sprintf("Type: %s\n", updatedIssue.IssueType) - } - - if cmd.Flags().Changed("priority") { - str += fmt.Sprintf("Priority: %d\n", updatedIssue.Priority) - } - - cmd.Print(str) + cmd.Printf("Updated issue to:\n%s", models.IssueString(*updatedIssue)) return nil } + +func init() { + updateCmd.Flags().StringVar(&updateFlags.title, "title", "", "New issue title") + updateCmd.Flags().StringVarP(&updateFlags.description, "desc", "d", "", "New issue description") + updateCmd.Flags().StringVarP(&updateFlags.status, "status", "s", "", "New issue status(open, closed, in_progress)") + updateCmd.Flags().StringVarP(&updateFlags.issueType, "type", "t", "", "New issue type(bug, feature, task)") + updateCmd.Flags().IntVarP(&updateFlags.priority, "priority", "p", 0, "New issue priority(0-5)") + + updateCmd.RegisterFlagCompletionFunc("type", completionFunc(typeOptions)) + updateCmd.RegisterFlagCompletionFunc("status", completionFunc(statusOptions)) + updateCmd.RegisterFlagCompletionFunc("priority", completionFunc(priorityRange)) + + rootCmd.AddCommand(updateCmd) +} + +func getUpdateValues(cmd *cobra.Command) (map[string]interface{}, error) { + updates := make(map[string]interface{}) + + if cmd.Flags().Changed("title") { + if updateFlags.title == "" { + return updates, fmt.Errorf("issue title cannot be empty") + } + updates["title"] = updateFlags.title + } + + if cmd.Flags().Changed("desc") { + updates["description"] = updateFlags.description + } + + if cmd.Flags().Changed("status") { + updates["status"] = updateFlags.status + } + + if cmd.Flags().Changed("type") { + updates["issue_type"] = updateFlags.issueType + } + + if cmd.Flags().Changed("priority") { + updates["priority"] = updateFlags.priority + } + + if len(updates) == 0 { + return updates, fmt.Errorf("no updates specified") + } + + return updates, nil +} From 155d9d79ae992387e01bc6e99fbd6405031a639a Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Mon, 9 Feb 2026 20:28:42 +0100 Subject: [PATCH 58/60] refine suggestions a bit --- pkg/cli/repl/suggestions.go | 47 ++++++++++++++----------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/pkg/cli/repl/suggestions.go b/pkg/cli/repl/suggestions.go index c62e499..ba79385 100644 --- a/pkg/cli/repl/suggestions.go +++ b/pkg/cli/repl/suggestions.go @@ -37,6 +37,7 @@ var createFlags = []prompt.Suggest{ {Text: "--priority", Description: "Issue priority (0-5)"}, } +// updateFlags is a list of prompt suggestions for the update command flags. var updateFlags = []prompt.Suggest{ {Text: "--title", Description: "New issue title"}, {Text: "--desc", Description: "New issue description"}, @@ -88,6 +89,18 @@ var isIDCommand = map[string]bool{ "get": true, "read": true, "close": true, + "update": true, + "edit": true, +} + +var commandFlags = map[string][]prompt.Suggest{ + "create": createFlags, + "add": createFlags, + "update": updateFlags, + "edit": updateFlags, + "list": listFlags, + "ls": listFlags, + "search": listFlags, } // commandSuggestions returns a list of prompt suggestions based on the current input words. @@ -106,39 +119,15 @@ func flagSuggestions(cmd string, words []string, text string) []prompt.Suggest { return filterByPrefix(values, lastWord) } + flags := commandFlags[cmd] + if isIDCommand[cmd] { - // For ID-oriented commands, pass the current partial argument (lastWord) - // so issueIDSuggestions can distinguish between completing the command - // name and completing the ID itself. - return issueIDSuggestions(lastWord, len(words) >= 2) - } - - // Update/edit: suggest issue IDs when typing the ID, flags after ID is provided - if cmd == "update" || cmd == "edit" { - if len(words) >= 2 && (lastWord == "" || strings.HasPrefix(lastWord, "-")) { - // ID already provided (trailing space) or typing a flag -> suggest update flags - flags := updateFlags - if lastWord == "" { - return flags - } - return filterByPrefix(flags, lastWord) + if len(words) < 2 && !strings.HasPrefix(lastWord, "-") { + return issueIDSuggestions(lastWord, true) } - return issueIDSuggestions(lastWord, len(words) >= 2) + return filterByPrefix(flags, lastWord) } - var flags []prompt.Suggest - switch cmd { - case "create", "add": - flags = createFlags - case "list", "ls", "search": - flags = listFlags - default: - return nil - } - - if lastWord == "" { - return flags - } return filterByPrefix(flags, lastWord) } From bb096ff19da719dbf18ad70bdd6bab13d7c206f0 Mon Sep 17 00:00:00 2001 From: Robin Olsen <129996395+Telikz@users.noreply.github.com> Date: Mon, 9 Feb 2026 23:42:44 +0100 Subject: [PATCH 59/60] Update pkg/cli/repl/suggestions.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pkg/cli/repl/suggestions.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/cli/repl/suggestions.go b/pkg/cli/repl/suggestions.go index 579ed2f..ba79385 100644 --- a/pkg/cli/repl/suggestions.go +++ b/pkg/cli/repl/suggestions.go @@ -25,7 +25,6 @@ var baseSuggestions = []prompt.Suggest{ {Text: "close", Description: "Close an issue by ID"}, {Text: "create", Description: "Create a new issue with title"}, {Text: "update", Description: "Update an existing issue by ID"}, - {Text: "update", Description: "Update an existing issue by ID"}, {Text: "describe", Description: "Get issue details by ID"}, {Text: "list", Description: "List all issues"}, } From c773e61f4e5e87f8bb9c43caf964d9b6af1672e1 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Tue, 10 Feb 2026 00:04:13 +0100 Subject: [PATCH 60/60] implement suggestions from copilot --- pkg/cli/commands/close.go | 21 ++++++++++++--------- pkg/cli/commands/create.go | 18 ++++++++---------- pkg/cli/commands/delete.go | 10 +++++----- pkg/cli/commands/update.go | 6 +++++- pkg/cli/repl/suggestions.go | 10 ++++++++++ 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/pkg/cli/commands/close.go b/pkg/cli/commands/close.go index 4bfecaa..b4ff882 100644 --- a/pkg/cli/commands/close.go +++ b/pkg/cli/commands/close.go @@ -2,7 +2,6 @@ package commands import ( "fmt" - "strings" "github.com/charmbracelet/huh" "github.com/spf13/cobra" @@ -11,19 +10,21 @@ import ( // closeCmd represents the close command, // which allows users to close an existing issue by its ID. var closeCmd = &cobra.Command{ - Use: "close [id]", - Short: "Close an existing issue", - Long: `Close an existing issue by its ID.`, - Example: `pm close pm-abc`, - ValidArgsFunction: completeIssues, + Use: "close [id]", + Short: "Close an existing issue", + Long: `Close an existing issue by its ID.`, + Example: `pm close pm-abc`, + Args: cobra.ExactArgs(1), RunE: runCloseCmd, + + ValidArgsFunction: completeIssues, } // runCloseCmd executes the close command logic, // which closes an issue by its ID after confirming with the user. func runCloseCmd(cmd *cobra.Command, args []string) error { - closeID := strings.Join(args, " ") + closeID := args[0] if closeID == "" { return fmt.Errorf("issue ID cannot be empty") @@ -40,8 +41,10 @@ func runCloseCmd(cmd *cobra.Command, args []string) error { } // Ask for closing reason - huh.NewInput().Value(&issue.CloseReason). - Title("Reason for closing the issue?").WithTheme(huh.ThemeBase()).Run() + if err = huh.NewInput().Value(&issue.CloseReason). + Title("Reason for closing the issue?").WithTheme(huh.ThemeBase()).Run(); err != nil { + return fmt.Errorf("error getting close reason: %w", err) + } // Close the issue. err = svc.Beads.CloseIssue(cmd.Context(), closeID, issue.CloseReason, "", "") diff --git a/pkg/cli/commands/create.go b/pkg/cli/commands/create.go index 84504db..538ed27 100644 --- a/pkg/cli/commands/create.go +++ b/pkg/cli/commands/create.go @@ -72,34 +72,32 @@ func runCreateInteractive() error { huh.NewGroup( huh.NewInput().Value(&createFlags.title).Title("Title"), - huh.NewText().Value(&createFlags.description).Title("Description"), - ).Title("Issue Details"), + huh.NewText().Value(&createFlags.description).Title("Description")), huh.NewGroup( - huh.NewSelect[string](). + huh.NewSelect[string]().Title("Status"). Options( huh.NewOption("Open", "open"), huh.NewOption("Closed", "closed"), huh.NewOption("In Progress", "in_progress"), - ).Value(&createFlags.status).Title("Status"), + ).Value(&createFlags.status), - huh.NewSelect[string](). + huh.NewSelect[string]().Title("Type"). Options( huh.NewOption("Bug", "bug"), huh.NewOption("Feature", "feature"), huh.NewOption("Task", "task"), - ).Value(&createFlags.issueType).Title("Type"), + ).Value(&createFlags.issueType), - huh.NewSelect[int](). + huh.NewSelect[int]().Title("Priority"). Options( huh.NewOption("0", 0), huh.NewOption("1", 1), huh.NewOption("2", 2), huh.NewOption("3", 3), huh.NewOption("4", 4), - ).Value(&createFlags.priority).Title("Priority"), - ).Title("Create New Issue").WithTheme(huh.ThemeBase()), - ) + ).Value(&createFlags.priority), + )).WithTheme(huh.ThemeBase16()) return form.Run() } diff --git a/pkg/cli/commands/delete.go b/pkg/cli/commands/delete.go index a684e53..b96e659 100644 --- a/pkg/cli/commands/delete.go +++ b/pkg/cli/commands/delete.go @@ -36,7 +36,7 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error { deleteID := strings.Join(args, " ") if deleteInteractive { - if err := runDeleteInteractive(); err != nil { + if err := runDeleteInteractive(cmd.Context()); err != nil { return err } return nil @@ -82,10 +82,10 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error { // runDeleteInteractive runs the interactive mode for deleting issues, // allowing users to select multiple issues for deletion. -func runDeleteInteractive() error { +func runDeleteInteractive(ctx context.Context) error { options := []huh.Option[string]{} - issues, err := svc.Beads.SearchIssues(context.Background(), "", models.IssueFilter{}) + issues, err := svc.Beads.SearchIssues(ctx, "", models.IssueFilter{}) if err != nil { return fmt.Errorf("error fetching issues: %w", err) } @@ -97,7 +97,7 @@ func runDeleteInteractive() error { form := huh.NewForm( huh.NewGroup( - huh.NewMultiSelect[string]().Value(&deleteIDs). + huh.NewMultiSelect[string](). Options(options...).Value(&deleteIDs). Title("Select issues to delete"))).WithTheme(huh.ThemeBase()) @@ -110,7 +110,7 @@ func runDeleteInteractive() error { } for _, id := range deleteIDs { - err := svc.Beads.DeleteIssue(context.Background(), id) + err := svc.Beads.DeleteIssue(ctx, id) if err != nil { return fmt.Errorf("error deleting issue with ID %s: %w", id, err) } diff --git a/pkg/cli/commands/update.go b/pkg/cli/commands/update.go index a93bc36..099a08c 100644 --- a/pkg/cli/commands/update.go +++ b/pkg/cli/commands/update.go @@ -24,10 +24,14 @@ func runUpdateCmd(cmd *cobra.Command, args []string) error { issueID := args[0] issue, err := svc.Beads.GetIssue(cmd.Context(), issueID) - if err != nil || issue == nil { + if err != nil { return fmt.Errorf("error getting issue: %w", err) } + if issue == nil { + return fmt.Errorf("issue with ID %s not found", issueID) + } + updates, err := getUpdateValues(cmd) if err != nil { return fmt.Errorf("error getting update values: %w", err) diff --git a/pkg/cli/repl/suggestions.go b/pkg/cli/repl/suggestions.go index ba79385..e99c681 100644 --- a/pkg/cli/repl/suggestions.go +++ b/pkg/cli/repl/suggestions.go @@ -31,6 +31,7 @@ var baseSuggestions = []prompt.Suggest{ // createFlags is a list of prompt suggestions for the create command flags. var createFlags = []prompt.Suggest{ + {Text: "--interactive", Description: "Create issue interactively"}, {Text: "--desc", Description: "Issue description"}, {Text: "--status", Description: "Issue status (open, closed, in_progress)"}, {Text: "--type", Description: "Issue type (bug, feature, task)"}, @@ -56,6 +57,11 @@ var listFlags = []prompt.Suggest{ {Text: "--limit", Description: "Limit number of results"}, } +var deleteFlags = []prompt.Suggest{ + {Text: "--yes", Description: "Confirm deletion without prompt"}, + {Text: "--interactive", Description: "Select issues to delete interactively"}, +} + // statusValues is a list of prompt suggestions for status types var statusValues = []prompt.Suggest{ {Text: "open", Description: "Open status"}, @@ -101,6 +107,10 @@ var commandFlags = map[string][]prompt.Suggest{ "list": listFlags, "ls": listFlags, "search": listFlags, + "delete": deleteFlags, + "del": deleteFlags, + "rm": deleteFlags, + "remove": deleteFlags, } // commandSuggestions returns a list of prompt suggestions based on the current input words.