示例#1
0
文件: main.go 项目: bsundsrud/slapt
func run(cmd *commander.Command) (returnCode int) {
	defer func() {
		if r := recover(); r != nil {
			fatal, ok := r.(*ctx.FatalError)
			if !ok {
				panic(r)
			}
			fmt.Fprintln(os.Stderr, "ERROR:", fatal.Message)
			returnCode = fatal.ReturnCode
		}
	}()
	returnCode = 0

	flags, _, err := cmd.ParseFlags([]string{"-config", "conf/slapt.conf"})
	if err != nil {
		ctx.Fatal(err)
	}

	err = initCtx(flags)
	if err != nil {
		ctx.Fatal(err)
	}
	defer shutdownContext()
	context.UpdateFlags(flags)

	err = http.ListenAndServe("localhost:8080", web.Router(context))
	if err != nil {
		ctx.Fatal(fmt.Errorf("unable to serve: %s", err))
	}

	return
}
示例#2
0
文件: run.go 项目: liftup/aptly
// Run runs single command starting from root cmd with args, optionally initializing context
func Run(cmd *commander.Command, cmdArgs []string, initContext bool) (returnCode int) {
	defer func() {
		if r := recover(); r != nil {
			fatal, ok := r.(*ctx.FatalError)
			if !ok {
				panic(r)
			}
			fmt.Fprintln(os.Stderr, "ERROR:", fatal.Message)
			returnCode = fatal.ReturnCode
		}
	}()

	returnCode = 0

	flags, args, err := cmd.ParseFlags(cmdArgs)
	if err != nil {
		ctx.Fatal(err)
	}

	if initContext {
		err = InitContext(flags)
		if err != nil {
			ctx.Fatal(err)
		}
		defer ShutdownContext()
	}

	context.UpdateFlags(flags)

	err = cmd.Dispatch(args)
	if err != nil {
		ctx.Fatal(err)
	}

	return
}