|
In the last skunkworks I implemented this as function confirmOkay which just returns whether the user typed "yes" back in to its prompting. I didn't check it in as part of SERVER-36196 because that was the determination if the session is interactive (when shell is in script mode you do not want to prompt, I would think) so that was a prerequisite.
I would change this ticket title to be "Ability to prompt in interactive shell" the code looked something like this in shell_utils.cpp:
+BSONObj promptOkay(const BSONObj& a, void*) {
|
+ Prompter prompter1("Okay to run this query anyway? (type yes) > ");
|
+ return BSON("" << prompter1.confirmOkay());
|
+}
|
+
|
...
|
+bool Prompter::confirmOkay() {
|
+ std::string input = "";
|
+ std::cout << _prompt;
|
+ getline(std::cin, input);
|
+ return (input=="yes");
|
+}
|
+
|
plus in shell_utils.h
I didn't submit it because I didn't get around to setting it up to accept a prompting string and I didn't write tests, but leaving this here just as an FYI.
|