homelab/services/parts-inventory/cli/cmd/get.go
Dan V deb6c38d7b chore: commit homelab setup — deployment, services, orchestration, skill
- 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>
2026-04-09 08:10:32 +02:00

62 lines
1.5 KiB
Go

package cmd
import (
"fmt"
"strings"
"github.com/spf13/cobra"
)
var getCmd = &cobra.Command{
Use: "get <id>",
Short: "Get a part by ID",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
part, err := GetClient().GetPart(args[0])
if err != nil {
return fmt.Errorf("failed to get part: %w", err)
}
fmt.Printf("ID: %s\n", part.ID)
fmt.Printf("Title: %s\n", part.Title)
fmt.Printf("Type: %s\n", part.Type)
fmt.Printf("Category: %s\n", part.Category)
fmt.Printf("Manufacturer: %s\n", part.Manufacturer)
fmt.Printf("Quantity: %d\n", part.Quantity)
fmt.Printf("Location: %s\n", part.Location)
fmt.Printf("Notes: %s\n", part.Notes)
fmt.Printf("Tags: %s\n", strings.Join(part.Tags, ", "))
if part.Dimensions != nil {
d := part.Dimensions
fmt.Println("Dimensions:")
if d.Width != nil {
fmt.Printf(" Width: %.2f\n", *d.Width)
}
if d.Length != nil {
fmt.Printf(" Length: %.2f\n", *d.Length)
}
if d.Height != nil {
fmt.Printf(" Height: %.2f\n", *d.Height)
}
if d.Unit != "" {
fmt.Printf(" Unit: %s\n", d.Unit)
}
}
if len(part.Properties) > 0 {
fmt.Println("Properties:")
for k, v := range part.Properties {
fmt.Printf(" %s: %v\n", k, v)
}
}
fmt.Printf("Created: %s\n", part.CreatedAt.Format("2006-01-02 15:04:05"))
fmt.Printf("Updated: %s\n", part.UpdatedAt.Format("2006-01-02 15:04:05"))
return nil
},
}
func init() {
rootCmd.AddCommand(getCmd)
}