Esempio n. 1
0
File: cli.go Progetto: luk5/rexray
func (c *CLI) preRun(cmd *cobra.Command, args []string) {

	if c.cfgFile != "" && gotil.FileExists(c.cfgFile) {
		if err := c.r.Config.ReadConfigFile(c.cfgFile); err != nil {
			panic(err)
		}
		cmd.Flags().Parse(os.Args[1:])
	}

	c.updateLogLevel()

	c.r.Config = c.r.Config.Scope("rexray.modules.default-docker")

	if isHelpFlag(cmd) {
		cmd.Help()
		panic(&helpFlagPanic{})
	}

	if permErr := c.checkCmdPermRequirements(cmd); permErr != nil {
		if term.IsTerminal() {
			printColorizedError(permErr)
		} else {
			printNonColorizedError(permErr)
		}

		fmt.Println()
		cmd.Help()
		panic(&printedErrorPanic{})
	}

	if c.isInitDriverManagersCmd(cmd) {
		if err := c.r.InitDrivers(); err != nil {

			if term.IsTerminal() {
				printColorizedError(err)
			} else {
				printNonColorizedError(err)
			}
			fmt.Println()

			helpCmd := cmd
			if cmd == c.volumeCmd {
				helpCmd = c.volumeGetCmd
			} else if cmd == c.snapshotCmd {
				helpCmd = c.snapshotGetCmd
			} else if cmd == c.deviceCmd {
				helpCmd = c.deviceGetCmd
			} else if cmd == c.adapterCmd {
				helpCmd = c.adapterGetTypesCmd
			}
			helpCmd.Help()

			panic(&printedErrorPanic{})
		}
	}
}
Esempio n. 2
0
func preRun(cmd *cobra.Command, args []string) {

	if cfgFile != "" && util.FileExists(cfgFile) {
		if err := c.ReadConfigFile(cfgFile); err != nil {
			panic(err)
		}
		cmd.Flags().Parse(os.Args[1:])
	}

	updateLogLevel()

	if isHelpFlag(cmd) {
		cmd.Help()
		panic(&HelpFlagPanic{})
	}

	if permErr := checkCmdPermRequirements(cmd); permErr != nil {
		if term.IsTerminal() {
			printColorizedError(permErr)
		} else {
			printNonColorizedError(permErr)
		}

		fmt.Println()
		cmd.Help()
		panic(&PrintedErrorPanic{})
	}

	if isInitDriverManagersCmd(cmd) {
		if initDmErr := initDriverManagers(); initDmErr != nil {

			if term.IsTerminal() {
				printColorizedError(initDmErr)
			} else {
				printNonColorizedError(initDmErr)
			}
			fmt.Println()

			helpCmd := cmd
			if cmd == volumeCmd {
				helpCmd = volumeGetCmd
			} else if cmd == snapshotCmd {
				helpCmd = snapshotGetCmd
			} else if cmd == deviceCmd {
				helpCmd = deviceGetCmd
			} else if cmd == adapterCmd {
				helpCmd = adapterGetTypesCmd
			}
			helpCmd.Help()

			panic(&PrintedErrorPanic{})
		}
	}
}