- 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>
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/olekukonko/tablewriter"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var listCmd = &cobra.Command{
|
|
Use: "list",
|
|
Short: "List or search parts",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
query, _ := cmd.Flags().GetString("query")
|
|
partType, _ := cmd.Flags().GetString("type")
|
|
category, _ := cmd.Flags().GetString("category")
|
|
|
|
result, err := GetClient().ListParts(query, partType, category)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to list parts: %w", err)
|
|
}
|
|
|
|
if len(result.Parts) == 0 {
|
|
fmt.Println("No parts found.")
|
|
return nil
|
|
}
|
|
|
|
table := tablewriter.NewWriter(os.Stdout)
|
|
table.SetHeader([]string{"ID", "Title", "Type", "Category", "Qty", "Location"})
|
|
table.SetBorder(false)
|
|
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
|
|
table.SetAlignment(tablewriter.ALIGN_LEFT)
|
|
|
|
for _, p := range result.Parts {
|
|
id := p.ID
|
|
if len(id) > 8 {
|
|
id = id[:8]
|
|
}
|
|
table.Append([]string{
|
|
id,
|
|
p.Title,
|
|
p.Type,
|
|
p.Category,
|
|
fmt.Sprintf("%d", p.Quantity),
|
|
p.Location,
|
|
})
|
|
}
|
|
|
|
table.Render()
|
|
fmt.Printf("Total: %d\n", result.Total)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
listCmd.Flags().StringP("query", "q", "", "Fuzzy search query")
|
|
listCmd.Flags().StringP("type", "t", "", "Filter by type")
|
|
listCmd.Flags().StringP("category", "c", "", "Filter by category")
|
|
rootCmd.AddCommand(listCmd)
|
|
}
|