This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5566591
commit e219724
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Inspired by https://samrapdev.com/capturing-sensitive-input-with-editor-in-golang-from-the-cli/ | ||
|
||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/caos/orbos/pkg/git" | ||
) | ||
|
||
func RemoveCommand(getRv GetRootValues) *cobra.Command { | ||
|
||
cmd := &cobra.Command{ | ||
Use: "remove <filepath>", | ||
Short: "Remove file from git repository", | ||
Long: "If the file doesn't exist, the command completes successfully", | ||
Args: cobra.MinimumNArgs(1), | ||
Example: `orbctl file remove caos-internal/orbiter/current.yml`, | ||
} | ||
|
||
cmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
|
||
filesStr := strings.Join(args, ",") | ||
|
||
rv, err := getRv("remove", "", map[string]interface{}{"files": filesStr}) | ||
if err != nil { | ||
return err | ||
} | ||
defer rv.ErrFunc(err) | ||
|
||
if !rv.Gitops { | ||
return errors.New("remove command is only supported with the --gitops flag") | ||
} | ||
|
||
if err := initRepo(rv.OrbConfig, rv.GitClient); err != nil { | ||
return err | ||
} | ||
|
||
files := make([]git.File, len(args)) | ||
for i := range args { | ||
files[i] = git.File{ | ||
Path: args[i], | ||
Content: nil, | ||
} | ||
} | ||
|
||
return rv.GitClient.UpdateRemote(fmt.Sprintf("Remove %s", filesStr), func() []git.File { return files }) | ||
} | ||
|
||
return cmd | ||
} |