Skip to content

Commit 4c7ce87

Browse files
committed
[shell_executor] add pathExpansion utility method.
1 parent 42ea1fa commit 4c7ce87

File tree

6 files changed

+289
-1
lines changed

6 files changed

+289
-1
lines changed

packages/shell_executor/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.1.4
2+
3+
* add `pathExpansion` utility method.
4+
15
## 0.1.3
26

37
* Update dart sdk version to ">=2.16.0 <4.0.0"

packages/shell_executor/lib/shell_executor.dart

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ library shell_executor;
22

33
export 'src/command.dart';
44
export 'src/shell_executor.dart';
5+
export 'src/utils/path_expansion.dart';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
String pathExpansion(
2+
String path, [
3+
Map<String, String> environment = const {},
4+
]) {
5+
if (path.startsWith('~/')) {
6+
final home = environment['HOME'] ?? environment['USERPROFILE'];
7+
path = '$home${path.substring(1)}';
8+
}
9+
10+
final matches = [
11+
...RegExp(r'\$(\w+)').allMatches(path),
12+
...RegExp(r'\$\{(\w+)\}').allMatches(path)
13+
];
14+
for (final match in matches) {
15+
final envName = match.group(1);
16+
final envValue = environment[envName];
17+
path = path.replaceFirst(match.group(0)!, envValue ?? '');
18+
}
19+
return path;
20+
}

packages/shell_executor/pubspec.lock

+240
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
# Generated by pub
22
# See https://dart.dev/tools/pub/glossary#lockfile
33
packages:
4+
_fe_analyzer_shared:
5+
dependency: transitive
6+
description:
7+
name: _fe_analyzer_shared
8+
sha256: ae92f5d747aee634b87f89d9946000c2de774be1d6ac3e58268224348cd0101a
9+
url: "https://pub.dev"
10+
source: hosted
11+
version: "61.0.0"
12+
analyzer:
13+
dependency: transitive
14+
description:
15+
name: analyzer
16+
sha256: ea3d8652bda62982addfd92fdc2d0214e5f82e43325104990d4f4c4a2a313562
17+
url: "https://pub.dev"
18+
source: hosted
19+
version: "5.13.0"
420
args:
521
dependency: transitive
622
description:
@@ -17,6 +33,14 @@ packages:
1733
url: "https://pub.dev"
1834
source: hosted
1935
version: "2.11.0"
36+
boolean_selector:
37+
dependency: transitive
38+
description:
39+
name: boolean_selector
40+
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
41+
url: "https://pub.dev"
42+
source: hosted
43+
version: "2.1.1"
2044
build_config:
2145
dependency: transitive
2246
description:
@@ -41,6 +65,30 @@ packages:
4165
url: "https://pub.dev"
4266
source: hosted
4367
version: "1.17.2"
68+
convert:
69+
dependency: transitive
70+
description:
71+
name: convert
72+
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
73+
url: "https://pub.dev"
74+
source: hosted
75+
version: "3.1.1"
76+
coverage:
77+
dependency: transitive
78+
description:
79+
name: coverage
80+
sha256: "2fb815080e44a09b85e0f2ca8a820b15053982b2e714b59267719e8a9ff17097"
81+
url: "https://pub.dev"
82+
source: hosted
83+
version: "1.6.3"
84+
crypto:
85+
dependency: transitive
86+
description:
87+
name: crypto
88+
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
89+
url: "https://pub.dev"
90+
source: hosted
91+
version: "3.0.3"
4492
dependency_validator:
4593
dependency: "direct dev"
4694
description:
@@ -57,6 +105,14 @@ packages:
57105
url: "https://pub.dev"
58106
source: hosted
59107
version: "7.0.0"
108+
frontend_server_client:
109+
dependency: transitive
110+
description:
111+
name: frontend_server_client
112+
sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612"
113+
url: "https://pub.dev"
114+
source: hosted
115+
version: "3.2.0"
60116
glob:
61117
dependency: transitive
62118
description:
@@ -65,6 +121,22 @@ packages:
65121
url: "https://pub.dev"
66122
source: hosted
67123
version: "2.1.2"
124+
http_multi_server:
125+
dependency: transitive
126+
description:
127+
name: http_multi_server
128+
sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b"
129+
url: "https://pub.dev"
130+
source: hosted
131+
version: "3.2.1"
132+
http_parser:
133+
dependency: transitive
134+
description:
135+
name: http_parser
136+
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
137+
url: "https://pub.dev"
138+
source: hosted
139+
version: "4.0.2"
68140
io:
69141
dependency: transitive
70142
description:
@@ -73,6 +145,14 @@ packages:
73145
url: "https://pub.dev"
74146
source: hosted
75147
version: "1.0.4"
148+
js:
149+
dependency: transitive
150+
description:
151+
name: js
152+
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
153+
url: "https://pub.dev"
154+
source: hosted
155+
version: "0.6.7"
76156
json_annotation:
77157
dependency: transitive
78158
description:
@@ -89,6 +169,14 @@ packages:
89169
url: "https://pub.dev"
90170
source: hosted
91171
version: "1.2.0"
172+
matcher:
173+
dependency: transitive
174+
description:
175+
name: matcher
176+
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
177+
url: "https://pub.dev"
178+
source: hosted
179+
version: "0.12.16"
92180
meta:
93181
dependency: transitive
94182
description:
@@ -97,6 +185,22 @@ packages:
97185
url: "https://pub.dev"
98186
source: hosted
99187
version: "1.9.1"
188+
mime:
189+
dependency: transitive
190+
description:
191+
name: mime
192+
sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e
193+
url: "https://pub.dev"
194+
source: hosted
195+
version: "1.0.4"
196+
node_preamble:
197+
dependency: transitive
198+
description:
199+
name: node_preamble
200+
sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db"
201+
url: "https://pub.dev"
202+
source: hosted
203+
version: "2.0.2"
100204
package_config:
101205
dependency: transitive
102206
description:
@@ -113,6 +217,14 @@ packages:
113217
url: "https://pub.dev"
114218
source: hosted
115219
version: "1.8.3"
220+
pool:
221+
dependency: transitive
222+
description:
223+
name: pool
224+
sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a"
225+
url: "https://pub.dev"
226+
source: hosted
227+
version: "1.5.1"
116228
pub_semver:
117229
dependency: transitive
118230
description:
@@ -129,6 +241,54 @@ packages:
129241
url: "https://pub.dev"
130242
source: hosted
131243
version: "1.2.3"
244+
shelf:
245+
dependency: transitive
246+
description:
247+
name: shelf
248+
sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4
249+
url: "https://pub.dev"
250+
source: hosted
251+
version: "1.4.1"
252+
shelf_packages_handler:
253+
dependency: transitive
254+
description:
255+
name: shelf_packages_handler
256+
sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e"
257+
url: "https://pub.dev"
258+
source: hosted
259+
version: "3.0.2"
260+
shelf_static:
261+
dependency: transitive
262+
description:
263+
name: shelf_static
264+
sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e
265+
url: "https://pub.dev"
266+
source: hosted
267+
version: "1.1.2"
268+
shelf_web_socket:
269+
dependency: transitive
270+
description:
271+
name: shelf_web_socket
272+
sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1"
273+
url: "https://pub.dev"
274+
source: hosted
275+
version: "1.0.4"
276+
source_map_stack_trace:
277+
dependency: transitive
278+
description:
279+
name: source_map_stack_trace
280+
sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae"
281+
url: "https://pub.dev"
282+
source: hosted
283+
version: "2.1.1"
284+
source_maps:
285+
dependency: transitive
286+
description:
287+
name: source_maps
288+
sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703"
289+
url: "https://pub.dev"
290+
source: hosted
291+
version: "0.10.12"
132292
source_span:
133293
dependency: transitive
134294
description:
@@ -137,6 +297,22 @@ packages:
137297
url: "https://pub.dev"
138298
source: hosted
139299
version: "1.10.0"
300+
stack_trace:
301+
dependency: transitive
302+
description:
303+
name: stack_trace
304+
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
305+
url: "https://pub.dev"
306+
source: hosted
307+
version: "1.11.0"
308+
stream_channel:
309+
dependency: transitive
310+
description:
311+
name: stream_channel
312+
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
313+
url: "https://pub.dev"
314+
source: hosted
315+
version: "2.1.1"
140316
string_scanner:
141317
dependency: transitive
142318
description:
@@ -153,6 +329,70 @@ packages:
153329
url: "https://pub.dev"
154330
source: hosted
155331
version: "1.2.1"
332+
test:
333+
dependency: "direct dev"
334+
description:
335+
name: test
336+
sha256: "13b41f318e2a5751c3169137103b60c584297353d4b1761b66029bae6411fe46"
337+
url: "https://pub.dev"
338+
source: hosted
339+
version: "1.24.3"
340+
test_api:
341+
dependency: transitive
342+
description:
343+
name: test_api
344+
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
345+
url: "https://pub.dev"
346+
source: hosted
347+
version: "0.6.0"
348+
test_core:
349+
dependency: transitive
350+
description:
351+
name: test_core
352+
sha256: "99806e9e6d95c7b059b7a0fc08f07fc53fabe54a829497f0d9676299f1e8637e"
353+
url: "https://pub.dev"
354+
source: hosted
355+
version: "0.5.3"
356+
typed_data:
357+
dependency: transitive
358+
description:
359+
name: typed_data
360+
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
361+
url: "https://pub.dev"
362+
source: hosted
363+
version: "1.3.2"
364+
vm_service:
365+
dependency: transitive
366+
description:
367+
name: vm_service
368+
sha256: f3743ca475e0c9ef71df4ba15eb2d7684eecd5c8ba20a462462e4e8b561b2e11
369+
url: "https://pub.dev"
370+
source: hosted
371+
version: "11.6.0"
372+
watcher:
373+
dependency: transitive
374+
description:
375+
name: watcher
376+
sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8"
377+
url: "https://pub.dev"
378+
source: hosted
379+
version: "1.1.0"
380+
web_socket_channel:
381+
dependency: transitive
382+
description:
383+
name: web_socket_channel
384+
sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b
385+
url: "https://pub.dev"
386+
source: hosted
387+
version: "2.4.0"
388+
webkit_inspection_protocol:
389+
dependency: transitive
390+
description:
391+
name: webkit_inspection_protocol
392+
sha256: "67d3a8b6c79e1987d19d848b0892e582dbb0c66c57cc1fef58a177dd2aa2823d"
393+
url: "https://pub.dev"
394+
source: hosted
395+
version: "1.2.0"
156396
yaml:
157397
dependency: transitive
158398
description:

packages/shell_executor/pubspec.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: shell_executor
22
description: A simple shell commands executor.
3-
version: 0.1.3
3+
version: 0.1.4
44
homepage: https://distributor.leanflutter.org
55
repository: https://github.com/leanflutter/flutter_distributor/tree/main/packages/shell_executor
66

@@ -9,3 +9,4 @@ environment:
99

1010
dev_dependencies:
1111
dependency_validator: ^3.0.0
12+
test: ^1.23.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import 'package:shell_executor/src/utils/path_expansion.dart';
2+
import 'package:test/test.dart';
3+
4+
void main() {
5+
Map<String, String> environment = {
6+
'HOME': '/home/root',
7+
};
8+
group('pathExpansion', () {
9+
test('~/Documents', () {
10+
final path = pathExpansion('~/Documents', environment);
11+
expect(path, '/home/root/Documents');
12+
});
13+
test('\$HOME/Documents', () {
14+
final r = pathExpansion('\$HOME/Documents', environment);
15+
expect(r, '/home/root/Documents');
16+
});
17+
test('\${HOME}/Documents', () {
18+
final r = pathExpansion('\${HOME}/Documents', environment);
19+
expect(r, '/home/root/Documents');
20+
});
21+
});
22+
}

0 commit comments

Comments
 (0)