| 1 | package cli |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "strings" |
| 6 | |
| 7 | "reasonix/internal/config" |
| 8 | "reasonix/internal/pluginpkg" |
| 9 | ) |
| 10 | |
| 11 | func pluginArgNames() []string { |
| 12 | names, err := pluginpkg.InstalledNames(config.ReasonixHomeDir()) |
| 13 | if err != nil { |
| 14 | return nil |
| 15 | } |
| 16 | return names |
| 17 | } |
| 18 | |
| 19 | func (m *chatTUI) runPluginSubcommand(input string) { |
| 20 | args := tokenizeArgs(input) |
| 21 | sub := "" |
| 22 | if len(args) > 1 { |
| 23 | sub = strings.ToLower(args[1]) |
| 24 | } |
| 25 | switch sub { |
| 26 | case "", "list", "ls": |
| 27 | text, err := pluginpkg.InstalledListText(config.ReasonixHomeDir()) |
| 28 | if err != nil { |
| 29 | m.notice("plugins: " + err.Error()) |
| 30 | return |
| 31 | } |
| 32 | m.commitLine(text) |
| 33 | case "show", "cat": |
| 34 | if len(args) < 3 { |
| 35 | m.notice("usage: /plugins show <name>") |
| 36 | return |
| 37 | } |
| 38 | text, err := pluginpkg.InstalledShowText(config.ReasonixHomeDir(), args[2]) |
| 39 | if err != nil { |
| 40 | m.notice("plugins: " + err.Error()) |
| 41 | return |
| 42 | } |
| 43 | m.commitLine(text) |
| 44 | default: |
| 45 | m.notice(fmt.Sprintf("unknown /plugins subcommand %s - try: /plugins or /plugins show <name>", args[1])) |
| 46 | } |
| 47 | } |
| 48 |