Borg/cmd/push.go
google-labs-jules[bot] 3ac7b365ef feat: S3/cloud storage backend
This commit introduces a new cloud storage backend with support for S3 and S3-compatible services.

Key changes:
- Created a `storage` package with a `Storage` interface.
- Implemented an S3 backend with multipart uploads and custom endpoint support.
- Added `push`, `pull`, `ls`, and `remote add` commands.
- Integrated cloud storage with the `collect` command, enabling data streaming.
- Added unit and integration tests for the new functionality.

Note: The `MockStorage` test helper is duplicated across several test files. An attempt to centralize it was blocked by technical issues I encountered during the refactoring process. This refactoring is left for a future commit.

Co-authored-by: Snider <631881+Snider@users.noreply.github.com>
2026-02-02 00:46:35 +00:00

50 lines
972 B
Go

package cmd
import (
"fmt"
"net/url"
"os"
"github.com/Snider/Borg/pkg/storage"
"github.com/spf13/cobra"
)
func NewPushCmd() *cobra.Command {
return &cobra.Command{
Use: "push [local-path] [remote-url]",
Short: "Push a local file to a remote storage URL",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
localPath := args[0]
remoteURL := args[1]
u, err := url.Parse(remoteURL)
if err != nil {
return fmt.Errorf("invalid remote URL: %w", err)
}
s, err := storage.NewStorage(u)
if err != nil {
return err
}
f, err := os.Open(localPath)
if err != nil {
return fmt.Errorf("error opening local file: %w", err)
}
defer f.Close()
err = s.Write(u.Path, f)
if err != nil {
return fmt.Errorf("error uploading file: %w", err)
}
fmt.Fprintln(cmd.OutOrStdout(), "File pushed successfully")
return nil
},
}
}
func init() {
RootCmd.AddCommand(NewPushCmd())
}