package main import ( "fmt" "github.com/spf13/cobra" "skillmgr/internal/config" "skillmgr/internal/types" ) var listCmd = &cobra.Command{ Use: "list", Short: "列出已安装的 skills 和 commands", Long: `显示所有已安装的 skills 和 commands。 示例: skillmgr list skillmgr list --type skill skillmgr list --platform claude skillmgr list --global`, RunE: func(cmd *cobra.Command, args []string) error { itemTypeStr, _ := cmd.Flags().GetString("type") platformStr, _ := cmd.Flags().GetString("platform") global, _ := cmd.Flags().GetBool("global") cfg, err := config.LoadInstallConfig() if err != nil { return err } if len(cfg.Installations) == 0 { fmt.Println("无已安装的 skills/commands") return nil } // 过滤 var filtered []types.InstallRecord for _, r := range cfg.Installations { // 按类型过滤 if itemTypeStr != "" && string(r.Type) != itemTypeStr { continue } // 按平台过滤 if platformStr != "" && string(r.Platform) != platformStr { continue } // 按作用域过滤 if global && r.Scope != types.ScopeGlobal { continue } if !global && cmd.Flags().Changed("global") && r.Scope != types.ScopeProject { continue } filtered = append(filtered, r) } if len(filtered) == 0 { fmt.Println("无匹配的安装记录") return nil } fmt.Println("已安装:") for _, r := range filtered { fmt.Printf("\n [%s] %s\n", r.Type, r.Name) fmt.Printf(" 平台: %s\n", r.Platform) fmt.Printf(" 作用域: %s\n", r.Scope) fmt.Printf(" 来源: %s\n", r.SourceRepo) fmt.Printf(" 路径: %s\n", r.InstallPath) fmt.Printf(" 安装于: %s\n", r.InstalledAt.Format("2006-01-02 15:04:05")) if !r.UpdatedAt.Equal(r.InstalledAt) { fmt.Printf(" 更新于: %s\n", r.UpdatedAt.Format("2006-01-02 15:04:05")) } } return nil }, } func init() { listCmd.Flags().String("type", "", "过滤类型 (skill|command)") listCmd.Flags().String("platform", "", "过滤平台 (claude|opencode)") listCmd.Flags().BoolP("global", "g", false, "仅显示全局安装") rootCmd.AddCommand(listCmd) }