コード例 #1
0
ファイル: main.go プロジェクト: abiosoft/ishell
func main() {
	shell := ishell.New()

	// display info
	shell.Println("Sample Interactive Shell")

	// handle login
	shell.Register("login", func(args ...string) (string, error) {
		doLogin(shell)
		return "", nil
	})

	// handle "greet".
	shell.Register("greet", func(args ...string) (string, error) {
		name := "Stranger"
		if len(args) > 0 {
			name = strings.Join(args, " ")
		}
		return "Hello " + name, nil
	})

	// read multiple lines with "multi" command
	shell.Register("multi", func(args ...string) (string, error) {
		shell.Println("Input multiple lines and end with semicolon ';'.")
		lines := shell.ReadMultiLines(";")
		shell.Println("Done reading. You wrote:")
		return lines, nil
	})

	// start shell
	shell.Start()
}
コード例 #2
0
ファイル: cli.go プロジェクト: cpitoniak/cli
func createNewShell() {
	shell = ishell.New()
}
コード例 #3
0
ファイル: main.go プロジェクト: abiosoft/runcmd
func main() {
	if len(os.Args) < 2 {
		fmt.Println("command missing.")
		os.Exit(1)
	}
	app := &runCmd{
		cmds: os.Args[1:],
	}

	shell := ishell.New()

	// remove defaults
	shell.Unregister("exit")
	shell.Unregister("help")
	shell.Unregister("clear")

	// handle all inputs
	shell.RegisterGeneric(func(args ...string) (string, error) {
		vars := env.EnvVar(append(os.Environ(), app.vars...))
		for i, a := range args {
			if strings.HasPrefix(a, "$") {
				if val := vars.Get(a[1:]); val != "" {
					args[i] = val
				}
			}
		}
		return "", app.run(args)
	})
	// environment variables
	shell.Register(".env", func(args ...string) (string, error) {
		switch len(args) {
		case 0:
			return app.vars.String(), nil
		case 1:
			app.vars.SetStr(args[0])
			return "", nil
		case 2:
			app.vars.Set(args[0], args[1])
			return "", nil
		}
		app.vars.Set(args[0], args[1])
		return "", fmt.Errorf(".env accepts at most 2 arguments")
	})
	// exit
	shell.Register(".exit", func(args ...string) (string, error) {
		shell.Stop()
		return "", nil
	})
	// clear screen
	shell.Register(".clear", func(args ...string) (string, error) {
		return "", shell.ClearScreen()
	})
	// switch command
	shell.Register(".switch", func(args ...string) (string, error) {
		app.cmds = args
		app.resetPrompt()
		return "", shell.ClearScreen()
	})
	// help text
	shell.Register(".help", func(args ...string) (string, error) {
		return help, nil
	})

	app.shell = shell
	app.resetPrompt()

	shell.Start()
}
コード例 #4
0
func main() {
	// create new shell.
	// by default, new shell includes 'exit', 'help' and 'clear' commands.
	shell := ishell.New()

	// display welcome info.
	shell.Println("PowerDNS Manager")

	commands.Init(shell)

	// start shell
	shell.Start()

	//zone := new(pdns.Zone)
	//zone.DNSSEC = false
	//zone.Kind = "Master"
	//zone.LastCheck = 0
	//zone.Name = "test.com"
	//zone.Type = "Zone"
	//zone.Records = make([]*pdns.Record, 6)
	//zone.Nameservers = []string{}

	//zone.Records[0] = new(pdns.Record)
	//zone.Records[0].Name = "test.com"
	//zone.Records[0].Type = "SOA"
	//zone.Records[0].Content = "dns1.epic-sys.io. info.epic.net. 2016012001 3600 600 2600 60"
	//zone.Records[0].Priority = 0
	//zone.Records[0].Disabled = false
	//zone.Records[0].TTL = 300
	//zone.Records[1] = new(pdns.Record)
	//zone.Records[1].Name = "test.com"
	//zone.Records[1].Type = "NS"
	//zone.Records[1].Content = "dns1.epic-sys.io"
	//zone.Records[1].Priority = 0
	//zone.Records[1].Disabled = false
	//zone.Records[1].TTL = 300
	//zone.Records[2] = new(pdns.Record)
	//zone.Records[2].Name = "test.com"
	//zone.Records[2].Type = "NS"
	//zone.Records[2].Content = "dns2.epic-sys.io"
	//zone.Records[2].Priority = 0
	//zone.Records[2].Disabled = false
	//zone.Records[2].TTL = 300
	//zone.Records[3] = new(pdns.Record)
	//zone.Records[3].Name = "test.com"
	//zone.Records[3].Type = "NS"
	//zone.Records[3].Content = "dns3.epic-sys.io"
	//zone.Records[3].Priority = 0
	//zone.Records[3].Disabled = false
	//zone.Records[3].TTL = 300
	//zone.Records[4] = new(pdns.Record)
	//zone.Records[4].Name = "test.com"
	//zone.Records[4].Type = "A"
	//zone.Records[4].Content = "127.0.0.1"
	//zone.Records[4].Priority = 0
	//zone.Records[4].Disabled = false
	//zone.Records[4].TTL = 300
	//zone.Records[5] = new(pdns.Record)
	//zone.Records[5].Name = "www.test.com"
	//zone.Records[5].Type = "CNAME"
	//zone.Records[5].Content = "test.com"
	//zone.Records[5].Priority = 0
	//zone.Records[5].Disabled = false
	//zone.Records[5].TTL = 300

	//request := gorequest.New()
	//request.Type("json")
	//request.Post("http://dns1.epic-sys.io/servers/localhost/zones")
	//request.Set("X-API-Key", "bisque.tutelage.organist.payment")
	//request.SendStruct(zone)
	//_, body, errs := request.End()
	//spew.Dump(body)
	//spew.Dump(errs)

}