Exemple #1
0
// Run the console.
func Console(config core.Config) (err error) {
	fmt.Printf(`
Welcome to the Gate administration console!

Gate Copyright (C) 2012-2015 Cyril Adrian <*****@*****.**>
This program comes with ABSOLUTELY NO WARRANTY; for details type show w.
This is free software, and you are welcome to redistribute it
under certain conditions; type show c for details.

Type help for details on available options.
Just hit <enter> to exit.

`)

	srv, err := proxy(config)
	if err != nil {
		return
	}

	remoter := remote.NewRemoter(srv, config)
	if err != nil {
		return
	}

	mmi, err := ui.Ui(srv, config)
	if err != nil {
		return
	}

	commander, err := commands.NewCommander(remoter, srv, config, mmi)
	if err != nil {
		return
	}

	state := liner.NewLiner()
	defer state.Close()

	rl := &readline{
		commander: commander,
		server:    srv,
		state:     state,
	}

	complete := func(line string) (result []string) {
		result, err := rl.complete(line)
		if err != nil {
			fmt.Println(err)
			return
		}
		return
	}

	state.SetCompleter(complete)

	e := rl.loop(config)
	if e != io.EOF {
		err = e
	}
	return
}
Exemple #2
0
// Run the console.
func CommandLine(config core.Config) (err error) {

	srv, err := proxy(config)
	if err != nil {
		return
	}

	remoter := remote.NewRemoter(srv, config)
	if err != nil {
		return
	}

	mmi, err := ui.Ui(srv, config)
	if err != nil {
		return
	}

	commander, err := commands.NewCommander(remoter, srv, config, mmi)
	if err != nil {
		return
	}

	cmd := commander.Command(os.Args[2])
	if cmd == nil {
		cmd = commander.Default()
	}

	err = cmd.Run(os.Args[2:])

	return
}