Exemple #1
1
// ValidateMain is called by the generated validate command.
// ke: {"func": {"notest": true}}
func ValidateMain(path string) {

	// Using process.Flags as the options means that the non-specified options are read from the
	// command flags.
	update := false
	options := &process.Flags{
		Update: &update,
		Path:   &path,
	}

	ctx, cancel, err := process.Initialise(context.Background(), options)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}

	// The log function outputs errors and messages to the console. We pass it in to permit testing.
	log := func(message string) {
		fmt.Println(message)
	}

	// The interrupt chanel signals that Ctrl+C or other OS interrupts have happened.
	interrupt := make(chan os.Signal, 1)
	signal.Notify(interrupt, os.Interrupt)
	signal.Notify(interrupt, syscall.SIGTERM)

	exitStatus := validateMain(ctx, cancel, log, interrupt)

	wgctx.WaitAndExit(ctx, exitStatus)

}
Exemple #2
0
Fichier : main.go Projet : kego/ke
func main() {
	// This turns off focus reporting mode that will print “^[[O” and “^[[I”
	// when the terminal window gets / loses focus
	// http://superuser.com/questions/931873/o-and-i-appearing-on-iterm2-when-focus-lost
	fmt.Print("\033[?1004l")

	ctx, cancel, err := process.Initialise(context.Background(), nil)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	env := envctx.FromContext(ctx)
	cmd := cmdctx.FromContext(ctx)

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	signal.Notify(c, syscall.SIGTERM)
	go func() {
		<-c
		cancel()
	}()

	if err := process.GenerateAll(ctx, env.Path, map[string]bool{}); err != nil {
		fmt.Println(err.Error())
		wgctx.WaitAndExit(ctx, 1)
	}

	if cmd.Validate {
		err := process.RunValidateCommand(ctx)
		if err != nil {
			if !cmd.Log {
				// in log mode, we have already written the output of the exec'ed ke command,
				// so we don't need to duplicate the error message.
				if v, ok := kerr.Source(err).(validate.ValidationCommandError); ok {
					fmt.Println(v.Description)
					wgctx.WaitAndExit(ctx, 4) // Exit code 4: validation error
				}
				fmt.Println(err.Error())
			}
			wgctx.WaitAndExit(ctx, 1)
		}
	}

	if cmd.Edit {
		if err = server.Start(ctx, cancel); err != nil {
			fmt.Println(err.Error())
			wgctx.WaitAndExit(ctx, 1)
		}
	}

	wgctx.WaitAndExit(ctx, 0)

}