-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from MindscapeHQ/feature/6-env-vars
feat: #6 support environment variables
- Loading branch information
Showing
15 changed files
with
257 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import 'dart:io'; | ||
|
||
/// Wraps access to Environment variables | ||
/// Allows faking for testing | ||
class Environment { | ||
static String raygunAppIdKey = 'RAYGUN_APP_ID'; | ||
static String raygunTokenKey = 'RAYGUN_TOKEN'; | ||
|
||
final String? raygunAppId; | ||
final String? raygunToken; | ||
|
||
static Environment? _instance; | ||
|
||
/// Singleton instance access | ||
/// Will init if not already | ||
static Environment get instance { | ||
_instance ??= Environment._init(); | ||
return _instance!; | ||
} | ||
|
||
/// For testing purposes | ||
static void setInstance(Environment instance) { | ||
_instance = instance; | ||
} | ||
|
||
/// Create custom instance | ||
Environment({ | ||
required this.raygunAppId, | ||
required this.raygunToken, | ||
}); | ||
|
||
factory Environment._init() { | ||
final raygunAppId = Platform.environment[raygunAppIdKey]; | ||
final raygunToken = Platform.environment[raygunTokenKey]; | ||
return Environment( | ||
raygunAppId: raygunAppId, | ||
raygunToken: raygunToken, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -407,4 +407,4 @@ packages: | |
source: hosted | ||
version: "3.1.2" | ||
sdks: | ||
dart: ">=3.5.0 <4.0.0" | ||
dart: ">=3.6.0 <4.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.