sifive / wit

Workspace Integration Tool
Apache License 2.0
23 stars 13 forks source link

Add a 'foreach' command #213

Closed mmjconolly closed 4 years ago

mmjconolly commented 4 years ago

This is inspired by git submodule foreach [link]

$ wit foreach --help
usage: wit foreach [-h] [--quiet] [--continue-on-fail] cmd ...

Perform a command in each repository directory.
The repository list is created by reading records contained in 'wit-lock.json'.

If used, options --quiet and --continue-on-fail must be specified before the command.

The following environment variables are exposed to the command:
    WIT_REPO_NAME    repository name
    WIT_REPO_PATH    path to repository
    WIT_LOCK_SOURCE  inital source location of repository
    WIT_LOCK_COMMIT  commit recorded in lockfile, actual repository contents could be different
    WIT_WORKSPACE    path to root of wit workspace

positional arguments:
  cmd                 command to run in each repository
  args                arguments for the command

optional arguments:
  -h, --help          show this help message and exit
  --quiet             Supress printed lines indicating working repository
  --continue-on-fail  run the command in each repository regardless of
                      failures
$ wit foreach 'echo $WIT_REPO_NAME; git rev-parse HEAD'
Entering 'repo1'
repo1
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Entering 'repo2'
repo2
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
mmjconolly commented 4 years ago

Not sure how I closed this