|
| 1 | +--- |
| 2 | +title: Command line interface |
| 3 | +subTitle: |
| 4 | +currentMenu: cli |
| 5 | +--- |
| 6 | + |
| 7 | +Discovery comes with a CLI (command line interface). |
| 8 | + |
| 9 | +You can use the CLI commands to: |
| 10 | + |
| 11 | +- debug what is happening |
| 12 | +- modify your local `discovery.json` |
| 13 | +- hook third party tools (like Gulp or Webpack) |
| 14 | + |
| 15 | +Actually, *discovery* is adding a set of commands to composer. |
| 16 | + |
| 17 | +## Listing asset types |
| 18 | + |
| 19 | +```bash |
| 20 | +$ composer discovery:list |
| 21 | +``` |
| 22 | + |
| 23 | +will output the list of asset types and the list of assets in each asset-type: |
| 24 | + |
| 25 | +``` |
| 26 | +my-asset-type-1: |
| 27 | + assetA |
| 28 | + assetB |
| 29 | + assetC |
| 30 | +my-asset-type-2: |
| 31 | + assetD |
| 32 | +``` |
| 33 | + |
| 34 | +You can also ask for the assets of a given asset-type: |
| 35 | + |
| 36 | +```bash |
| 37 | +$ composer discovery:list my-asset-type-2 |
| 38 | +``` |
| 39 | + |
| 40 | +will output: |
| 41 | + |
| 42 | +``` |
| 43 | +my-asset-type-2: |
| 44 | + assetD |
| 45 | +``` |
| 46 | + |
| 47 | +Finally, if you need more data, you can use the JSON output (maybe you want to output the metadata associated to each asset or you want to integrate the output with a third party tool). |
| 48 | + |
| 49 | +```bash |
| 50 | +$ composer discovery:list --format=json |
| 51 | +``` |
| 52 | + |
| 53 | +## Dumping the Discovery files |
| 54 | + |
| 55 | +Discovery is "dumping" a set of files that enable extremely quick access to the assets. **If you change manually a `discovery.json` file in your project, you will need to regenerate those files.** You can do this with the `discovery:dump` command: |
| 56 | + |
| 57 | +```bash |
| 58 | +$ composer discovery:dump |
| 59 | +``` |
| 60 | + |
| 61 | +## Adding an asset |
| 62 | + |
| 63 | +You can add an asset to an asset type using the `discovery:add` command: |
| 64 | + |
| 65 | +```bash |
| 66 | +$ composer discovery:add "my-asset-type" "my-asset-value" |
| 67 | +``` |
| 68 | + |
| 69 | +The asset is added to the `discovery.json` file at the root of your project. |
| 70 | + |
| 71 | +You can also set the priority while adding an asset: |
| 72 | + |
| 73 | +```bash |
| 74 | +$ composer discovery:add "my-asset-type" "my-asset-value" --priority=42 |
| 75 | +``` |
| 76 | + |
| 77 | +Note: currently, discovery does not support adding metadata via the command line. You will need to edit the `discovery.json` file manually to add metadata to an asset. |
| 78 | + |
| 79 | +## Removing an asset |
| 80 | + |
| 81 | +You can remove an asset from a project using the `discovery:remove` command: |
| 82 | + |
| 83 | +```bash |
| 84 | +$ composer discovery:remove "my-asset-type" "my-asset-value" |
| 85 | +``` |
| 86 | + |
| 87 | +The asset is removed from the `discovery.json` file at the root of your project or a "remove" action is added in the `discovery.json` file at the root of your project (if the asset is defined in a dependency). |
0 commit comments