|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + |
| 7 | + "github.com/spf13/cobra" |
| 8 | + |
| 9 | + "github.com/nextlevelbuilder/goclaw/internal/channels/teams/appmanifest" |
| 10 | + "github.com/nextlevelbuilder/goclaw/internal/config" |
| 11 | +) |
| 12 | + |
| 13 | +func teamsCmd() *cobra.Command { |
| 14 | + cmd := &cobra.Command{ |
| 15 | + Use: "teams", |
| 16 | + Short: "Microsoft Teams channel management", |
| 17 | + } |
| 18 | + cmd.AddCommand(teamsAppPackageCmd()) |
| 19 | + return cmd |
| 20 | +} |
| 21 | + |
| 22 | +func teamsAppPackageCmd() *cobra.Command { |
| 23 | + var ( |
| 24 | + name string |
| 25 | + fullName string |
| 26 | + description string |
| 27 | + developer string |
| 28 | + botID string |
| 29 | + iconColor string |
| 30 | + iconOutline string |
| 31 | + output string |
| 32 | + toStdout bool |
| 33 | + ) |
| 34 | + |
| 35 | + cmd := &cobra.Command{ |
| 36 | + Use: "app-package", |
| 37 | + Short: "Generate a Teams app package ZIP for sideloading", |
| 38 | + Long: "Generates a Teams-compatible app package (manifest.json + icons) for sideloading into Microsoft Teams.", |
| 39 | + RunE: func(cmd *cobra.Command, args []string) error { |
| 40 | + if output == "" && !toStdout { |
| 41 | + return fmt.Errorf("specify --output <file> or --stdout") |
| 42 | + } |
| 43 | + if output != "" && toStdout { |
| 44 | + return fmt.Errorf("--output and --stdout are mutually exclusive") |
| 45 | + } |
| 46 | + |
| 47 | + cfg, err := config.Load(resolveConfigPath()) |
| 48 | + if err != nil { |
| 49 | + return fmt.Errorf("loading config: %w", err) |
| 50 | + } |
| 51 | + if botID == "" { |
| 52 | + botID = cfg.Channels.Teams.BotID |
| 53 | + } |
| 54 | + |
| 55 | + opts := appmanifest.Options{ |
| 56 | + BotID: botID, |
| 57 | + Name: name, |
| 58 | + FullName: fullName, |
| 59 | + Description: description, |
| 60 | + Developer: developer, |
| 61 | + } |
| 62 | + |
| 63 | + if iconColor != "" { |
| 64 | + data, err := os.ReadFile(iconColor) |
| 65 | + if err != nil { |
| 66 | + return fmt.Errorf("reading color icon: %w", err) |
| 67 | + } |
| 68 | + opts.ColorIcon = data |
| 69 | + } |
| 70 | + if iconOutline != "" { |
| 71 | + data, err := os.ReadFile(iconOutline) |
| 72 | + if err != nil { |
| 73 | + return fmt.Errorf("reading outline icon: %w", err) |
| 74 | + } |
| 75 | + opts.OutlineIcon = data |
| 76 | + } |
| 77 | + |
| 78 | + zipData, err := appmanifest.GenerateZIP(opts) |
| 79 | + if err != nil { |
| 80 | + return err |
| 81 | + } |
| 82 | + |
| 83 | + if toStdout { |
| 84 | + _, err = os.Stdout.Write(zipData) |
| 85 | + return err |
| 86 | + } |
| 87 | + |
| 88 | + if err := os.WriteFile(output, zipData, 0644); err != nil { |
| 89 | + return fmt.Errorf("writing %s: %w", output, err) |
| 90 | + } |
| 91 | + fmt.Fprintf(os.Stderr, "Teams app package written to %s (%d bytes)\n", output, len(zipData)) |
| 92 | + return nil |
| 93 | + }, |
| 94 | + } |
| 95 | + |
| 96 | + cmd.Flags().StringVar(&name, "name", "", "bot display name (required, max 30 chars)") |
| 97 | + cmd.Flags().StringVar(&fullName, "full-name", "", "full bot name (default: same as --name)") |
| 98 | + cmd.Flags().StringVar(&description, "description", "", "short description (max 80 chars)") |
| 99 | + cmd.Flags().StringVar(&developer, "developer", "", "developer name (default: GoClaw)") |
| 100 | + cmd.Flags().StringVar(&botID, "bot-id", "", "override bot ID from config") |
| 101 | + cmd.Flags().StringVar(&iconColor, "icon-color", "", "path to custom 192x192 color icon (PNG)") |
| 102 | + cmd.Flags().StringVar(&iconOutline, "icon-outline", "", "path to custom 32x32 outline icon (PNG)") |
| 103 | + cmd.Flags().StringVarP(&output, "output", "o", "", "output file path") |
| 104 | + cmd.Flags().BoolVar(&toStdout, "stdout", false, "write ZIP to stdout (for piping/Docker)") |
| 105 | + _ = cmd.MarkFlagRequired("name") |
| 106 | + |
| 107 | + return cmd |
| 108 | +} |
0 commit comments