Implement the construction of Kopia CLI REPOSITORY commands using the safecli package. #2646
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change Overview
This PR introduces several components for building Kopia CLI commands more effectively and safely within the Kanister project. The changes are made across various files, exclusively within the
pkg/kopia/cli
package. Below is the summary of the changes:pkg/kopia/cli/internal/flag/*
Defines an
Applier
interface for applying commands and/or flags tosafecli.CommandAppender
.This interface has a single method
Apply(cli safecli.CommandAppender) error
, which serves as a contract for implementing classes to append commands/flags tosafecli.CommandAppender
.It also provides utility functions and types to work with flags more efficiently.
It includes methods to create a collection of flags, handle errors within flags, and apply multiple flags to a CLI command safely.
pkg/kopia/cli/internal/flag/string_flag.go & bool_flag.go
stringFlag and boolFlag structs
These structures implement the
Applier
interface and provide mechanisms to append flags to a command only if certain conditions (like non-empty values for string flags) are met.stringFlag
includes functionalities for handling redacted output, for hiding sensitive information in logs.Both
stringFlag
andboolFlag
provide public methods to create new flags conveniently.pkg/kopia/cli/internal/flag/storage/{azure, fs, gcs, s3}
These packages offer flags specific to various storage backends.
pkg/kopia/cli/repository/*
This package utilizes the new structures and interfaces to implement the Kopia repository-related CLI commands in a more structured and safe manner.
pkg/kopia/cli/internal/test/*
This package implements test suites and utilities to validate the behavior of the new structures and interfaces.
pkg/kopia/cli/errors.go
Adds error messages for different failure scenarios related to flags.
Pull request type
Please check the type of change your PR introduces:
Test Plan