Merge pull request #5 from LazyBachelor/LPM-44
LPM-44 Add Command REPL for auto-completeion and ux
This commit is contained in:
@@ -1,17 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"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"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
func main() {
|
||||
config := pkg.SurveyConfig{
|
||||
RootCmd: "pm",
|
||||
WebAddress: "localhost:8080",
|
||||
IssuePrefix: "pm",
|
||||
BeadsDBPath: "./.pm/db.db",
|
||||
@@ -25,7 +28,9 @@ func main() {
|
||||
case "tui":
|
||||
err = tui.Run(ctx, config)
|
||||
case "cli":
|
||||
err = cli.Run(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:
|
||||
|
||||
21
go.mod
21
go.mod
@@ -6,14 +6,21 @@ 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/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
|
||||
github.com/spf13/cobra v1.10.2
|
||||
github.com/steveyegge/beads v0.49.3
|
||||
golang.org/x/term v0.39.0
|
||||
)
|
||||
|
||||
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
|
||||
@@ -27,13 +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/huh v0.8.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
|
||||
@@ -54,17 +63,22 @@ 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/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
|
||||
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 +99,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
|
||||
|
||||
43
go.sum
43
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=
|
||||
@@ -33,6 +35,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=
|
||||
@@ -43,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=
|
||||
@@ -57,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=
|
||||
@@ -67,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=
|
||||
@@ -127,15 +139,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=
|
||||
@@ -144,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=
|
||||
@@ -158,6 +187,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 +254,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=
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,23 +1,45 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/cli/commands"
|
||||
"context"
|
||||
)
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
|
||||
defer cleanup()
|
||||
|
||||
if err := commands.Execute(svc); err != nil {
|
||||
commands.SetServices(svc)
|
||||
|
||||
if err := commands.Execute(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
defer cleanup()
|
||||
|
||||
commands.SetServices(svc)
|
||||
|
||||
if err := commands.ExecuteArgs(args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
42
pkg/cli/commands/completion.go
Normal file
42
pkg/cli/commands/completion.go
Normal file
@@ -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
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// Variables to hold flag values for the create command.
|
||||
var (
|
||||
createDescription string
|
||||
createStatus string
|
||||
@@ -16,36 +17,24 @@ 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`
|
||||
)
|
||||
|
||||
// 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",
|
||||
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),
|
||||
RunE: runCreateCmd,
|
||||
}
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
|
||||
// runCreateCmd executes the create command logic,
|
||||
func runCreateCmd(cmd *cobra.Command, args []string) error {
|
||||
createTitle := strings.Join(args, " ")
|
||||
|
||||
@@ -61,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 != "" {
|
||||
@@ -88,7 +79,29 @@ 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)")
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -1,66 +1,47 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"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]",
|
||||
Aliases: []string{"get", "read"},
|
||||
Short: "Get issue details",
|
||||
Long: `Get issue details by ID`,
|
||||
RunE: runGetCmd,
|
||||
Args: cobra.ExactArgs(1),
|
||||
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) {
|
||||
if svc == nil {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
issues, err := svc.Beads.AllIssues(cmd.Context())
|
||||
if err != nil {
|
||||
return nil, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
var completions []string
|
||||
for _, issue := range issues {
|
||||
|
||||
if strings.HasPrefix(issue.ID, toComplete) {
|
||||
completions = append(completions, issue.ID)
|
||||
} else if strings.HasPrefix(issue.Title, toComplete) {
|
||||
completions = append(completions, issue.ID)
|
||||
}
|
||||
}
|
||||
|
||||
return completions, cobra.ShellCompDirectiveNoFileComp
|
||||
}
|
||||
|
||||
@@ -1,28 +1,62 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/charmbracelet/fang"
|
||||
|
||||
"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 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
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
// 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")
|
||||
|
||||
31
pkg/cli/repl/completer.go
Normal file
31
pkg/cli/repl/completer.go
Normal file
@@ -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
|
||||
}
|
||||
48
pkg/cli/repl/executor.go
Normal file
48
pkg/cli/repl/executor.go
Normal file
@@ -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
|
||||
}
|
||||
27
pkg/cli/repl/options.go
Normal file
27
pkg/cli/repl/options.go
Normal file
@@ -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),
|
||||
}
|
||||
}
|
||||
59
pkg/cli/repl/repl.go
Normal file
59
pkg/cli/repl/repl.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package repl
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"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"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to initialize services: %w", err)
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
commands.SetServices(svc)
|
||||
|
||||
fmt.Println(styles.TitleStyle.Render(ReplTitle))
|
||||
|
||||
var history []string
|
||||
|
||||
for {
|
||||
input := prompt.Input(
|
||||
PromptPrefix,
|
||||
completer,
|
||||
promptOptions(history)...,
|
||||
)
|
||||
|
||||
input = strings.TrimSpace(input)
|
||||
|
||||
if input == "exit" || input == "quit" {
|
||||
fmt.Println("Goodbye!")
|
||||
break
|
||||
}
|
||||
|
||||
history = append(history, input)
|
||||
|
||||
// Ignore errors for now, gives better ux
|
||||
output, _ := execute(input)
|
||||
|
||||
fmt.Println(styles.CommandStyle.Render(output))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
155
pkg/cli/repl/suggestions.go
Normal file
155
pkg/cli/repl/suggestions.go
Normal file
@@ -0,0 +1,155 @@
|
||||
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" {
|
||||
// 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
|
||||
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(partial string, hasCommand bool) []prompt.Suggest {
|
||||
// Only show suggestions if we've typed the command already
|
||||
if !hasCommand {
|
||||
return nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
10
pkg/cli/styles/styles.go
Normal file
10
pkg/cli/styles/styles.go
Normal file
@@ -0,0 +1,10 @@
|
||||
// Package styles defines the styling for the CLI output using the lipgloss library.
|
||||
package styles
|
||||
|
||||
import "github.com/charmbracelet/lipgloss"
|
||||
|
||||
var (
|
||||
TitleStyle = lipgloss.NewStyle().Bold(true).Padding(1)
|
||||
|
||||
CommandStyle = lipgloss.NewStyle().Padding(1)
|
||||
)
|
||||
Reference in New Issue
Block a user