@@ -72,6 +72,7 @@ Examples:
7272
7373 # Get service details in YAML format
7474 tiger service get svc-12345 --output yaml` ,
75+ ValidArgsFunction : serviceIDCompletion ,
7576 RunE : func (cmd * cobra.Command , args []string ) error {
7677 // Get config
7778 cfg , err := config .Load ()
@@ -470,6 +471,7 @@ Examples:
470471
471472 # Update password without saving (using global flag)
472473 tiger service update-password svc-12345 --new-password new-secure-password --password-storage none` ,
474+ ValidArgsFunction : serviceIDCompletion ,
473475 RunE : func (cmd * cobra.Command , args []string ) error {
474476 // Get config
475477 cfg , err := config .Load ()
@@ -901,6 +903,7 @@ Examples:
901903
902904 # Delete service with custom wait timeout
903905 tiger service delete svc-12345 --wait-timeout 15m` ,
906+ ValidArgsFunction : serviceIDCompletion ,
904907 RunE : func (cmd * cobra.Command , args []string ) error {
905908 // Require explicit service ID for safety
906909 if len (args ) < 1 {
@@ -1092,7 +1095,8 @@ Examples:
10921095
10931096 # Fork with custom wait timeout
10941097 tiger service fork svc-12345 --now --wait-timeout 45m` ,
1095- Args : cobra .MaximumNArgs (1 ),
1098+ Args : cobra .MaximumNArgs (1 ),
1099+ ValidArgsFunction : serviceIDCompletion ,
10961100 RunE : func (cmd * cobra.Command , args []string ) error {
10971101 // Validate timing flags first - exactly one must be specified
10981102 timingFlagsSet := 0
@@ -1287,3 +1291,51 @@ Examples:
12871291
12881292 return cmd
12891293}
1294+ func serviceIDCompletion (cmd * cobra.Command , _ []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
1295+ services , err := listServices (cmd )
1296+ if err != nil {
1297+ return nil , cobra .ShellCompDirectiveError
1298+ }
1299+
1300+ results := make ([]string , 0 , len (services ))
1301+ for _ , service := range services {
1302+ if service .ServiceId != nil && strings .HasPrefix (* service .ServiceId , toComplete ) {
1303+ results = append (results , cobra .CompletionWithDesc (* service .ServiceId , * service .Name ))
1304+ }
1305+ }
1306+ return results , cobra .ShellCompDirectiveNoFileComp
1307+ }
1308+
1309+ func listServices (cmd * cobra.Command ) ([]api.Service , error ) {
1310+ // Get API key and project ID for authentication
1311+ apiKey , projectID , err := getCredentialsForService ()
1312+ if err != nil {
1313+ return nil , exitWithCode (ExitAuthenticationError , fmt .Errorf ("authentication required: %w. Please run 'tiger auth login'" , err ))
1314+ }
1315+
1316+ // Create API client
1317+ client , err := api .NewTigerClient (apiKey )
1318+ if err != nil {
1319+ return nil , fmt .Errorf ("failed to create API client: %w" , err )
1320+ }
1321+
1322+ // Make API call to list services
1323+ ctx , cancel := context .WithTimeout (cmd .Context (), 30 * time .Second )
1324+ defer cancel ()
1325+
1326+ resp , err := client .GetProjectsProjectIdServicesWithResponse (ctx , projectID )
1327+ if err != nil {
1328+ return nil , fmt .Errorf ("failed to list services: %w" , err )
1329+ }
1330+
1331+ // Handle API response
1332+ if resp .StatusCode () != 200 {
1333+ return nil , exitWithErrorFromStatusCode (resp .StatusCode (), resp .JSON4XX )
1334+ }
1335+
1336+ if resp .JSON200 == nil || len (* resp .JSON200 ) == 0 {
1337+ return []api.Service {}, nil
1338+ }
1339+
1340+ return * resp .JSON200 , nil
1341+ }
0 commit comments