Commit 04aeef84 authored by xster's avatar xster Committed by GitHub

Let iOS flutter run auto-sign default to first profile (#10181)

* Let run default to first profile

* fix

* review notes
parent 437d4ab1
...@@ -90,16 +90,29 @@ class AnsiTerminal { ...@@ -90,16 +90,29 @@ class AnsiTerminal {
/// Prompts the user to input a chraracter within the accepted list. /// Prompts the user to input a chraracter within the accepted list.
/// Reprompts if inputted character is not in the list. /// Reprompts if inputted character is not in the list.
/// ///
/// `prompt` is the text displayed prior to waiting for user input each time.
/// `defaultChoiceIndex`, if given, will be the character in `acceptedCharacters`
/// in the index given if the user presses enter without any key input.
/// `displayAcceptedCharacters` prints also the accepted keys next to the `prompt` if true.
///
/// Throws a [TimeoutException] if a `timeout` is provided and its duration /// Throws a [TimeoutException] if a `timeout` is provided and its duration
/// expired without user input. Duration resets per key press. /// expired without user input. Duration resets per key press.
Future<String> promptForCharInput( Future<String> promptForCharInput(
List<String> acceptedCharacters, { List<String> acceptedCharacters, {
String prompt, String prompt,
int defaultChoiceIndex,
bool displayAcceptedCharacters: true, bool displayAcceptedCharacters: true,
Duration timeout, Duration timeout,
}) async { }) async {
assert(acceptedCharacters != null); assert(acceptedCharacters != null);
assert(acceptedCharacters.isNotEmpty); assert(acceptedCharacters.isNotEmpty);
List<String> charactersToDisplay = acceptedCharacters;
if (defaultChoiceIndex != null) {
assert(defaultChoiceIndex >= 0 && defaultChoiceIndex < acceptedCharacters.length);
charactersToDisplay = new List<String>.from(charactersToDisplay);
charactersToDisplay[defaultChoiceIndex] = bolden(charactersToDisplay[defaultChoiceIndex]);
acceptedCharacters.add('\n');
}
String choice; String choice;
singleCharMode = true; singleCharMode = true;
while( while(
...@@ -110,7 +123,7 @@ class AnsiTerminal { ...@@ -110,7 +123,7 @@ class AnsiTerminal {
if (isNotEmpty(prompt)) { if (isNotEmpty(prompt)) {
printStatus(prompt, emphasis: true, newline: false); printStatus(prompt, emphasis: true, newline: false);
if (displayAcceptedCharacters) if (displayAcceptedCharacters)
printStatus(' [${acceptedCharacters.join("|")}]', newline: false); printStatus(' [${charactersToDisplay.join("|")}]', newline: false);
printStatus(': ', emphasis: true, newline: false); printStatus(': ', emphasis: true, newline: false);
} }
Future<String> inputFuture = onCharInput.first; Future<String> inputFuture = onCharInput.first;
...@@ -120,6 +133,8 @@ class AnsiTerminal { ...@@ -120,6 +133,8 @@ class AnsiTerminal {
printStatus(choice); printStatus(choice);
} }
singleCharMode = false; singleCharMode = false;
if (defaultChoiceIndex != null && choice == '\n')
choice = acceptedCharacters[defaultChoiceIndex];
return choice; return choice;
} }
} }
......
...@@ -153,6 +153,7 @@ Future<String> _chooseSigningIdentity(List<String> validCodeSigningIdentities) a ...@@ -153,6 +153,7 @@ Future<String> _chooseSigningIdentity(List<String> validCodeSigningIdentities) a
..add('a'), ..add('a'),
prompt: 'Please select a certificate for code signing', prompt: 'Please select a certificate for code signing',
displayAcceptedCharacters: true, displayAcceptedCharacters: true,
defaultChoiceIndex: 0, // Just pressing enter chooses the first one.
); );
if (choice == 'a') if (choice == 'a')
......
...@@ -21,6 +21,7 @@ void main() { ...@@ -21,6 +21,7 @@ void main() {
testUsingContext('character prompt', () async { testUsingContext('character prompt', () async {
mockStdInStream = new Stream<String>.fromFutures(<Future<String>>[ mockStdInStream = new Stream<String>.fromFutures(<Future<String>>[
new Future<String>.value('d'), // Not in accepted list. new Future<String>.value('d'), // Not in accepted list.
new Future<String>.value('\n'), // Not in accepted list
new Future<String>.value('b'), new Future<String>.value('b'),
]).asBroadcastStream(); ]).asBroadcastStream();
final String choice = final String choice =
...@@ -29,10 +30,32 @@ void main() { ...@@ -29,10 +30,32 @@ void main() {
prompt: 'Please choose something', prompt: 'Please choose something',
); );
expect(choice, 'b'); expect(choice, 'b');
expect(testLogger.statusText, ''' expect(
Please choose something [a|b|c]: d testLogger.statusText,
Please choose something [a|b|c]: b 'Please choose something [a|b|c]: d\n'
'''); 'Please choose something [a|b|c]: \n'
'\n'
'Please choose something [a|b|c]: b\n'
);
});
testUsingContext('default character choice without displayAcceptedCharacters', () async {
mockStdInStream = new Stream<String>.fromFutures(<Future<String>>[
new Future<String>.value('\n'), // Not in accepted list
]).asBroadcastStream();
final String choice =
await terminalUnderTest.promptForCharInput(
<String>['a', 'b', 'c'],
prompt: 'Please choose something',
displayAcceptedCharacters: false,
defaultChoiceIndex: 1, // which is b.
);
expect(choice, 'b');
expect(
testLogger.statusText,
'Please choose something: \n'
'\n'
);
}); });
}); });
} }
......
...@@ -189,7 +189,7 @@ void main() { ...@@ -189,7 +189,7 @@ void main() {
expect( expect(
testLogger.statusText, testLogger.statusText,
contains('Please select a certificate for code signing [1|2|3|a]: 3') contains('Please select a certificate for code signing [<bold>1</bold>|2|3|a]: 3')
); );
expect( expect(
testLogger.statusText, testLogger.statusText,
...@@ -228,6 +228,9 @@ class MockStdIn extends Mock implements IOSink {} ...@@ -228,6 +228,9 @@ class MockStdIn extends Mock implements IOSink {}
Stream<String> mockTerminalStdInStream; Stream<String> mockTerminalStdInStream;
class TestTerminal extends AnsiTerminal { class TestTerminal extends AnsiTerminal {
@override
String bolden(String message) => '<bold>$message</bold>';
@override @override
Stream<String> get onCharInput { Stream<String> get onCharInput {
return mockTerminalStdInStream; return mockTerminalStdInStream;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment