@@ -9,22 +9,43 @@ abstract class MeCommands {
99 }) async {
1010 final user = await cloudApiClient.users.readUser ();
1111
12- String planDisplayName = 'No plan' ;
12+ SubscriptionInfo ? subscriptionInfo ;
1313 try {
14- final subscriptionInfo = await cloudApiClient.plans.getSubscriptionInfo ();
15- planDisplayName = subscriptionInfo.planDisplayName;
16- } on NoSubscriptionException {
17- planDisplayName = 'No plan' ;
14+ subscriptionInfo = await cloudApiClient.plans.getSubscriptionInfo ();
15+ } on NoSubscriptionException catch (_) {
1816 } on Exception catch (e) {
1917 logger.debug ('Failed to fetch subscription info: $e ' );
2018 }
2119
20+ final planDisplayName = subscriptionInfo? .planDisplayName ?? 'No plan' ;
21+ final status = _determineStatus (subscriptionInfo) ?? '' ;
22+
2223 final table = TablePrinter (
23- headers: ['Email' , 'Plan' ],
24+ headers: ['Email' , 'Plan' , 'Status' ],
2425 rows: [
25- [user.email, planDisplayName],
26+ [user.email, planDisplayName, status ],
2627 ],
2728 );
2829 table.writeLines (logger.line);
2930 }
31+
32+ static String ? _determineStatus (final SubscriptionInfo ? subscriptionInfo) {
33+ if (subscriptionInfo == null ) {
34+ return null ;
35+ }
36+
37+ final now = DateTime .now ();
38+ final today = DateTime (now.year, now.month, now.day);
39+
40+ final endDate = subscriptionInfo.endDate;
41+ final trialEndDate = subscriptionInfo.trialEndDate;
42+
43+ if (endDate != null && endDate.isBefore (today)) {
44+ return 'Subscription ended ${endDate .toString ().substring (0 , 10 )}' ;
45+ } else if (trialEndDate != null && ! trialEndDate.isBefore (today)) {
46+ return 'Trial until ${trialEndDate .toString ().substring (0 , 10 )}' ;
47+ } else {
48+ return 'Subscription active' ;
49+ }
50+ }
3051}
0 commit comments