Skip to content

Commit

Permalink
Accept file paths from CLI arguments, closes #10
Browse files Browse the repository at this point in the history
Squashed commit of the following:
commit e32052e
Author: 孙娇 <[email protected]>
Date:   Wed May 15 23:51:52 2024 +0800

    complete

commit f4fa97d
Merge: c07631a 16e020a
Author: 孙娇 <[email protected]>
Date:   Wed May 15 22:35:17 2024 +0800

    Merge branch 'main' into args

commit c07631a
Merge: ca10e3d 3ecc9c8
Author: 孙娇 <[email protected]>
Date:   Tue Apr 16 16:15:43 2024 +0800

    Merge branch 'main' into args

commit ca10e3d
Author: 孙娇 <[email protected]>
Date:   Tue Apr 16 15:39:06 2024 +0800

    arg test

commit 3d144ac
Author: 孙娇 <[email protected]>
Date:   Mon Apr 15 09:27:42 2024 +0800

    add args support
  • Loading branch information
sun-jiao committed May 15, 2024
1 parent 16e020a commit 018013e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
16 changes: 16 additions & 0 deletions dev/dart_args_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:args/args.dart';

void main([List<String> arguments = const []]) async {
var parser = ArgParser();
parser.addFlag('hekl', abbr: 'h');

arguments.indexWhere((element) => element.startsWith('-'));

final results = parser.parse(arguments);

print(results.options.toList());
print(results.arguments);
print(results.rest);

print(arguments);
}
10 changes: 9 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:args/args.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:intl/intl.dart' hide TextDirection;
Expand All @@ -10,6 +11,8 @@ import 'entity/sharedpref.dart';
import 'entity/theme_extension.dart';
import 'l10n/l10n.dart';
import 'pages/home_page.dart';
import 'pages/files_page.dart';
import 'tools/ex_file.dart';
import 'widget/custom_dialog.dart';

late Locale _appLocale;
Expand All @@ -19,7 +22,7 @@ Locale _getLocale() {
return Locale(localeNames[0], localeNames.length > 1 ? localeNames[1] : null);
}

void main() async {
void main([List<String> arguments = const []]) async {
WidgetsFlutterBinding.ensureInitialized();
_appLocale = _getLocale();
L10n.load(_appLocale);
Expand All @@ -33,6 +36,11 @@ void main() async {
),
);

final results = ArgParser().parse(arguments);

final initFiles = results.rest.map((e) => e.toFileSystemEntity().absolute);
FilesPage.addFiles(initFiles);

while (!Shared.initialed) {
await Shared.init();
}
Expand Down
4 changes: 4 additions & 0 deletions lib/pages/files_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class FilesPage extends StatefulWidget {

@override
State<FilesPage> createState() => FilesPageState();

static void addFiles(Iterable<FileSystemEntity> files) {
_files.addAll(files);
}
}

final List<FileSystemEntity> _files = [];
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies:

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
args: ^2.5.0
audio_metadata_reader: ^0.0.5
cross_file: ^0.3.4+1
crypto: ^3.0.3
Expand Down

0 comments on commit 018013e

Please sign in to comment.