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 no push changes to git") 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") if err != nil { logrus.Fatal(err) } configObj, err := controller.ReadTheConfig(config) if err != nil { logrus.Fatal(err) } configObj.SopsBin = sopsBin err = controller.Reconcile(workdir, sshKey, configObj, dryRun) if err != nil { logrus.Fatal(err) } logrus.Info("your config is synced") }