diff --git a/cli/cli/command_framework/highlevel/service_identifier_arg/service_identifier_arg.go b/cli/cli/command_framework/highlevel/service_identifier_arg/service_identifier_arg.go index bf9a6f44f2..85764352f2 100644 --- a/cli/cli/command_framework/highlevel/service_identifier_arg/service_identifier_arg.go +++ b/cli/cli/command_framework/highlevel/service_identifier_arg/service_identifier_arg.go @@ -13,25 +13,25 @@ import ( ) const ( - enclaveIdentifierArgKey = "enclave" validShortenedUuidOrNameMatches = 1 uuidDelimiter = ", " ) func NewServiceIdentifierArg( - argKey string, + serviceIdentifierArgKey string, + enclaveIdentifierArgKey string, isOptional bool, isGreedy bool, ) *args.ArgConfig { - validate := getValidationFunc(argKey, isGreedy) + validate := getValidationFunc(serviceIdentifierArgKey, isGreedy, enclaveIdentifierArgKey) return &args.ArgConfig{ - Key: argKey, + Key: serviceIdentifierArgKey, IsOptional: isOptional, DefaultValue: "", IsGreedy: isGreedy, - ArgCompletionProvider: args.NewManualCompletionsProvider(getCompletionsOfActiveServices), + ArgCompletionProvider: args.NewManualCompletionsProvider(getCompletionsOfActiveServices(enclaveIdentifierArgKey)), ValidationFunc: validate, } } @@ -39,7 +39,8 @@ func NewServiceIdentifierArg( // TODO we added this constructor for allowing 'service logs' command to disable the validation for consuming logs from removed or stopped enclaves // TODO after https://github.com/kurtosis-tech/kurtosis/issues/879 is done func NewHistoricalServiceIdentifierArgWithValidationDisabled( - argKey string, + serviceIdentifierArgKey string, + enclaveIdentifierArgKey string, isOptional bool, isGreedy bool, ) *args.ArgConfig { @@ -47,11 +48,11 @@ func NewHistoricalServiceIdentifierArgWithValidationDisabled( var noValidationFunc func(ctx context.Context, flags *flags.ParsedFlags, args *args.ParsedArgs) error return &args.ArgConfig{ - Key: argKey, + Key: serviceIdentifierArgKey, IsOptional: isOptional, DefaultValue: "", IsGreedy: isGreedy, - ArgCompletionProvider: args.NewManualCompletionsProvider(getCompletionsForExistingAndHistoricalServices), + ArgCompletionProvider: args.NewManualCompletionsProvider(getCompletionsForExistingAndHistoricalServices(enclaveIdentifierArgKey)), ValidationFunc: noValidationFunc, } } @@ -88,75 +89,82 @@ func getServiceUuidsAndNamesForEnclave(ctx context.Context, enclaveIdentifier st return serviceUuids, serviceNamesToUuid, nil } -func getCompletionsForExistingAndHistoricalServices(ctx context.Context, _ *flags.ParsedFlags, previousArgs *args.ParsedArgs) ([]string, error) { - enclaveIdentifier, err := previousArgs.GetNonGreedyArg(enclaveIdentifierArgKey) - if err != nil { - return nil, stacktrace.Propagate(err, "An error occurred getting the enclave identifier using key '%v'", enclaveIdentifierArgKey) - } +func getCompletionsForExistingAndHistoricalServices(enclaveIdentifierArgKey string) func(ctx context.Context, _ *flags.ParsedFlags, previousArgs *args.ParsedArgs) ([]string, error) { + return func(ctx context.Context, _ *flags.ParsedFlags, previousArgs *args.ParsedArgs) ([]string, error) { + enclaveIdentifier, err := previousArgs.GetNonGreedyArg(enclaveIdentifierArgKey) + if err != nil { + return nil, stacktrace.Propagate(err, "An error occurred getting the enclave identifier using key '%v'", enclaveIdentifierArgKey) + } - kurtosisCtx, err := kurtosis_context.NewKurtosisContextFromLocalEngine() - if err != nil { - return nil, stacktrace.Propagate( - err, - "An error occurred connecting to the Kurtosis engine for retrieving the service UUIDs & names for tab completion", - ) - } + kurtosisCtx, err := kurtosis_context.NewKurtosisContextFromLocalEngine() + if err != nil { + return nil, stacktrace.Propagate( + err, + "An error occurred connecting to the Kurtosis engine for retrieving the service UUIDs & names for tab completion", + ) + } - enclaveContext, err := kurtosisCtx.GetEnclaveContext(ctx, enclaveIdentifier) - if err != nil { - return nil, stacktrace.Propagate(err, "An error occurred while fetching enclave for identifier '%v'", enclaveIdentifier) - } + enclaveContext, err := kurtosisCtx.GetEnclaveContext(ctx, enclaveIdentifier) + if err != nil { + return nil, stacktrace.Propagate(err, "An error occurred while fetching enclave for identifier '%v'", enclaveIdentifier) + } - serviceIdentifiers, err := enclaveContext.GetExistingAndHistoricalServiceIdentifiers(ctx) - if err != nil { - return nil, stacktrace.Propagate(err, "An error occurred while fetching services for enclave '%v'", enclaveContext.GetEnclaveName()) - } + serviceIdentifiers, err := enclaveContext.GetExistingAndHistoricalServiceIdentifiers(ctx) + if err != nil { + return nil, stacktrace.Propagate(err, "An error occurred while fetching services for enclave '%v'", enclaveContext.GetEnclaveName()) + } - return serviceIdentifiers.GetOrderedListOfNames(), nil + return serviceIdentifiers.GetOrderedListOfNames(), nil + } } -func getCompletionsOfActiveServices(ctx context.Context, flags *flags.ParsedFlags, previousArgs *args.ParsedArgs) ([]string, error) { - enclaveIdentifier, err := previousArgs.GetNonGreedyArg(enclaveIdentifierArgKey) - if err != nil { - return nil, stacktrace.Propagate(err, "An error occurred getting the enclave identifier using key '%v'", enclaveIdentifierArgKey) - } +func getCompletionsOfActiveServices(enclaveIdentifierArgKey string) func(ctx context.Context, flags *flags.ParsedFlags, previousArgs *args.ParsedArgs) ([]string, error) { + return func(ctx context.Context, _ *flags.ParsedFlags, previousArgs *args.ParsedArgs) ([]string, error) { + enclaveIdentifier, err := previousArgs.GetNonGreedyArg(enclaveIdentifierArgKey) + if err != nil { + return nil, stacktrace.Propagate(err, "An error occurred getting the enclave identifier using key '%v'", enclaveIdentifierArgKey) + } - _, serviceNames, err := getServiceUuidsAndNamesForEnclave(ctx, enclaveIdentifier) - if err != nil { - return nil, stacktrace.Propagate(err, "An error occurred getting the services retrieving for enclave identifier tab completion") - } + _, serviceNames, err := getServiceUuidsAndNamesForEnclave(ctx, enclaveIdentifier) + if err != nil { + return nil, stacktrace.Propagate(err, "An error occurred getting the services retrieving for enclave identifier tab completion") + } - serviceNamesList := []string{} - for serviceName := range serviceNames { - serviceNamesList = append(serviceNamesList, string(serviceName)) - } - sort.Strings(serviceNamesList) + serviceNamesList := []string{} + for serviceName := range serviceNames { + serviceNamesList = append(serviceNamesList, string(serviceName)) + } + sort.Strings(serviceNamesList) - return serviceNamesList, nil + return serviceNamesList, nil + } } -func getServiceIdentifiersForValidation(ctx context.Context, _ *flags.ParsedFlags, previousArgs *args.ParsedArgs) (map[services.ServiceUUID]bool, map[services.ServiceName]services.ServiceUUID, map[string][]services.ServiceUUID, error) { - enclaveIdentifier, err := previousArgs.GetNonGreedyArg(enclaveIdentifierArgKey) - if err != nil { - return nil, nil, nil, stacktrace.Propagate(err, "An error occurred getting the enclave identifier using key '%v'", enclaveIdentifierArgKey) - } +func getServiceIdentifiersForValidation(enclaveIdentifierArgKey string) func(ctx context.Context, _ *flags.ParsedFlags, previousArgs *args.ParsedArgs) (map[services.ServiceUUID]bool, map[services.ServiceName]services.ServiceUUID, map[string][]services.ServiceUUID, error) { + return func(ctx context.Context, _ *flags.ParsedFlags, previousArgs *args.ParsedArgs) (map[services.ServiceUUID]bool, map[services.ServiceName]services.ServiceUUID, map[string][]services.ServiceUUID, error) { + enclaveIdentifier, err := previousArgs.GetNonGreedyArg(enclaveIdentifierArgKey) + if err != nil { + return nil, nil, nil, stacktrace.Propagate(err, "An error occurred getting the enclave identifier using key '%v'", enclaveIdentifierArgKey) + } - serviceUuids, serviceNames, err := getServiceUuidsAndNamesForEnclave(ctx, enclaveIdentifier) - if err != nil { - return nil, nil, nil, stacktrace.Propagate(err, "An error occurred getting the services retrieving for enclave identifier tab completion") - } + serviceUuids, serviceNames, err := getServiceUuidsAndNamesForEnclave(ctx, enclaveIdentifier) + if err != nil { + return nil, nil, nil, stacktrace.Propagate(err, "An error occurred getting the services retrieving for enclave identifier tab completion") + } - shortenedUuidsToUuids := make(map[string][]services.ServiceUUID) - for serviceUuid := range serviceUuids { - shortenedUuid := uuid_generator.ShortenedUUIDString(string(serviceUuid)) - shortenedUuidsToUuids[shortenedUuid] = append(shortenedUuidsToUuids[shortenedUuid], serviceUuid) + shortenedUuidsToUuids := make(map[string][]services.ServiceUUID) + for serviceUuid := range serviceUuids { + shortenedUuid := uuid_generator.ShortenedUUIDString(string(serviceUuid)) + shortenedUuidsToUuids[shortenedUuid] = append(shortenedUuidsToUuids[shortenedUuid], serviceUuid) + } + return serviceUuids, serviceNames, shortenedUuidsToUuids, nil } - return serviceUuids, serviceNames, shortenedUuidsToUuids, nil } func getValidationFunc( argKey string, isGreedy bool, + enclaveIdentifierArgKey string, ) func(context.Context, *flags.ParsedFlags, *args.ParsedArgs) error { return func(ctx context.Context, flags *flags.ParsedFlags, args *args.ParsedArgs) error { var serviceIdentifiersToValidate []string @@ -174,7 +182,7 @@ func getValidationFunc( serviceIdentifiersToValidate = []string{serviceUuid} } - serviceUuids, serviceNames, shortenedUuidsToUuids, err := getServiceIdentifiersForValidation(ctx, flags, args) + serviceUuids, serviceNames, shortenedUuidsToUuids, err := getServiceIdentifiersForValidation(enclaveIdentifierArgKey)(ctx, flags, args) if err != nil { return stacktrace.Propagate(err, "An error occurred while getting the services for the enclave") } diff --git a/cli/cli/commands/files/storeservice/storeservice.go b/cli/cli/commands/files/storeservice/storeservice.go index 70ec666105..9db35b040f 100644 --- a/cli/cli/commands/files/storeservice/storeservice.go +++ b/cli/cli/commands/files/storeservice/storeservice.go @@ -89,6 +89,7 @@ var FilesStoreServiceCmd = &engine_consuming_kurtosis_command.EngineConsumingKur ), service_identifier_arg.NewServiceIdentifierArg( serviceIdentifierArgKey, + enclaveIdentifierArgKey, isServiceIdentifierArgOptional, isServiceIdentifierArgGreedy, ), diff --git a/cli/cli/commands/port/print/print.go b/cli/cli/commands/port/print/print.go index 11b46514d0..2ccf6e656c 100644 --- a/cli/cli/commands/port/print/print.go +++ b/cli/cli/commands/port/print/print.go @@ -53,6 +53,7 @@ var PortPrintCmd = &engine_consuming_kurtosis_command.EngineConsumingKurtosisCom // TODO we should fix this after https://github.com/kurtosis-tech/kurtosis/issues/879 service_identifier_arg.NewHistoricalServiceIdentifierArgWithValidationDisabled( serviceIdentifierArgKey, + enclaveIdentifierArgKey, isServiceIdentifierArgOptional, isServiceIdentifierArgGreedy, ), diff --git a/cli/cli/commands/service/exec/exec.go b/cli/cli/commands/service/exec/exec.go index c48db7ef93..f6af8e0f8e 100644 --- a/cli/cli/commands/service/exec/exec.go +++ b/cli/cli/commands/service/exec/exec.go @@ -55,6 +55,7 @@ var ServiceShellCmd = &engine_consuming_kurtosis_command.EngineConsumingKurtosis ), service_identifier_arg.NewServiceIdentifierArg( serviceIdentifierArgKey, + enclaveIdentifierArgKey, isServiceGuidArgOptional, isServiceGuidArgGreedy, ), diff --git a/cli/cli/commands/service/logs/logs.go b/cli/cli/commands/service/logs/logs.go index c3ce450eb5..afeeff87fb 100644 --- a/cli/cli/commands/service/logs/logs.go +++ b/cli/cli/commands/service/logs/logs.go @@ -113,6 +113,7 @@ var ServiceLogsCmd = &engine_consuming_kurtosis_command.EngineConsumingKurtosisC ), service_identifier_arg.NewServiceIdentifierArg( serviceIdentifierArgKey, + enclaveIdentifierArgKey, isServiceIdentifierArgGreedy, isServiceIdentifierArgOptional, ), diff --git a/cli/cli/commands/service/rm/rm.go b/cli/cli/commands/service/rm/rm.go index 56732d2257..31438d1c84 100644 --- a/cli/cli/commands/service/rm/rm.go +++ b/cli/cli/commands/service/rm/rm.go @@ -60,6 +60,7 @@ var ServiceRmCmd = &engine_consuming_kurtosis_command.EngineConsumingKurtosisCom ), service_identifier_arg.NewServiceIdentifierArg( serviceIdentifierArgKey, + enclaveIdentifierArgKey, isServiceIdentifierArgGreedy, isServiceIdentifierArgOptional, ), diff --git a/cli/cli/commands/service/shell/shell.go b/cli/cli/commands/service/shell/shell.go index 133a3fe6b6..688066f4cf 100644 --- a/cli/cli/commands/service/shell/shell.go +++ b/cli/cli/commands/service/shell/shell.go @@ -51,6 +51,7 @@ var ServiceShellCmd = &engine_consuming_kurtosis_command.EngineConsumingKurtosis ), service_identifier_arg.NewServiceIdentifierArg( serviceIdentifierArgKey, + enclaveIdentifierArgKey, isServiceGuidArgOptional, isServiceGuidArgGreedy, ), diff --git a/cli/cli/commands/service/start/start.go b/cli/cli/commands/service/start/start.go index 0c47c66d9a..45d947db06 100644 --- a/cli/cli/commands/service/start/start.go +++ b/cli/cli/commands/service/start/start.go @@ -60,6 +60,7 @@ var ServiceStartCmd = &engine_consuming_kurtosis_command.EngineConsumingKurtosis ), service_identifier_arg.NewServiceIdentifierArg( serviceIdentifierArgKey, + enclaveIdentifierArgKey, isServiceIdentifierArgGreedy, isServiceIdentifierArgOptional, ), diff --git a/cli/cli/commands/service/stop/stop.go b/cli/cli/commands/service/stop/stop.go index 5af557a6c2..df2c453e98 100644 --- a/cli/cli/commands/service/stop/stop.go +++ b/cli/cli/commands/service/stop/stop.go @@ -60,6 +60,7 @@ var ServiceStopCmd = &engine_consuming_kurtosis_command.EngineConsumingKurtosisC ), service_identifier_arg.NewServiceIdentifierArg( serviceIdentifierArgKey, + enclaveIdentifierArgKey, isServiceIdentifierArgGreedy, isServiceIdentifierArgOptional, ),