Esempio n. 1
0
// Run ...
func Run() {
	// Parse cl
	cli.VersionPrinter = printVersion

	app := cli.NewApp()
	app.Name = path.Base(os.Args[0])
	app.Usage = "Bitrise Automations Workflow Runner"
	app.Version = version.VERSION

	app.Author = ""
	app.Email = ""

	app.Before = before

	app.Flags = flags
	app.Commands = commands

	app.Action = func(c *cli.Context) error {
		pluginName, pluginArgs, isPlugin := plugins.ParseArgs(c.Args())
		if isPlugin {
			log.Debugf("Try to run bitrise plugin: (%s) with args: (%v)", pluginName, pluginArgs)

			plugin, found, err := plugins.LoadPlugin(pluginName)
			if err != nil {
				return fmt.Errorf("Failed to get plugin (%s), error: %s", pluginName, err)
			}
			if !found {
				return fmt.Errorf("Plugin (%s) not installed", pluginName)
			}

			log.Debugf("Start plugin: (%s)", pluginName)
			if err := plugins.RunPluginByCommand(plugin, pluginArgs); err != nil {
				return fmt.Errorf("Failed to run plugin (%s), error: %s", pluginName, err)
			}
		} else {
			if err := cli.ShowAppHelp(c); err != nil {
				return fmt.Errorf("Failed to show help, error: %s", err)
			}
			return errors.New("")
		}

		return nil
	}

	if err := app.Run(os.Args); err != nil {
		log.Fatal(err)
	}
}
Esempio n. 2
0
// Run ...
func Run() {
	// Parse cl
	cli.VersionPrinter = printVersion

	app := cli.NewApp()
	app.Name = path.Base(os.Args[0])
	app.Usage = "Bitrise Automations Workflow Runner"
	app.Version = "1.3.0"

	app.Author = ""
	app.Email = ""

	app.Before = before

	app.Flags = flags
	app.Commands = commands

	app.Action = func(c *cli.Context) {
		pluginName, pluginType, pluginArgs, isPlugin := plugins.ParseArgs(c.Args())
		if isPlugin {
			log.SetLevel(log.DebugLevel)
			log.Debugln()
			log.Debugf("Try to run bitrise plugin: (%s) (type: %s) with args: (%v)", pluginName, pluginType, pluginArgs)

			printableName := plugins.PrintableName(pluginName, pluginType)
			log.Debugf("Plugin: %v", printableName)

			plugin, err := plugins.GetPlugin(pluginName, pluginType)
			if err != nil {
				log.Fatalf("Failed to get plugin (%s), err: %s", printableName, err)
			}

			messageFromPlugin, err := plugins.RunPlugin(app.Version, plugin, pluginArgs)
			log.Debugf("message from plugin: %s", messageFromPlugin)

			if err != nil {
				log.Fatalf("Failed to run plugin (%s), err: %s", printableName, err)
			}
		} else {
			cli.ShowAppHelp(c)
		}
	}

	if err := app.Run(os.Args); err != nil {
		log.Fatal("Finished with Error:", err)
	}
}