MCPcopy
hub / github.com/cli/cli / Ask

Method Ask

pkg/cmd/codespace/common.go:157–177  ·  view source on GitHub ↗

ask asks survey questions on the terminal, using standard options. It fails unless hasTTY, but ideally callers should avoid calling it in that case.

(qs []*survey.Question, response interface{})

Source from the content-addressed store, hash-verified

155// ask asks survey questions on the terminal, using standard options.
156// It fails unless hasTTY, but ideally callers should avoid calling it in that case.
157func (p *Prompter) Ask(qs []*survey.Question, response interface{}) error {
158 if !hasTTY {
159 return fmt.Errorf("no terminal")
160 }
161 err := survey.Ask(qs, response, survey.WithShowCursor(true))
162 // The survey package temporarily clears the terminal's ISIG mode bit
163 // (see tcsetattr(3)) so the QUIT button (Ctrl-C) is reported as
164 // ASCII \x03 (ETX) instead of delivering SIGINT to the application.
165 // So we have to serve ourselves the SIGINT.
166 //
167 // https://github.com/AlecAivazis/survey/#why-isnt-ctrl-c-working
168 if err == terminal.InterruptErr {
169 self, _ := os.FindProcess(os.Getpid())
170 _ = self.Signal(os.Interrupt) // assumes POSIX
171
172 // Suspend the goroutine, to avoid a race between
173 // return from main and async delivery of INT signal.
174 select {}
175 }
176 return err
177}
178
179var ErrTooManyArgs = errors.New("the command accepts no arguments")
180

Callers 3

chooseCodespaceFromListFunction · 0.95
ConfirmMethod · 0.95
CreateMethod · 0.95

Implementers 4

PrompterMockinternal/prompter/prompter_mock.go
huhPrompterinternal/prompter/huh_prompter.go
accessiblePrompterinternal/prompter/prompter.go
surveyPrompterinternal/prompter/prompter.go

Calls 2

ErrorfMethod · 0.65
AskMethod · 0.65

Tested by

no test coverage detected