Skip to content

Commit

Permalink
⚡ Better version handling
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse committed Mar 8, 2022
1 parent 8dfed5d commit 06a0625
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 30 deletions.
30 changes: 16 additions & 14 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:alfred_workflow/alfred_workflow.dart'
show AlfredItem, AlfredItemIcon, AlfredItemText, AlfredWorkflow;
import 'package:algolia/algolia.dart' show AlgoliaQuerySnapshot;
import 'package:args/args.dart' show ArgParser, ArgResults;
import 'package:collection/collection.dart' show IterableExtension;
import 'package:easy_debounce/easy_debounce.dart' show EasyDebounce;
import 'package:html_unescape/html_unescape.dart' show HtmlUnescape;

Expand Down Expand Up @@ -87,32 +88,33 @@ void main(List<String> arguments) async {
final ArgParser parser = ArgParser()
..addOption('query', abbr: 'q', mandatory: true)
..addFlag('verbose', abbr: 'v', defaultsTo: false);

final ArgResults args = parser.parse(arguments);

final String query = args['query'].replaceAll(RegExp(r'\s+'), ' ').trim();
final String version = query.split(' ').firstWhere(
List<String> query =
args['query'].replaceAll(RegExp(r'\s+'), ' ').trim().split(' ');
String? version = query.firstWhereOrNull(
(el) => Config.supportedVersions.contains(el),
orElse: () => Config.supportedVersions.last,
);

if (args['verbose']) {
verbose = true;
);
if (version != null) {
query.removeWhere((str) => str == version);
} else {
version = Config.supportedVersions.last;
}
final String queryString = query.join(' ').trim();

if (verbose) {
stdout.writeln('Query: "$query"');
}
if (args['verbose']) verbose = true;

if (verbose) stdout.writeln('Query: "$queryString"');

EasyDebounce.debounce(
'search',
Duration(milliseconds: 250),
() async {
if (query.isEmpty) {
() async {
if (queryString.isEmpty) {
_showPlaceholder();
} else {
await _performSearch(
query,
queryString,
version: version,
);
}
Expand Down
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>2.0.0</string>
<string>2.0.1</string>
<key>webaddress</key>
<string>https://github.com/techouse</string>
</dict>
Expand Down
21 changes: 7 additions & 14 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "34.0.0"
version: "36.0.0"
alfred_workflow:
dependency: "direct main"
description:
Expand All @@ -30,7 +30,7 @@ packages:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.0"
version: "3.3.1"
analyzer_plugin:
dependency: transitive
description:
Expand Down Expand Up @@ -66,20 +66,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
cli_util:
dependency: transitive
description:
name: cli_util
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.5"
collection:
dependency: transitive
dependency: "direct main"
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -107,14 +100,14 @@ packages:
name: dart_code_metrics
url: "https://pub.dartlang.org"
source: hosted
version: "4.11.0"
version: "4.12.0"
dart_style:
dependency: transitive
description:
name: dart_style
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
version: "2.2.2"
easy_debounce:
dependency: "direct main"
description:
Expand Down Expand Up @@ -198,7 +191,7 @@ packages:
name: pub_semver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.1"
source_span:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Search the Tailwind CSS documentation using Alfred
# Prevent accidental publishing to pub.dev.
publish_to: 'none'

version: 2.0.0
version: 2.0.1

environment:
sdk: '>=2.16.1 <3.0.0'
Expand All @@ -18,6 +18,7 @@ dependencies:
git:
url: git@github.com:techouse/alfred_workflow.git
ref: master
collection: ^1.16.0

dev_dependencies:
lints: ^1.0.0
Expand Down

0 comments on commit 06a0625

Please sign in to comment.