Skip to content

Commit eb1a228

Browse files
authored
Added guidelines for using commands in package file. (#61)
1 parent a5b1890 commit eb1a228

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

guidelines/index.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ This is an array of scripts that will be installed into a project.
7777
"scripts": ["script.sh"]
7878
```
7979

80-
### files
80+
### files (optional)
8181

82-
This is an array of files that will be installed into a project.
82+
This is an array of non-script files that will be installed into a project.
8383

8484
```json
8585
"files": ["bar.txt", "foo.txt"]
@@ -105,6 +105,23 @@ This is a hash of dependencies only needed during development. Like the `depend
105105
}
106106
```
107107

108+
### commands (optional)
109+
110+
This is a hash of commands. The keys are the names of the commands and the values are the commands to execute in a shell. The commands can be called from the command line with `bpkg run` followed by the command name.
111+
112+
```json
113+
"commands": {
114+
"say-hello": "echo \"Hello $1\""
115+
}
116+
```
117+
118+
The commands are run with `eval`, which runs the command as if on the command line. Commands can contain environment variables, and supports [shell features] (including *[special parameters]* and *[shell expansions]*). Passed parameters (on the command line after the command name) can be accessed in the command by using `$@` or `$1`.
119+
120+
```bash
121+
$ bpkg run say-hello "Bash Package Manager"
122+
Hello Bash Package Manager
123+
```
124+
108125
## Packaging best practices
109126

110127
These are guidelines that we strongly encourage developers to follow.
@@ -133,3 +150,6 @@ $ my_script some more args --blah
133150
```
134151

135152
[json]: http://json.org/example
153+
[shell features]: https://www.gnu.org/software/bash/manual/html_node/Basic-Shell-Features.html
154+
[special parameters]: https://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html
155+
[shell expansions]: https://www.gnu.org/software/bash/manual/html_node/Shell-Expansions.html

0 commit comments

Comments
 (0)