-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_props.dart
More file actions
62 lines (51 loc) · 1.47 KB
/
config_props.dart
File metadata and controls
62 lines (51 loc) · 1.47 KB
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
import 'dart:io';
import 'package:args/args.dart';
import 'package:raygun_cli/environment.dart';
/// Configuration properties for the Raygun CLI
class ConfigProps {
/// Raygun's application ID
final String appId;
/// Raygun's access token
final String token;
ConfigProps._({
required this.appId,
required this.token,
});
/// Load configuration properties from arguments or environment variables
/// and return a new instance of [ConfigProps] or exit with code 2.
factory ConfigProps.load(ArgResults arguments, {bool verbose = false}) {
String? appId;
String? token;
// Providing app-id and token via argument takes priority
if (arguments.wasParsed('app-id')) {
appId = arguments['app-id'];
} else {
appId = Environment.instance.raygunAppId;
}
if (appId == null) {
print('Error: Missing "app-id"');
print(
' Please provide "app-id" via argument or environment variable "RAYGUN_APP_ID"');
exit(2);
}
if (arguments.wasParsed('token')) {
token = arguments['token'];
} else {
token = Environment.instance.raygunToken;
}
if (token == null) {
print('Error: Missing "token"');
print(
' Please provide "token" via argument or environment variable "RAYGUN_TOKEN"');
exit(2);
}
if (verbose) {
print('App ID: $appId');
print('Token: $token');
}
return ConfigProps._(
appId: appId,
token: token,
);
}
}