chore(commands): more commands for suggestions (#10)

## What's new
- color completion message command green
https://github.com/versenilvis/IRIS/pull/10/commits/6e141f5e6909fad1ec42725cce38d51729acf399
- new flat command folder structure
https://github.com/versenilvis/IRIS/pull/10/commits/87026a854a529ec5d5baed967d5f7a7f0085a24b
- fix some linter problems
https://github.com/versenilvis/IRIS/pull/10/commits/536de790cefda912f50bf4022e40ce2b965db2e2
- fix some gemini fix suggestions
This commit is contained in:
VERSE
2026-06-23 10:27:26 +07:00
committed by GitHub
parent 3d76a3ee88
commit a2972f61f1
42 changed files with 2406 additions and 245 deletions
+81
View File
@@ -0,0 +1,81 @@
package python
import (
"context"
"os/exec"
"strings"
"time"
"github.com/versenilvis/iris/commands/core"
)
func pipPackageGenerator(tokens []string, _ string, _ string) []core.Suggestion {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, "pip", "list", "--format=freeze")
out, err := cmd.Output()
if err != nil {
// try pip3
cmd = exec.CommandContext(ctx, "pip3", "list", "--format=freeze")
out, err = cmd.Output()
if err != nil {
return nil
}
}
var results []core.Suggestion
for _, line := range strings.Split(string(out), "\n") {
line = strings.TrimSpace(line)
if line == "" {
continue
}
// format is "package==version"
parts := strings.SplitN(line, "==", 2)
name := parts[0]
desc := ""
if len(parts) == 2 {
desc = "v" + parts[1]
}
results = append(results, core.Suggestion{Cmd: name, Desc: desc})
}
return results
}
func makePipSpec(name string) *core.Spec {
return &core.Spec{
Name: name,
Description: "python packages",
Subcommands: []core.Subcommand{
{Name: "install", Description: "install package", Options: []core.Option{
{Name: "-r", Description: "from requirements file"},
{Name: "-U", Description: "upgrade"},
{Name: "--user", Description: "install for user only"},
{Name: "--editable", Description: "editable install"},
{Name: "--index-url", Description: "custom package index"},
{Name: "--no-deps", Description: "skip dependencies"},
}},
{Name: "uninstall", Description: "remove package", Generator: pipPackageGenerator, Options: []core.Option{
{Name: "-y", Description: "yes to all prompts"},
}},
{Name: "freeze", Description: "list installed packages"},
{Name: "list", Description: "list installed", Options: []core.Option{
{Name: "--outdated", Description: "show outdated"},
{Name: "--format", Description: "output format"},
}},
{Name: "show", Description: "show package info", Generator: pipPackageGenerator},
{Name: "download", Description: "download packages"},
{Name: "check", Description: "verify compatibility"},
{Name: "config", Description: "manage config"},
{Name: "search", Description: "search pypi"},
{Name: "wheel", Description: "build wheel archive"},
{Name: "hash", Description: "compute hashes"},
{Name: "completion", Description: "generate completion"},
},
}
}
func init() {
core.Register(makePipSpec("pip"))
core.Register(makePipSpec("pip3"))
}