Skip to content

Commit

Permalink
feat: basic command line argument support
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Feb 3, 2023
1 parent 0104362 commit 025c1ae
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
51 changes: 49 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'dart:convert';
import 'dart:io';

import 'package:args/args.dart';
import 'package:catcher/catcher.dart';
import 'package:fl_query/fl_query.dart';
import 'package:flutter/foundation.dart';
Expand All @@ -8,6 +10,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:spotube/collections/cache_keys.dart';
Expand All @@ -29,7 +32,42 @@ import 'package:window_manager/window_manager.dart';
import 'package:window_size/window_size.dart';

final bowl = QueryBowl();
void main() async {
void main(List<String> rawArgs) async {
final parser = ArgParser();

parser.addFlag(
'verbose',
abbr: 'v',
help: 'Verbose mode',
callback: (verbose) {
if (verbose) {
Platform.environment['VERBOSE'] = 'true';
Platform.environment['DEBUG'] = 'true';
Platform.environment['ERROR'] = 'true';
}
},
);
parser.addFlag(
"version",
help: "Print version and exit",
negatable: false,
);

parser.addFlag("help", abbr: "h", negatable: false);

final arguments = parser.parse(rawArgs);

if (arguments["help"] == true) {
print(parser.usage);
exit(0);
}

if (arguments["version"] == true) {
final package = await PackageInfo.fromPlatform();
print("Spotube v${package.version}");
exit(0);
}

WidgetsFlutterBinding.ensureInitialized();
await Hive.initFlutter();
Hive.registerAdapter(CacheTrackAdapter());
Expand Down Expand Up @@ -64,6 +102,7 @@ void main() async {
}

Catcher(
enableLogger: arguments["verbose"] ?? !kReleaseMode,
debugConfig: CatcherOptions(
SilentReportMode(),
[
Expand All @@ -86,7 +125,15 @@ void main() async {
],
),
releaseConfig: CatcherOptions(SilentReportMode(), [
FileHandler(await getLogsPath(), printLogs: false),
if (arguments["verbose"] ?? false)
ConsoleHandler(
enableDeviceParameters: false,
enableApplicationParameters: false,
),
FileHandler(
await getLogsPath(),
printLogs: false,
),
]),
runAppFunction: () {
runApp(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ packages:
source: hosted
version: "3.3.6"
args:
dependency: transitive
dependency: "direct main"
description:
name: args
url: "https://pub.dartlang.org"
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ environment:

dependencies:
adwaita: ^0.5.2
args: ^2.3.2
async: ^2.9.0
audio_service: ^0.18.9
audio_session: ^0.1.13
Expand Down

0 comments on commit 025c1ae

Please sign in to comment.