/
main.dart
77 lines (65 loc) · 2.12 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import 'package:mason_logger/mason_logger.dart';
enum Shape {
square,
circle,
triangle,
diamond,
}
Future<void> main() async {
final logger = Logger(level: Level.verbose)
..info('info')
..alert('alert')
..err('error')
..success('success')
..warn('warning')
..detail('detail')
..info('');
final favoriteColor = logger.chooseOne(
'Pick a color.',
choices: ['red', 'green', 'blue'],
defaultValue: 'blue',
);
logger.info('Got it, $favoriteColor it is!');
final desserts = logger.chooseAny(
'Which desserts do you like?',
choices: ['🍦', '🍪', '🍩'],
);
logger.info('Awesome, $desserts it is!');
final favoriteAnimal = logger.prompt(
'What is your favorite animal?',
defaultValue: '🐈',
);
final likesCats = logger.confirm('Do you like cats?', defaultValue: true);
final progress = logger.progress('Calculating');
await Future<void>.delayed(const Duration(milliseconds: 500));
progress.update('Halfway!');
await Future<void>.delayed(const Duration(milliseconds: 500));
progress.complete('Done!');
logger
..info('Your favorite animal is a $favoriteAnimal!')
..alert(likesCats ? 'You are a cat person!' : 'You are not a cat person.');
final failing = logger.progress('Trying to fail now!');
await Future<void>.delayed(const Duration(seconds: 1));
failing.fail('See I failed!');
final canceling = logger.progress('Trying to cancel now!');
await Future<void>.delayed(const Duration(seconds: 1));
canceling.cancel();
final repoLink = link(
message: 'GitHub Repository',
uri: Uri.parse('https://github.com/felangel/mason'),
);
logger.info('To learn more, visit the $repoLink.');
final shape = logger.chooseOne<Shape>(
'What is your favorite shape?',
choices: Shape.values,
display: (shape) => 'Is it a ${shape.name}?',
);
logger.info('You chose $shape!');
final shapes = logger.chooseAny<Shape>(
'Or did you want to choose multiples?',
choices: Shape.values,
defaultValues: [shape],
display: (shape) => 'Is it a ${shape.name}?',
);
logger.info('You chose the following shapes: $shapes!');
}