|
| 1 | +import 'dart:io'; |
| 2 | + |
| 3 | +import 'package:raygun_cli/deployments/deployments_api.dart'; |
| 4 | +import 'package:args/args.dart'; |
| 5 | +import '../config_props.dart'; |
| 6 | + |
| 7 | +class Deployments { |
| 8 | + final ArgResults command; |
| 9 | + final bool verbose; |
| 10 | + late final String appId; |
| 11 | + late final String token; |
| 12 | + |
| 13 | + Deployments({ |
| 14 | + required this.command, |
| 15 | + required this.verbose, |
| 16 | + required ConfigProps config, |
| 17 | + }) { |
| 18 | + appId = config.appId; |
| 19 | + token = config.token; |
| 20 | + } |
| 21 | + |
| 22 | + Future<void> notify() async { |
| 23 | + if (!command.wasParsed('api-key')) { |
| 24 | + print('Error: Missing "--api-key"'); |
| 25 | + print(' Please provide "--api-key" via argument'); |
| 26 | + exit(2); |
| 27 | + } |
| 28 | + if (!command.wasParsed('version')) { |
| 29 | + print('Error: Missing "--version"'); |
| 30 | + print(' Please provide "--version" via argument'); |
| 31 | + exit(2); |
| 32 | + } |
| 33 | + |
| 34 | + final apiKey = command.option('api-key') as String; |
| 35 | + final version = command.option('version') as String; |
| 36 | + final ownerName = command.option('owner-name'); |
| 37 | + final emailAddress = command.option('email-address'); |
| 38 | + final comment = command.option('comment'); |
| 39 | + final scmIdentifier = command.option('scm-identifier'); |
| 40 | + final scmType = command.option('scm-type'); |
| 41 | + |
| 42 | + if (verbose) { |
| 43 | + print('app-id: $appId'); |
| 44 | + print('token: $token'); |
| 45 | + print('api-key: $apiKey'); |
| 46 | + print('version: $version'); |
| 47 | + print('owner-name: $ownerName'); |
| 48 | + print('email-address: $emailAddress'); |
| 49 | + print('comment: $comment'); |
| 50 | + print('scm-identifier: $scmIdentifier'); |
| 51 | + print('scm-type: $scmType'); |
| 52 | + } |
| 53 | + |
| 54 | + final success = await createDeployment( |
| 55 | + token: token, |
| 56 | + apiKey: apiKey, |
| 57 | + version: version, |
| 58 | + ownerName: ownerName, |
| 59 | + emailAddress: emailAddress, |
| 60 | + comment: comment, |
| 61 | + scmIdentifier: scmIdentifier, |
| 62 | + scmType: scmType, |
| 63 | + ); |
| 64 | + |
| 65 | + if (success) { |
| 66 | + print('Deployment created successfully'); |
| 67 | + exit(0); |
| 68 | + } else { |
| 69 | + print('Failed to create deployment'); |
| 70 | + exit(2); |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments