Skip to content

Commit

Permalink
[shell_executor] add pathExpansion utility method.
Browse files Browse the repository at this point in the history
  • Loading branch information
lijy91 committed May 31, 2023
1 parent 42ea1fa commit 4c7ce87
Show file tree
Hide file tree
Showing 6 changed files with 289 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/shell_executor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.4

* add `pathExpansion` utility method.

## 0.1.3

* Update dart sdk version to ">=2.16.0 <4.0.0"
Expand Down
1 change: 1 addition & 0 deletions packages/shell_executor/lib/shell_executor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ library shell_executor;

export 'src/command.dart';
export 'src/shell_executor.dart';
export 'src/utils/path_expansion.dart';
20 changes: 20 additions & 0 deletions packages/shell_executor/lib/src/utils/path_expansion.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
String pathExpansion(
String path, [
Map<String, String> environment = const {},
]) {
if (path.startsWith('~/')) {
final home = environment['HOME'] ?? environment['USERPROFILE'];
path = '$home${path.substring(1)}';
}

final matches = [
...RegExp(r'\$(\w+)').allMatches(path),
...RegExp(r'\$\{(\w+)\}').allMatches(path)
];
for (final match in matches) {
final envName = match.group(1);
final envValue = environment[envName];
path = path.replaceFirst(match.group(0)!, envValue ?? '');
}
return path;
}
240 changes: 240 additions & 0 deletions packages/shell_executor/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
_fe_analyzer_shared:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: ae92f5d747aee634b87f89d9946000c2de774be1d6ac3e58268224348cd0101a
url: "https://pub.dev"
source: hosted
version: "61.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
sha256: ea3d8652bda62982addfd92fdc2d0214e5f82e43325104990d4f4c4a2a313562
url: "https://pub.dev"
source: hosted
version: "5.13.0"
args:
dependency: transitive
description:
Expand All @@ -17,6 +33,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.11.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
build_config:
dependency: transitive
description:
Expand All @@ -41,6 +65,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.17.2"
convert:
dependency: transitive
description:
name: convert
sha256: "0f08b14755d163f6e2134cb58222dd25ea2a2ee8a195e53983d57c075324d592"
url: "https://pub.dev"
source: hosted
version: "3.1.1"
coverage:
dependency: transitive
description:
name: coverage
sha256: "2fb815080e44a09b85e0f2ca8a820b15053982b2e714b59267719e8a9ff17097"
url: "https://pub.dev"
source: hosted
version: "1.6.3"
crypto:
dependency: transitive
description:
name: crypto
sha256: ff625774173754681d66daaf4a448684fb04b78f902da9cb3d308c19cc5e8bab
url: "https://pub.dev"
source: hosted
version: "3.0.3"
dependency_validator:
dependency: "direct dev"
description:
Expand All @@ -57,6 +105,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "7.0.0"
frontend_server_client:
dependency: transitive
description:
name: frontend_server_client
sha256: "408e3ca148b31c20282ad6f37ebfa6f4bdc8fede5b74bc2f08d9d92b55db3612"
url: "https://pub.dev"
source: hosted
version: "3.2.0"
glob:
dependency: transitive
description:
Expand All @@ -65,6 +121,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.2"
http_multi_server:
dependency: transitive
description:
name: http_multi_server
sha256: "97486f20f9c2f7be8f514851703d0119c3596d14ea63227af6f7a481ef2b2f8b"
url: "https://pub.dev"
source: hosted
version: "3.2.1"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
io:
dependency: transitive
description:
Expand All @@ -73,6 +145,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.4"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
json_annotation:
dependency: transitive
description:
Expand All @@ -89,6 +169,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.0"
matcher:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.16"
meta:
dependency: transitive
description:
Expand All @@ -97,6 +185,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.1"
mime:
dependency: transitive
description:
name: mime
sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e
url: "https://pub.dev"
source: hosted
version: "1.0.4"
node_preamble:
dependency: transitive
description:
name: node_preamble
sha256: "6e7eac89047ab8a8d26cf16127b5ed26de65209847630400f9aefd7cd5c730db"
url: "https://pub.dev"
source: hosted
version: "2.0.2"
package_config:
dependency: transitive
description:
Expand All @@ -113,6 +217,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.8.3"
pool:
dependency: transitive
description:
name: pool
sha256: "20fe868b6314b322ea036ba325e6fc0711a22948856475e2c2b6306e8ab39c2a"
url: "https://pub.dev"
source: hosted
version: "1.5.1"
pub_semver:
dependency: transitive
description:
Expand All @@ -129,6 +241,54 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.3"
shelf:
dependency: transitive
description:
name: shelf
sha256: ad29c505aee705f41a4d8963641f91ac4cee3c8fad5947e033390a7bd8180fa4
url: "https://pub.dev"
source: hosted
version: "1.4.1"
shelf_packages_handler:
dependency: transitive
description:
name: shelf_packages_handler
sha256: "89f967eca29607c933ba9571d838be31d67f53f6e4ee15147d5dc2934fee1b1e"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
shelf_static:
dependency: transitive
description:
name: shelf_static
sha256: a41d3f53c4adf0f57480578c1d61d90342cd617de7fc8077b1304643c2d85c1e
url: "https://pub.dev"
source: hosted
version: "1.1.2"
shelf_web_socket:
dependency: transitive
description:
name: shelf_web_socket
sha256: "9ca081be41c60190ebcb4766b2486a7d50261db7bd0f5d9615f2d653637a84c1"
url: "https://pub.dev"
source: hosted
version: "1.0.4"
source_map_stack_trace:
dependency: transitive
description:
name: source_map_stack_trace
sha256: "84cf769ad83aa6bb61e0aa5a18e53aea683395f196a6f39c4c881fb90ed4f7ae"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
source_maps:
dependency: transitive
description:
name: source_maps
sha256: "708b3f6b97248e5781f493b765c3337db11c5d2c81c3094f10904bfa8004c703"
url: "https://pub.dev"
source: hosted
version: "0.10.12"
source_span:
dependency: transitive
description:
Expand All @@ -137,6 +297,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
url: "https://pub.dev"
source: hosted
version: "1.11.0"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
string_scanner:
dependency: transitive
description:
Expand All @@ -153,6 +329,70 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.2.1"
test:
dependency: "direct dev"
description:
name: test
sha256: "13b41f318e2a5751c3169137103b60c584297353d4b1761b66029bae6411fe46"
url: "https://pub.dev"
source: hosted
version: "1.24.3"
test_api:
dependency: transitive
description:
name: test_api
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
test_core:
dependency: transitive
description:
name: test_core
sha256: "99806e9e6d95c7b059b7a0fc08f07fc53fabe54a829497f0d9676299f1e8637e"
url: "https://pub.dev"
source: hosted
version: "0.5.3"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
url: "https://pub.dev"
source: hosted
version: "1.3.2"
vm_service:
dependency: transitive
description:
name: vm_service
sha256: f3743ca475e0c9ef71df4ba15eb2d7684eecd5c8ba20a462462e4e8b561b2e11
url: "https://pub.dev"
source: hosted
version: "11.6.0"
watcher:
dependency: transitive
description:
name: watcher
sha256: "3d2ad6751b3c16cf07c7fca317a1413b3f26530319181b37e3b9039b84fc01d8"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web_socket_channel:
dependency: transitive
description:
name: web_socket_channel
sha256: d88238e5eac9a42bb43ca4e721edba3c08c6354d4a53063afaa568516217621b
url: "https://pub.dev"
source: hosted
version: "2.4.0"
webkit_inspection_protocol:
dependency: transitive
description:
name: webkit_inspection_protocol
sha256: "67d3a8b6c79e1987d19d848b0892e582dbb0c66c57cc1fef58a177dd2aa2823d"
url: "https://pub.dev"
source: hosted
version: "1.2.0"
yaml:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion packages/shell_executor/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: shell_executor
description: A simple shell commands executor.
version: 0.1.3
version: 0.1.4
homepage: https://distributor.leanflutter.org
repository: https://github.com/leanflutter/flutter_distributor/tree/main/packages/shell_executor

Expand All @@ -9,3 +9,4 @@ environment:

dev_dependencies:
dependency_validator: ^3.0.0
test: ^1.23.1
22 changes: 22 additions & 0 deletions packages/shell_executor/test/src/utils/path_expansion_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:shell_executor/src/utils/path_expansion.dart';
import 'package:test/test.dart';

void main() {
Map<String, String> environment = {
'HOME': '/home/root',
};
group('pathExpansion', () {
test('~/Documents', () {
final path = pathExpansion('~/Documents', environment);
expect(path, '/home/root/Documents');
});
test('\$HOME/Documents', () {
final r = pathExpansion('\$HOME/Documents', environment);
expect(r, '/home/root/Documents');
});
test('\${HOME}/Documents', () {
final r = pathExpansion('\${HOME}/Documents', environment);
expect(r, '/home/root/Documents');
});
});
}

0 comments on commit 4c7ce87

Please sign in to comment.