func runVerify(c *cli.Context) {
	config := common.NewConfig()
	err := config.LoadConfig(c.String("config"))
	if err != nil {
		log.Fatalln(err)
		return
	}

	// verify if runner exist
	runners := []*common.RunnerConfig{}
	for _, runner := range config.Runners {
		if common.VerifyRunner(runner.URL, runner.Token) {
			runners = append(runners, runner)
		}
	}

	if !c.Bool("delete") {
		return
	}

	// check if anything changed
	if len(config.Runners) == len(runners) {
		return
	}

	config.Runners = runners

	// save config file
	err = config.SaveConfig(c.String("config"))
	if err != nil {
		log.Fatalln("Failed to update", c.String("config"), err)
	}
	log.Println("Updated", c.String("config"))
}
func (c *VerifyCommand) Execute(context *cli.Context) {
	err := c.loadConfig()
	if err != nil {
		log.Fatalln(err)
		return
	}

	// verify if runner exist
	runners := []*common.RunnerConfig{}
	for _, runner := range c.config.Runners {
		if common.VerifyRunner(runner.URL, runner.Token) {
			runners = append(runners, runner)
		}
	}

	if !c.DeleteNonExisting {
		return
	}

	// check if anything changed
	if len(c.config.Runners) == len(runners) {
		return
	}

	c.config.Runners = runners

	// save config file
	err = c.saveConfig()
	if err != nil {
		log.Fatalln("Failed to update", c.ConfigFile, err)
	}
	log.Println("Updated", c.ConfigFile)
}
func (s *RegisterCommand) askRunner() {
	s.URL = s.ask("url", "Please enter the gitlab-ci coordinator URL (e.g. https://ci.gitlab.com/):")

	if s.Token != "" {
		if !common.VerifyRunner(s.URL, s.Token) {
			log.Fatalln("Failed to verify this runner. Perhaps you are having network problems")
		}
	} else {
		s.RegistrationToken = s.ask("registration-token", "Please enter the gitlab-ci token for this runner:")
		s.Name = s.ask("name", "Please enter the gitlab-ci description for this runner:")
		s.TagList = s.ask("tag-list", "Please enter the gitlab-ci tags for this runner (comma separated):")

		result := common.RegisterRunner(s.URL, s.RegistrationToken, s.Name, s.TagList)
		if result == nil {
			log.Fatalln("Failed to register this runner. Perhaps you are having network problems")
		}

		s.Token = result.Token
		s.registered = true
	}
}
func (s *RegisterCommand) askRunner() {
	s.URL = s.ask("url", "Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/ci):")

	if s.Token != "" {
		log.Infoln("Token specified trying to verify runner...")
		log.Warningln("If you want to register use the '-r' instead of '-t'.")
		if !common.VerifyRunner(s.URL, s.Token) {
			log.Fatalln("Failed to verify this runner. Perhaps you are having network problems")
		}
	} else {
		s.RegistrationToken = s.ask("registration-token", "Please enter the gitlab-ci token for this runner:")
		s.Name = s.ask("name", "Please enter the gitlab-ci description for this runner:")
		s.TagList = s.ask("tag-list", "Please enter the gitlab-ci tags for this runner (comma separated):", true)

		result := common.RegisterRunner(s.URL, s.RegistrationToken, s.Name, s.TagList)
		if result == nil {
			log.Fatalln("Failed to register this runner. Perhaps you are having network problems")
		}

		s.Token = result.Token
		s.registered = true
	}
}