Chromium Code Reviews| Index: sdk/lib/_internal/pub/lib/src/pubspec.dart |
| diff --git a/sdk/lib/_internal/pub/lib/src/pubspec.dart b/sdk/lib/_internal/pub/lib/src/pubspec.dart |
| index 7aa573503dbd3d1127a07f07703530f8d6c678e7..7d43b039d3a06dbcfbaa41002b1afab330f3718a 100644 |
| --- a/sdk/lib/_internal/pub/lib/src/pubspec.dart |
| +++ b/sdk/lib/_internal/pub/lib/src/pubspec.dart |
| @@ -239,6 +239,59 @@ class Pubspec { |
| bool _parsedPublishTo = false; |
| String _publishTo; |
| + /// The executables that should be placed on the user's PATH when this |
|
nweiz
2014/09/15 22:57:18
"placed on the user's PATH" isn't really accurate,
|
| + /// package is globally activated. |
| + /// |
| + /// It is a map of strings to string. Each key is the name of the command |
| + /// that will be placed on the user's PATH. The value is the name of the |
| + /// .dart script (without extension) in the package's `bin` directory that |
| + /// should be run for that command. Both key and value must be "simple" |
| + /// strings: alphanumerics, underscores and hypens only. If a value is |
|
nweiz
2014/09/15 22:57:18
We don't otherwise restrict the name of executable
Bob Nystrom
2014/09/17 21:34:35
The OS implicitly prevents you from putting path s
nweiz
2014/09/17 22:58:26
I don't mind the restrictions on the binstub name,
Bob Nystrom
2014/09/18 19:17:52
Done.
|
| + /// omitted, it is inferred to use the same name as the key. |
| + Map<String, String> get executables { |
| + if (_executables != null) return _executables; |
| + |
| + var yaml = fields['executables']; |
| + if (yaml == null) { |
| + _executables = {}; |
| + return _executables; |
| + } |
| + |
| + if (yaml is! Map) { |
| + _error('"executables" field must be a map.', |
| + fields.nodes['executables'].span); |
| + } |
| + |
| + yaml.nodes.forEach((key, value) { |
| + // Don't allow path separators or other stuff meaningful to the shell. |
| + validateName(name, description) { |
| + final validName = new RegExp(r"^[a-zA-Z0-9_-]+$"); |
| + if (!validName.hasMatch(name.value)) { |
| + _error('"executables" $description may only contain letters, ' |
| + 'numbers, hyphens and underscores.', name.span); |
| + } |
| + } |
| + |
| + if (key.value is! String) { |
| + _error('"executables" keys must be strings.', key.span); |
| + } |
| + |
| + validateName(key, "keys"); |
| + |
| + if (value.value == null) return; |
| + |
| + if (value.value is! String) { |
| + _error('"executables" values must be strings or null.', value.span); |
| + } |
| + |
| + validateName(value, "values"); |
| + }); |
| + |
| + _executables = yaml; |
| + return _executables; |
| + } |
| + Map<String, String> _executables; |
| + |
| /// Whether the package is private and cannot be published. |
| /// |
| /// This is specified in the pubspec by setting "publish_to" to "none". |