-
Notifications
You must be signed in to change notification settings - Fork 231
/
Copy pathgithub_activity.dart
54 lines (44 loc) · 1.23 KB
/
github_activity.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
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:cli_app/github_activity.dart';
import 'package:cli_app/src/formatter.dart';
void main(List<String> args) {
var options = parseOptions(args);
if (options.help) {
_printUsage();
return;
}
if (options.user?.isEmpty ?? true) {
_printUsage();
return;
}
var fetcher = ActivityService(
options.user!,
options.verbose!,
options.interval,
formatter: _getFormatter(options),
);
// Stream the github activity to the console
fetcher.getActivityStrings().listen((s) {
print(s);
})
..onDone(() => exit(0))
..onError((e) => print('Unable to fetch stats:\n$e'));
}
/// Gets the correct [Formatter] defined by [Options]
EventFormatter _getFormatter(Options options) {
if (options.format == 'markdown') {
return MarkdownEventFormatter();
}
return DefaultEventFormatter();
}
void _printUsage() {
print('''
A command line utility for fetching a GitHub user's recent activity.
Usage: github_activity [<args>]
Arguments:
${parser.usage}
''');
}