53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"git.badhouseplants.net/allanger/shoebill/internal/controller"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
sync = &cobra.Command{
|
|
Use: "sync",
|
|
Short: "sync does something",
|
|
Long: ``,
|
|
Run: syncCmd,
|
|
}
|
|
)
|
|
|
|
func init() {
|
|
sync.Flags().StringP("config", "c", "config.yaml", "A path to the configuration file")
|
|
sync.Flags().String("workdir", "", "A path to the workdir. On the moment of running, it should be an empty dir")
|
|
sync.Flags().String("ssh-key", "", "A path to the pricate ssh key")
|
|
sync.Flags().Bool("dry-run", false, "If set to false, will not push changes to git")
|
|
sync.Flags().Bool("diff", false, "If set to false, will show helm diffs for not preserved charts")
|
|
sync.Flags().String("sops-bin", "/usr/bin/sops", "A path to the sops binary in your system")
|
|
|
|
rootCmd.AddCommand(sync)
|
|
}
|
|
|
|
func syncCmd(cmd *cobra.Command, args []string) {
|
|
config := cmd.Flag("config").Value.String()
|
|
workdir := cmd.Flag("workdir").Value.String()
|
|
sshKey := cmd.Flag("ssh-key").Value.String()
|
|
sopsBin := cmd.Flag("sops-bin").Value.String()
|
|
dryRun, err := cmd.Flags().GetBool("dry-run")
|
|
diff, err := cmd.Flags().GetBool("diff")
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
configObj, err := controller.ReadTheConfig(config)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
configObj.SopsBin = sopsBin
|
|
|
|
err = controller.Sync(workdir, sshKey, configObj, dryRun, diff)
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
logrus.Info("your config is synced")
|
|
}
|