mirror of
https://github.com/paymog/slack-cli.git
synced 2026-09-18 23:43:49 +08:00
ed6ea666d0
CLI list/table commands (channels, messages, users, saved items, user groups) now print a JSON array of objects instead of CSV, so agents can pipe straight to jq. Conversion lives in the CLI output layer (internal/output): tabular commands call emitTable, which parses the handler's CSV into a JSON array (column order preserved, HTML escaping off so Slack <@U>/links/& stay legible). JSON-returning handlers are re-indented; plain-text status lines pass through. --raw still prints the original CSV/text verbatim. pkg/handler is untouched, so the bundled MCP server's output is unchanged and upstream merges stay clean. Values are strings (CSV carries no types); use jq's tonumber when you need numbers.
39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
package cmds
|
|
|
|
import (
|
|
"github.com/paymog/slack-cli/internal/config"
|
|
"github.com/paymog/slack-cli/internal/runtime"
|
|
"github.com/paymog/slack-cli/pkg/handler"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newUsersCommand(cfg *config.Config) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "users",
|
|
Aliases: []string{"user"},
|
|
Short: "Search workspace users",
|
|
}
|
|
cmd.AddCommand(usersSearchCommand(cfg))
|
|
return cmd
|
|
}
|
|
|
|
func usersSearchCommand(cfg *config.Config) *cobra.Command {
|
|
var limit int
|
|
cmd := &cobra.Command{
|
|
Use: "search <query>",
|
|
Short: "Search users by name, email, or display name, as JSON",
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
p, logger, err := runtime.PrepareRead(cmd.Context(), cfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
h := handler.NewConversationsHandler(p, logger)
|
|
a := map[string]any{"query": args[0], "limit": limit}
|
|
return emitTable(cmd, cfg, "users_search", h.UsersSearchHandler, a)
|
|
},
|
|
}
|
|
cmd.Flags().IntVar(&limit, "limit", 10, "max results (1-100)")
|
|
return cmd
|
|
}
|