Beispiel #1
0
func handleAuthentication(client *trackerapi.Client, terminal *term.Terminal) {
	if !client.IsAuthenticated() {
		username := terminal.Prompt("Username: "******"Password: ", term.DisableEcho)
		client.Authenticate(username, password)
	}
}
Beispiel #2
0
		It("returns an instance of Terminal", func() {
			Expect(terminal).To(BeAssignableToTypeOf(&term.Terminal{}))
		})

		It("defaults the InputFile to os.Stdin", func() {
			Expect(terminal.InputFile).To(Equal(os.Stdin))
		})

		It("defaults the OutputFile to os.Stdout", func() {
			Expect(terminal.OutputFile).To(Equal(os.Stdout))
		})
	})

	Describe("Terminal#Prompt", func() {
		var (
			terminal      *term.Terminal
			stdin, stdout *os.File
		)
		BeforeEach(func() {
			terminal = term.New()
			stdin, _ = ioutil.TempFile(os.TempDir(), "stdin")
			stdout, _ = ioutil.TempFile(os.TempDir(), "stdout")
			terminal.SetInput(stdin)
			terminal.SetOutput(stdout)
		})

		It("prints the prompt, waits for and returns user input", func() {
			stdin.WriteString("Mister Tee")
			stdin.Seek(0, 0)
			output := terminal.Prompt("What is your name?: ", term.EnableEcho)
			Expect(output).To(ContainSubstring("Mister Tee"))
			stdoutContents, _ := ioutil.ReadFile(stdout.Name())