- Add .gitignore: exclude compiled binaries, build artifacts, and Helm values files containing real secrets (authentik, prometheus) - Add all Kubernetes deployment manifests (deployment/) - Add services source code: ha-sync, device-inventory, games-console, paperclip, parts-inventory - Add Ansible orchestration: playbooks, roles, inventory, cloud-init - Add hardware specs, execution plans, scripts, HOMELAB.md - Add skills/homelab/SKILL.md + skills/install.sh to preserve Copilot skill - Remove previously-tracked inventory-cli binary from git index Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var updateCmd = &cobra.Command{
|
|
Use: "update <id>",
|
|
Short: "Update an existing part",
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
id := args[0]
|
|
payload := map[string]interface{}{}
|
|
|
|
if cmd.Flags().Changed("title") {
|
|
v, _ := cmd.Flags().GetString("title")
|
|
payload["title"] = v
|
|
}
|
|
if cmd.Flags().Changed("type") {
|
|
v, _ := cmd.Flags().GetString("type")
|
|
payload["type"] = v
|
|
}
|
|
if cmd.Flags().Changed("category") {
|
|
v, _ := cmd.Flags().GetString("category")
|
|
payload["category"] = v
|
|
}
|
|
if cmd.Flags().Changed("manufacturer") {
|
|
v, _ := cmd.Flags().GetString("manufacturer")
|
|
payload["manufacturer"] = v
|
|
}
|
|
if cmd.Flags().Changed("quantity") {
|
|
v, _ := cmd.Flags().GetInt("quantity")
|
|
payload["quantity"] = v
|
|
}
|
|
if cmd.Flags().Changed("location") {
|
|
v, _ := cmd.Flags().GetString("location")
|
|
payload["location"] = v
|
|
}
|
|
if cmd.Flags().Changed("notes") {
|
|
v, _ := cmd.Flags().GetString("notes")
|
|
payload["notes"] = v
|
|
}
|
|
if cmd.Flags().Changed("tags") {
|
|
v, _ := cmd.Flags().GetString("tags")
|
|
payload["tags"] = strings.Split(v, ",")
|
|
}
|
|
|
|
properties := parseProperties(cmd)
|
|
if len(properties) > 0 {
|
|
payload["properties"] = properties
|
|
}
|
|
|
|
if len(payload) == 0 {
|
|
return fmt.Errorf("no fields provided to update")
|
|
}
|
|
|
|
part, err := GetClient().UpdatePart(id, payload)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to update part: %w", err)
|
|
}
|
|
|
|
fmt.Printf("Updated part: %s — %s\n", part.ID, part.Title)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
updateCmd.Flags().String("title", "", "Part title")
|
|
updateCmd.Flags().String("type", "", "Part type")
|
|
updateCmd.Flags().String("category", "", "Part category")
|
|
updateCmd.Flags().String("manufacturer", "", "Manufacturer")
|
|
updateCmd.Flags().Int("quantity", 0, "Quantity")
|
|
updateCmd.Flags().String("location", "", "Storage location")
|
|
updateCmd.Flags().String("notes", "", "Notes")
|
|
updateCmd.Flags().String("tags", "", "Comma-separated tags")
|
|
updateCmd.Flags().StringArray("property", []string{}, "Property in key=value format (repeatable)")
|
|
rootCmd.AddCommand(updateCmd)
|
|
}
|