func (c *UnregisterCommand) Execute(context *cli.Context) {
	if !common.DeleteRunner(c.URL, c.Token) {
		log.Fatalln("Failed to delete runner")
	}

	err := c.loadConfig()
	if err != nil {
		log.Warningln(err)
		return
	}

	runners := []*common.RunnerConfig{}
	for _, otherRunner := range c.config.Runners {
		if otherRunner.RunnerCredentials == c.RunnerCredentials {
			continue
		}
		runners = append(runners, otherRunner)
	}

	// 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 runUnregister(c *cli.Context) {
	runner := common.RunnerConfig{
		URL:   c.String("url"),
		Token: c.String("token"),
	}

	if !common.DeleteRunner(runner.URL, runner.Token) {
		log.Fatalln("Failed to delete runner")
	}

	config := common.NewConfig()
	err := config.LoadConfig(c.String("config"))
	if err != nil {
		return
	}

	runners := []*common.RunnerConfig{}
	for _, otherRunner := range config.Runners {
		if otherRunner.Token == runner.Token && otherRunner.URL == runner.URL {
			continue
		}
		runners = append(runners, otherRunner)
	}

	// 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 *RegisterCommand) Execute(context *cli.Context) {
	c.context = context
	err := c.loadConfig()
	if err != nil {
		log.Fatalln(err)
	}
	c.askRunner()

	if !c.LeaveRunner {
		defer func() {
			if r := recover(); r != nil {
				if c.registered {
					common.DeleteRunner(c.URL, c.Token)
				}

				// pass panic to next defer
				panic(r)
			}
		}()

		signals := make(chan os.Signal, 1)
		signal.Notify(signals, os.Interrupt)

		go func() {
			s := <-signals
			common.DeleteRunner(c.URL, c.Token)
			log.Fatalf("RECEIVED SIGNAL: %v", s)
		}()
	}

	c.askExecutor()

	if limit := helpers.NonZeroOrDefault(c.Limit, 0); c.config.Concurrent < limit {
		log.Warningf("Specified limit (%d) larger then current concurrent limit (%d). Concurrent limit will not be enlarged.", limit, c.config.Concurrent)
	}

	switch c.Executor {
	case "docker":
		c.askDocker()
		c.SSH = nil
		c.Parallels = nil
	case "docker-ssh":
		c.askDocker()
		c.askSSHLogin()
		c.Parallels = nil
	case "ssh":
		c.askSSHServer()
		c.askSSHLogin()
		c.Docker = nil
		c.Parallels = nil
	case "parallels":
		c.askParallels()
		c.askSSHServer()
		c.Docker = nil
	}

	c.addRunner(&c.RunnerConfig)
	c.saveConfig()

	log.Printf("Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!")
}
func runRegister(c *cli.Context) {
	s := RegistrationContext{
		Context:    c,
		config:     common.NewConfig(),
		configFile: c.String("config"),
		reader:     bufio.NewReader(os.Stdin),
	}

	defer func() {
		if r := recover(); r != nil {
			log.Fatalf("FATAL ERROR: %v", r)
		}
	}()

	s.loadConfig()

	runnerConfig := s.askRunner()

	if !c.Bool("leave-runner") {
		defer func() {
			if r := recover(); r != nil {
				common.DeleteRunner(runnerConfig.URL, runnerConfig.Token)
				// pass panic to next defer
				panic(r)
			}
		}()

		signals := make(chan os.Signal, 1)
		signal.Notify(signals, os.Interrupt)

		go func() {
			s := <-signals
			common.DeleteRunner(runnerConfig.URL, runnerConfig.Token)
			log.Fatalf("RECEIVED SIGNAL: %v", s)
		}()
	}

	runnerConfig.Executor = s.askExecutor()
	limit := c.Int("limit")
	runnerConfig.Limit = &limit

	if s.config.Concurrent < limit {
		log.Warningf("Specified limit (%d) larger then current concurrent limit (%d). Concurrent limit will not be enlarged.", limit, s.config.Concurrent)
	}

	switch runnerConfig.Executor {
	case "docker", "docker-ssh":
		s.askDocker(&runnerConfig)
	case "parallels":
		s.askParallels(&runnerConfig)
	}

	switch runnerConfig.Executor {
	case "ssh":
		s.askSSH(&runnerConfig, false)
	case "docker-ssh":
		s.askSSH(&runnerConfig, true)
	case "parallels":
		s.askSSH(&runnerConfig, true)
	}

	s.addRunner(&runnerConfig)
	s.saveConfig()

	log.Printf("Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!")
}