Beispiel #1
0
func cmdShell(app *cli.App) {
	cli.OsExiter = func(c int) {}
	reader := bufio.NewReader(os.Stdin)
	sigs := make(chan os.Signal, 1)
	go func() {
		for range sigs {
			fmt.Printf("\n(type quit or q to exit)\n\nblesh >")
		}
	}()
	defer close(sigs)
	signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
	for {
		fmt.Print("blesh > ")
		text, _ := reader.ReadString('\n')
		text = strings.TrimSpace(text)
		if text == "" {
			continue
		}
		if text == "quit" || text == "q" {
			break
		}
		app.Run(append(os.Args[1:], strings.Split(text, " ")...))
	}
	signal.Stop(sigs)
}
Beispiel #2
0
func cmdConsole(app *cli.App, c *cli.Context) error {
	// don't hard exit on mistyped commands (eg. check vs check_tx)
	app.CommandNotFound = badCmd
	for {
		fmt.Printf("\n> ")
		bufReader := bufio.NewReader(os.Stdin)
		line, more, err := bufReader.ReadLine()
		if more {
			return errors.New("Input is too long")
		} else if err != nil {
			return err
		}

		args := []string{"tmsp-cli"}
		args = append(args, strings.Split(string(line), " ")...)
		if err := app.Run(args); err != nil {
			// if the command doesn't succeed, inform the user without exiting
			fmt.Println("Error:", err.Error())
		}
	}
}
Beispiel #3
0
func cmdBatch(app *cli.App, c *cli.Context) error {
	bufReader := bufio.NewReader(os.Stdin)
	for {
		line, more, err := bufReader.ReadLine()
		if more {
			return errors.New("Input line is too long")
		} else if err == io.EOF {
			break
		} else if len(line) == 0 {
			continue
		} else if err != nil {
			return err
		}
		args := []string{"tmsp-cli"}
		if c.GlobalBool("verbose") {
			args = append(args, "--verbose")
		}
		args = append(args, strings.Split(string(line), " ")...)
		app.Run(args)
	}
	return nil
}
Beispiel #4
0
func registerControlCommandsAt(app *cli.App) {
	clientFactory := client.NewFactory(conf.Instance())

	commonClientFlags := []cli.Flag{}

	app.Commands = append(app.Commands,
		createConfigCommand(commonClientFlags, clientFactory),
		createControlConfigCommand(commonClientFlags, clientFactory),
		createServicesCommand(commonClientFlags, clientFactory),
		createServiceCommand(commonClientFlags, clientFactory),
		createServiceConfigCommand(commonClientFlags, clientFactory),
		createServiceStatusCommand(commonClientFlags, clientFactory),
		createServicePidCommand(commonClientFlags, clientFactory),
		createStartServiceCommand(commonClientFlags, clientFactory),
		createRestartServiceCommand(commonClientFlags, clientFactory),
		createStopServiceCommand(commonClientFlags, clientFactory),
		createKillServiceCommand(commonClientFlags, clientFactory),
		createSignalServiceCommand(commonClientFlags, clientFactory),
	)
}
Beispiel #5
0
func registerDaemonCommandsAt(executableType ExecutableType, app *cli.App) {
	var name string
	switch executableType {
	case Daemon:
		name = "run"
	default:
		name = "daemon"
	}

	app.Commands = append(app.Commands, cli.Command{
		Name:            name,
		SkipFlagParsing: true,
		ArgsUsage:       "[<args pass to master service>...]",
		Usage:           "Run " + caretakerd.DaemonName + " in forground.",
		Before:          ensureDaemonConfig,
		Action: func(context *cli.Context) {
			runDaemon(*conf.instance, context.Args())
		},
		OnUsageError: onUsageErrorFor(name),
	})

}