Initial logic is implemented
This commit is contained in:
47
cmd/root.go
Normal file
47
cmd/root.go
Normal file
@ -0,0 +1,47 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.badhouseplants.net/allanger/giops/internal/build"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var fullVersion = fmt.Sprintf("%s - %s", build.Version, build.CommitHash)
|
||||
var longDescription = `---
|
||||
Giops is just GitOps with a glottal T
|
||||
|
||||
It's a tool that is supposed to help engineers follow the GitOps practies
|
||||
without fighting with GitOps being inapplicable to the real world.
|
||||
|
||||
Yeah, I quite hate this GitOps obsession, but since it's already there,
|
||||
I think it makes sense to make it work.
|
||||
|
||||
---
|
||||
Information about the build:
|
||||
Version: %s (build on %s)
|
||||
|
||||
---
|
||||
`
|
||||
|
||||
var (
|
||||
rootCmd = &cobra.Command{
|
||||
Use: "giops",
|
||||
Short: "giops – GitOps without pain, kinda",
|
||||
Long: fmt.Sprintf(longDescription, fullVersion, build.BuildTime),
|
||||
SilenceErrors: true,
|
||||
SilenceUsage: true,
|
||||
Version: build.Version,
|
||||
}
|
||||
)
|
||||
|
||||
func Execute(ctx context.Context) error {
|
||||
rootCmd.PersistentFlags().Bool("server", false, "Set to true, if you want to start it in the deamon mode")
|
||||
if err := rootCmd.ExecuteContext(ctx); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Whoops. There was an error while executing your CLI '%s'", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return nil
|
||||
}
|
46
cmd/sync.go
Normal file
46
cmd/sync.go
Normal file
@ -0,0 +1,46 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"git.badhouseplants.net/allanger/giops/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")
|
||||
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()
|
||||
dryRun, err := cmd.Flags().GetBool("dry-run")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
configObj, err := controller.ReadTheConfig(config)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
err = controller.Reconcile(workdir, sshKey, configObj, dryRun)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
logrus.Info("your config is synced")
|
||||
}
|
Reference in New Issue
Block a user