Skip to content

Commit f58102f

Browse files
committed
[add] terrun update command
1 parent 764b9a3 commit f58102f

13 files changed

+78
-52
lines changed

analysis_options.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
include: package:lints/recommended.yaml
2+
3+
linter:
4+
rules:
5+
- prefer_single_quotes
6+
- unawaited_futures

lib/features/configure/configure.dart

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'dart:io';
33

44
import 'package:args/command_runner.dart';
55
import 'package:terrun/services/services.dart';
6-
import 'package:terrun/services/shell/shell.dart';
76

87
import 'defaults.dart';
98

lib/features/features.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
export 'configure/configure.dart';
12
export 'loop.dart';
3+
export 'update.dart';

lib/features/update.dart

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import 'dart:async';
2+
3+
import 'package:args/command_runner.dart';
4+
import 'package:terrun/services/display/display.dart';
5+
import 'package:terrun/services/shell/shell_service.dart';
6+
7+
class UpdateCommand extends Command<void> {
8+
final ShellService _shell;
9+
final DisplayService _display;
10+
11+
UpdateCommand(
12+
this._shell,
13+
this._display,
14+
);
15+
@override
16+
String get description => 'Updates to the latest version';
17+
18+
@override
19+
String get name => 'update';
20+
21+
@override
22+
FutureOr<void>? run() async {
23+
var script = [
24+
'git -C \$(brew --repository mikeborodin/terrun) pull',
25+
'brew upgrade terrun',
26+
];
27+
final updated = await Stream.fromIterable(script).asyncMap((line) => _shell.run(line)).any(
28+
(element) => element.stdout != 0,
29+
);
30+
if (updated) {
31+
_display.drawMessage(
32+
'Updated successfully',
33+
type: MessageType.success,
34+
);
35+
} else {
36+
_display.drawMessage(
37+
'Error while running lines $script',
38+
type: MessageType.error,
39+
);
40+
}
41+
}
42+
}

lib/main.dart

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
11
import 'package:args/command_runner.dart';
2-
import 'package:terrun/features/configure/configure.dart';
3-
import 'package:terrun/features/loop.dart';
4-
import 'package:terrun/services/services.dart';
5-
import 'package:terrun/services/shell/shell_service.dart';
6-
import 'package:terrun/services/shell/shell_service_impl.dart';
2+
3+
import 'features/features.dart';
4+
import 'services/services.dart';
75

86
Future<void> app(List<String> args) async {
97
var env = Env.load();
10-
118
final ShellService shell = ShellServiceImpl();
129
final RunnerService shellRunner = ProcessRunnerService(shell);
1310
final DisplayService display = ConsoleDisplaySevice()..init();
1411

15-
final commandRunner = CommandRunner(
12+
final runner = CommandRunner(
1613
'terrun',
1714
'run anything with minimum keystrokes',
18-
);
19-
20-
commandRunner
15+
)
2116
..addCommand(ConfigureCommand(
2217
display,
2318
shell,
@@ -27,7 +22,13 @@ Future<void> app(List<String> args) async {
2722
shellRunner,
2823
display,
2924
env,
30-
));
25+
))
26+
..addCommand(
27+
UpdateCommand(
28+
shell,
29+
display,
30+
),
31+
);
3132

32-
await commandRunner.run(args);
33+
await runner.run(args);
3334
}

lib/services/display/console_display_service.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ConsoleDisplaySevice implements DisplayService {
5050
@override
5151
void clear() => _clear();
5252

53-
void _clear() => print("\x1B[2J\x1B[0;0H");
53+
void _clear() => print('\x1B[2J\x1B[0;0H');
5454

5555
void _drawInput(String input) {
5656
stdout.writeln('----------------------');

lib/services/display/display.dart

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import 'package:riverpod/riverpod.dart';
2-
3-
import 'console_display_service.dart';
4-
import 'display_service.dart';
5-
1+
export 'colored_string_ext.dart';
62
export 'console_display_service.dart';
73
export 'display_service.dart';
8-
export 'colored_string_ext.dart';
94

10-
final displayServiceProvider = Provider<DisplayService>(
11-
(ref) => ConsoleDisplaySevice(),
12-
);

lib/services/services.dart

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export 'config/config_reader.dart';
33
export 'display/display.dart';
44
export 'env/env.dart';
55
export 'runner/runner.dart';
6+
export 'shell/shell.dart';

lib/services/shell/shell_service.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'dart:io';
22

3+
export 'shell_service_impl.dart';
4+
35
abstract class ShellService {
46
Future<ProcessResult> run(String commands);
57
}

pubspec.lock

-16
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,6 @@ packages:
217217
url: "https://pub.dev"
218218
source: hosted
219219
version: "2.1.3"
220-
riverpod:
221-
dependency: "direct main"
222-
description:
223-
name: riverpod
224-
sha256: "59a48de9c757aa61aa28e9fd625ffb360d43b6b54606f12536622c55be9e8c4b"
225-
url: "https://pub.dev"
226-
source: hosted
227-
version: "2.2.0"
228220
shelf:
229221
dependency: transitive
230222
description:
@@ -289,14 +281,6 @@ packages:
289281
url: "https://pub.dev"
290282
source: hosted
291283
version: "1.11.0"
292-
state_notifier:
293-
dependency: transitive
294-
description:
295-
name: state_notifier
296-
sha256: "8fe42610f179b843b12371e40db58c9444f8757f8b69d181c97e50787caed289"
297-
url: "https://pub.dev"
298-
source: hosted
299-
version: "0.7.2+1"
300284
stream_channel:
301285
dependency: transitive
302286
description:

pubspec.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: terrun
22
description: terrun - efficient terminal runner
3-
version: 0.0.3
3+
version: 0.0.6
44
repository: https://github.com/mikeborodin/menusc
55

66
environment:
@@ -9,7 +9,6 @@ environment:
99
dependencies:
1010
ansicolor: ^2.0.1
1111
args: ^2.4.0
12-
riverpod: ^2.2.0
1312
yaml: ^3.1.1
1413

1514
dev_dependencies:

test/services/config/config_parser_test.dart

+10-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void main() {
88
parser = ConfigParser();
99
});
1010
test('should parse 3 leveled yaml config', () async {
11-
final config = parser.parse("""
11+
final config = parser.parse('''
1212
commands:
1313
n:
1414
name: apps
@@ -19,7 +19,7 @@ commands:
1919
n:
2020
name: telegram
2121
command: open -a telegram
22-
""");
22+
''');
2323
expect(
2424
config.commands.keys,
2525
equals(
@@ -29,7 +29,7 @@ commands:
2929
});
3030

3131
test('should parse 3 leveled yaml config', () async {
32-
final config = parser.parse("""
32+
final config = parser.parse('''
3333
commands:
3434
n:
3535
name: group1
@@ -43,7 +43,7 @@ commands:
4343
t:
4444
name: telegram
4545
command: open -a telegram
46-
""");
46+
''');
4747
expect(
4848
config.commands.keys,
4949
equals(
@@ -52,7 +52,7 @@ commands:
5252
);
5353
});
5454
test('should parse preRun hooks from yaml config', () async {
55-
final config = parser.parse("""
55+
final config = parser.parse('''
5656
hooks:
5757
preRun:
5858
- command: test
@@ -65,17 +65,17 @@ commands:
6565
name: chrome browser
6666
command: open -a chrome
6767
68-
""");
68+
''');
6969
expect(
7070
config.hooks.preRun.first.command,
7171
equals(
72-
"test",
72+
'test',
7373
),
7474
);
7575
});
7676

7777
test('should parse postRun hooks from yaml config', () async {
78-
final config = parser.parse("""
78+
final config = parser.parse('''
7979
hooks:
8080
postRun:
8181
- command: test
@@ -88,11 +88,11 @@ commands:
8888
name: chrome browser
8989
command: open -a chrome
9090
91-
""");
91+
''');
9292
expect(
9393
config.hooks.postRun.first.command,
9494
equals(
95-
"test",
95+
'test',
9696
),
9797
);
9898
});

test/services/runner/runner_service_test.dart

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:terrun/core/core.dart';
22
import 'package:terrun/services/runner/console_runner_service.dart';
33
import 'package:terrun/services/runner/runner_service.dart';
44
import 'package:terrun/services/shell/shell_service.dart';
5-
import 'package:terrun/services/shell/shell_service_impl.dart';
65
import 'package:test/test.dart';
76

87
void main() {

0 commit comments

Comments
 (0)