Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Autocomplete file artifact name on download #910

Merged
merged 2 commits into from Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 38 additions & 1 deletion cli/cli/commands/files/download/download.go
Expand Up @@ -77,7 +77,7 @@ var FilesUploadCmd = &engine_consuming_kurtosis_command.EngineConsumingKurtosisC
IsOptional: isArtifactIdentifierArgOptional,
IsGreedy: isArtifactIdentifierArgGreedy,
DefaultValue: nil,
ArgCompletionProvider: nil,
ArgCompletionProvider: args.NewManualCompletionsProvider(getCompletions),
},
file_system_path_arg.NewDirpathArg(
destinationPathArgKey,
Expand Down Expand Up @@ -197,3 +197,40 @@ func validateArtifactIdentifier(ctx context.Context, flags *flags.ParsedFlags, a

return nil
}

func getCompletions(ctx context.Context, flags *flags.ParsedFlags, previousArgs *args.ParsedArgs) ([]string, error) {
kurtosisCtx, err := kurtosis_context.NewKurtosisContextFromLocalEngine()
if err != nil {
return nil, stacktrace.Propagate(
err,
"An error occurred connecting to the Kurtosis engine for retrieving the names for tab completion",
)
}

enclaveIdentifier, err := previousArgs.GetNonGreedyArg(enclaveIdentifierArgKey)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred getting the enclave ID using key '%v'", enclaveIdentifierArgKey)
}
enclave, err := kurtosisCtx.GetEnclaveContext(ctx, enclaveIdentifier)
if err != nil {
return nil, stacktrace.Propagate(
err,
"An error occurred getting the enclave identifiers",
)
}

fileArtifacts, err := enclave.GetAllFilesArtifactNamesAndUuids(ctx)
victorcolombo marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, stacktrace.Propagate(
err,
"An error occurred getting the file artifacts",
)
}
fileArtifactNames := []string{}
for _, fileArtifact := range fileArtifacts {
fileName := fileArtifact.GetFileName()
fileArtifactNames = append(fileArtifactNames, fileName)
}

return fileArtifactNames, nil
}