@@ -44,6 +44,7 @@ func Command() *cobra.Command {
44
44
lastSeenDuration time.Duration
45
45
exclude []string
46
46
confirm bool
47
+ ephemeral bool
47
48
)
48
49
49
50
cmd := & cobra.Command {
@@ -62,6 +63,9 @@ Examples:
62
63
# Show devices that would be deleted (default behavior)
63
64
tscli delete devices --last-seen 15m
64
65
66
+ # Delete only ephemeral devices not seen for 1 hour
67
+ tscli delete devices --last-seen 1h --ephemeral --confirm
68
+
65
69
# Delete devices not seen for 24 hours, excluding specific patterns
66
70
tscli delete devices --last-seen 24h --exclude server --exclude prod --confirm
67
71
@@ -74,7 +78,7 @@ Examples:
74
78
return fmt .Errorf ("failed to create client: %w" , err )
75
79
}
76
80
77
- summary , err := deleteDisconnectedDevices (cmd .Context (), client , lastSeenDuration , exclude , confirm )
81
+ summary , err := deleteDisconnectedDevices (cmd .Context (), client , lastSeenDuration , exclude , ephemeral , confirm )
78
82
if err != nil {
79
83
return fmt .Errorf ("failed to delete devices: %w" , err )
80
84
}
@@ -94,13 +98,15 @@ Examples:
94
98
"Duration to consider a device disconnected (e.g., 15m, 1h, 24h)" )
95
99
cmd .Flags ().StringSliceVar (& exclude , "exclude" , nil ,
96
100
"Device names to exclude by partial match (can be specified multiple times)" )
101
+ cmd .Flags ().BoolVar (& ephemeral , "ephemeral" , false ,
102
+ "Only delete ephemeral devices" )
97
103
cmd .Flags ().BoolVar (& confirm , "confirm" , false ,
98
104
"Actually delete devices (default is a dry run)" )
99
105
100
106
return cmd
101
107
}
102
108
103
- func deleteDisconnectedDevices (ctx context.Context , client * tsapi.Client , lastSeenTimeout time.Duration , excludedDevices []string , confirm bool ) (* DeletionSummary , error ) {
109
+ func deleteDisconnectedDevices (ctx context.Context , client * tsapi.Client , lastSeenTimeout time.Duration , excludedDevices []string , ephemeralOnly bool , confirm bool ) (* DeletionSummary , error ) {
104
110
// List all devices with full details to get ephemeral status
105
111
devices , err := client .Devices ().ListWithAllFields (ctx )
106
112
if err != nil {
@@ -119,6 +125,12 @@ func deleteDisconnectedDevices(ctx context.Context, client *tsapi.Client, lastSe
119
125
continue
120
126
}
121
127
128
+ // Check if we should only process ephemeral devices
129
+ if ephemeralOnly && ! device .IsEphemeral {
130
+ skippedDevices = append (skippedDevices , fmt .Sprintf ("%s (not ephemeral)" , device .Name ))
131
+ continue
132
+ }
133
+
122
134
// Calculate time since the device was last seen
123
135
timeSinceLastSeen := now .Sub (device .LastSeen .Time )
124
136
if timeSinceLastSeen > lastSeenTimeout {
0 commit comments