MCPcopy Create free account
hub / github.com/cli/cli / Ask

Method Ask

pkg/cmd/codespace/common.go:158–178  ·  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

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

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