Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): bad state error on no argument #7

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions bin/stacked.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ Future<void> main(List<String> arguments) async {

if (_handleAnalytics(argResults)) exit(0);

// Ignore notify version for compile and update commands
if (arguments.first != 'compile' && arguments.first != 'update') {
await _notifyNewVersionAvailable();
}
await _notifyNewVersionAvailable(arguments: arguments);

runner.run(arguments);
} on InvalidStackedStructureException catch (e) {
Expand Down Expand Up @@ -119,7 +116,17 @@ Future<void> _handleFirstRun() async {
analyticsService.enable(opt == 'y' || opt == 'yes');
}

Future<void> _notifyNewVersionAvailable() async {
/// Notifies new version of Stacked CLI is available
Future<void> _notifyNewVersionAvailable({
List<String> arguments = const [],
List<String> ignored = const ['compile', 'update'],
}) async {
if (arguments.isEmpty) return;

for (var arg in ignored) {
if (arguments.first == arg) return;
}

if (await locator<PubService>().hasLatestVersion()) return;

stdout.writeln('''
Expand Down
2 changes: 1 addition & 1 deletion lib/src/services/pub_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PubService {

/// Returns current `stacked_cli` version installed on the system.
Future<String> getCurrentVersion() async {
late String version;
String version = 'Current Version Not Available';

final packages = await _processService.runPubGlobalList();
for (var package in packages) {
Expand Down