Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Commit

Permalink
add flux reconcile subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
cr1cr1 committed Sep 28, 2023
1 parent a3d22a4 commit 34374b4
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions cmd/fluxReconcile.go
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

0 comments on commit 34374b4

Please sign in to comment.