-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathfleet_management_get.go
More file actions
54 lines (46 loc) · 1.84 KB
/
fleet_management_get.go
File metadata and controls
54 lines (46 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package fleetcontrol
import (
"fmt"
"github.com/spf13/cobra"
"github.com/newrelic/newrelic-cli/internal/client"
"github.com/newrelic/newrelic-client-go/v2/pkg/fleetcontrol"
)
// handleFleetGet implements the 'get' command to retrieve a fleet entity by ID.
//
// This command fetches detailed information about a specific fleet including its
// configuration, managed entity type, scope, tags, and metadata.
//
// The command:
// 1. Validates flag values (done automatically by framework via YAML rules)
// 2. Calls the New Relic API to retrieve the entity by ID using GetEntity
// 3. Validates that the entity exists and is a fleet
// 4. Filters and returns the fleet details
//
// Parameters:
// - cmd: The cobra command being executed
// - args: Command arguments (not used)
// - flags: Validated flag values from YAML configuration
//
// Returns:
// - Error if fleet retrieval fails, nil on success
func handleFleetGet(_ *cobra.Command, _ []string, flags *FlagValues) error {
// Get typed flag values
f := flags.Get()
// Use GetEntity to fetch the entity directly by ID
entityInterface, err := client.NRClient.FleetControl.GetEntity(f.FleetID)
if err != nil {
return PrintError(fmt.Errorf("failed to get fleet: %w", err))
}
if entityInterface == nil {
return PrintError(fmt.Errorf("fleet with ID '%s' not found", f.FleetID))
}
// Dereference the interface pointer and type assert to fleet entity
fleetEntity, ok := (*entityInterface).(*fleetcontrol.EntityManagementFleetEntity)
if !ok {
return PrintError(fmt.Errorf("entity '%s' is not a fleet (type: %T)", f.FleetID, *entityInterface))
}
// Convert to filtered output format with status wrapper
// Always show tags for get command since it's fetching a specific entity
filteredOutput := FilterFleetEntityFromEntityManagement(*fleetEntity, true)
return PrintFleetSuccess(filteredOutput)
}