This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
1 changed file
with
81 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,81 @@ | ||
/* | ||
Copyright © 2023 Dataflows | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"github.com/thedataflows/go-commons/pkg/config" | ||
) | ||
|
||
type FluxReconcile struct { | ||
cmd *cobra.Command | ||
parent *Flux | ||
} | ||
|
||
// fluxReconcileCmd represents the fluxReconcile command | ||
var ( | ||
fluxReconcileCmd = &cobra.Command{ | ||
Use: "reconcile", | ||
Short: "Reconcile FluxCD", | ||
Long: ``, | ||
Aliases: []string{"r"}, | ||
RunE: RunFluxReconcileCommand, | ||
} | ||
|
||
fluxReconcile = NewFluxReconcile(flux) | ||
) | ||
|
||
func init() { | ||
fluxCmd.AddCommand(fluxReconcileCmd) | ||
fluxReconcileCmd.SilenceErrors = fluxReconcileCmd.Parent().SilenceErrors | ||
fluxReconcileCmd.SilenceUsage = fluxReconcileCmd.Parent().SilenceUsage | ||
|
||
// Bind flags | ||
config.ViperBindPFlagSet(fluxReconcileCmd, nil) | ||
|
||
fluxReconcile.SetCmd(fluxReconcileCmd) | ||
} | ||
|
||
// RunFluxReconcileCommand runs flux bootstrap subcommand | ||
func RunFluxReconcileCommand(cmd *cobra.Command, args []string) error { | ||
if err := fluxReconcile.CheckRequiredFlags(); err != nil { | ||
return err | ||
} | ||
|
||
// Run the main command | ||
newArgs := []string{ | ||
cmd.Parent().Use, | ||
cmd.Use, | ||
fmt.Sprintf("--%s=%s", fluxReconcile.parent.KeyFluxContext(), fluxReconcile.parent.GetFluxContext()), | ||
} | ||
if len(args) > 0 { | ||
newArgs = append(newArgs, args...) | ||
} else { | ||
newArgs = append(newArgs, regexp.MustCompile(`\s+`).Split(viper.GetString(cmd.Parent().Use+"."+cmd.Use), -1)...) | ||
} | ||
if err := RunRawCommand(rawCmd, newArgs); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func NewFluxReconcile(parent *Flux) *FluxReconcile { | ||
return &FluxReconcile{ | ||
parent: parent, | ||
} | ||
} | ||
|
||
func (f *FluxReconcile) SetCmd(cmd *cobra.Command) { | ||
f.cmd = cmd | ||
} | ||
|
||
func (f *FluxReconcile) CheckRequiredFlags() error { | ||
return f.parent.CheckRequiredFlags() | ||
} | ||
|
||
// Flags keys, defaults and value getters |