Ejemplo n.º 1
0
func main() {
	cmds := &cobra.Command{
		Use:   "gofabric8",
		Short: "gofabric8 is used to validate & deploy fabric8 components on to your Kubernetes or OpenShift environment",
		Long: `gofabric8 is used to validate & deploy fabric8 components on to your Kubernetes or OpenShift environment
								Find more information at http://fabric8.io.`,
		Run: runHelp,
	}

	f := cmdutil.NewFactory(nil)
	f.BindFlags(cmds.PersistentFlags())

	cmds.PersistentFlags().StringP("version", "v", "latest", "fabric8 version")
	cmds.PersistentFlags().BoolP("yes", "y", false, "assume yes")

	cmds.AddCommand(commands.NewCmdValidate(f))
	cmds.AddCommand(commands.NewCmdDeploy(f))
	cmds.AddCommand(commands.NewCmdPull(f))
	cmds.AddCommand(commands.NewCmdRoutes(f))
	cmds.AddCommand(commands.NewCmdSecrets(f))
	cmds.AddCommand(commands.NewCmdVolume(f))
	cmds.AddCommand(commands.NewCmdVersion())

	cmds.Execute()
}
Ejemplo n.º 2
0
func main() {
	cmds := &cobra.Command{
		Use:   "gofabric8",
		Short: "gofabric8 is used to validate & deploy fabric8 components on to your Kubernetes or OpenShift environment",
		Long: `gofabric8 is used to validate & deploy fabric8 components on to your Kubernetes or OpenShift environment
								Find more information at http://fabric8.io.`,
		Run: runHelp,
	}

	cmds.PersistentFlags().String("fabric8-version", "latest", "fabric8 version")
	cmds.PersistentFlags().BoolP("yes", "y", false, "assume yes")
	cmds.PersistentFlags().BoolP(batchFlag, "b", false, "Run in batch mode to avoid prompts")

	f := cmdutil.NewFactory(nil)
	f.BindFlags(cmds.PersistentFlags())

	updated := false
	oldHandler := cmds.PersistentPreRun
	cmds.PersistentPreRun = func(cmd *cobra.Command, args []string) {
		if !updated {
			updated = true
			flag := cmds.Flags().Lookup(batchFlag)
			batch := false
			if flag != nil {
				batch = flag.Value.String() == "true"
			}

			if !batch {
				home := homedir.HomeDir()
				if home == "" {
					util.Fatalf("No user home environment variable found for OS %s", runtime.GOOS)
				}
				writeFileLocation := home + hiddenFolder
				err := os.MkdirAll(writeFileLocation, 0700)
				if err != nil {
					util.Errorf("Unable to create directory to store update file %s %v\n", writeFileLocation, err)
				}
				localVersion, err := version.GetSemverVersion()
				if err != nil {
					util.Errorf("Unable to get local version %v", err)
				}
				viper.SetDefault(config.WantUpdateNotification, true)
				viper.SetDefault(config.ReminderWaitPeriodInHours, 24)
				update.MaybeUpdate(os.Stdout, githubOrg, githubRepo, binaryName, writeFileLocation+lastUpdateCheck, localVersion)

			}
		}
		if oldHandler != nil {
			oldHandler(cmd, args)
		}
	}

	cmds.AddCommand(commands.NewCmdConsole(f))
	cmds.AddCommand(commands.NewCmdDeploy(f))
	cmds.AddCommand(commands.NewCmdDockerEnv(f))
	cmds.AddCommand(commands.NewCmdIngress(f))
	cmds.AddCommand(commands.NewCmdInstall(f))
	cmds.AddCommand(commands.NewCmdPull(f))
	cmds.AddCommand(commands.NewCmdRoutes(f))
	cmds.AddCommand(commands.NewCmdRun(f))
	cmds.AddCommand(commands.NewCmdSecrets(f))
	cmds.AddCommand(commands.NewCmdService(f))
	cmds.AddCommand(commands.NewCmdStart(f))
	cmds.AddCommand(commands.NewCmdValidate(f))
	cmds.AddCommand(commands.NewCmdVersion())
	cmds.AddCommand(commands.NewCmdVolumes(f))

	cmds.Execute()
}