Skip to content

Commit

Permalink
Merge pull request #88 from oceanprotocol/issue-42-args-lib
Browse files Browse the repository at this point in the history
updating cli to use command cli library
  • Loading branch information
jamiehewitt15 authored Feb 19, 2025
2 parents 72c2f05 + 010dfd8 commit 1cae4d4
Show file tree
Hide file tree
Showing 6 changed files with 507 additions and 159 deletions.
184 changes: 184 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,190 @@ Make sure to update chainId from the assets from `metadata` folder.
npm run cli publish metadata/simpleDownloadDataset.json
```

### Command Usage

The Ocean CLI supports flexible argument ordering. You can supply arguments using:
- **Positional Arguments** (traditional style): Must follow the defined order.
- **Named Options**: Can be provided in any order. These options include flags like `--did`, `--file`, etc.

#### General Format

```bash
npm run cli <command> [options] <arguments>
```

#### Help Commands

- **General help:**
`npm run cli --help` or `npm run cli -h`

- **Command-specific help:**
`npm run cli help <command>`

#### Examples

**Get DDO:**

- **Positional:**
`npm run cli getDDO did:op:123`

- **Named Option:**
`npm run cli getDDO --did did:op:123`

---

**Publish:**

- **Positional:**
`npm run cli publish metadata.json`

- **Named Options:**
`npm run cli publish --file metadata.json`
With encryption disabled:
`npm run cli publish --file metadata.json --encrypt false`
(Note: `--file` and `--encrypt` can be in any order.)

---

**Publish Algorithm:**

- **Positional:**
`npm run cli publishAlgo algorithm.json`

- **Named Options:**
`npm run cli publishAlgo --file algorithm.json`
With encryption disabled:
`npm run cli publishAlgo --encrypt false --file algorithm.json`

---

**Edit Asset:**

- **Positional:**
`npm run cli editAsset did:op:123 metadata.json`

- **Named Options:**
`npm run cli editAsset --did did:op:123 --file metadata.json`
(The flags can be provided in any order, for example:
`npm run cli editAsset --file metadata.json --did did:op:123`)

---

**Download:**

- **Positional:**
`npm run cli download did:op:123 ./custom-folder`

- **Named Options:**
`npm run cli download --did did:op:123 --folder ./custom-folder`
(Order of `--did` and `--folder` does not matter.)

---

**Start Compute:**

- **Positional:**
`npm run cli startCompute did1,did2 algoDid env1`

- **Named Options:**
`npm run cli startCompute --datasets did1,did2 --algo algoDid --env env1`
(Options can be provided in any order.)

---

**Stop Compute:**

- **Positional:**
`npm run cli stopCompute did:op:123 job-123`

- **Named Options:**
`npm run cli stopCompute --dataset did:op:123 --job job-123`
(Optionally, you can also provide an agreement ID using `--agreement`.)

---

**Get Job Status:**

- **Positional:**
`npm run cli getJobStatus did:op:123 job-123`

- **Named Options:**
`npm run cli getJobStatus --dataset did:op:123 --job job-123`
(Optionally, an agreement ID may be provided.)

---

**Download Job Results:**

- **Positional:**
`npm run cli downloadJobResults job-123 0 ./results`

- **Named Options:**
`npm run cli downloadJobResults --job job-123 --index 0 --folder ./results`

---

**Mint Ocean:**

- **Positional:**
`npm run cli mintOcean`
(No arguments are required for this command.)

---

#### Available Named Options Per Command

- **getDDO:**
`-d, --did <did>`

- **publish:**
`-f, --file <metadataFile>`
`-e, --encrypt [boolean]` (Default: `true`)

- **publishAlgo:**
`-f, --file <metadataFile>`
`-e, --encrypt [boolean]` (Default: `true`)

- **editAsset:**
`-d, --did <datasetDid>`
`-f, --file <metadataFile>`
`-e, --encrypt [boolean]` (Default: `true`)

- **download:**
`-d, --did <did>`
`-f, --folder [destinationFolder]` (Default: `.`)

- **startCompute:**
`-d, --datasets <datasetDids>`
`-a, --algo <algoDid>`
`-e, --env <computeEnvId>`

- **stopCompute:**
`-d, --dataset <datasetDid>`
`-j, --job <jobId>`
`-a, --agreement [agreementId]`

- **getJobStatus:**
`-d, --dataset <datasetDid>`
`-j, --job <jobId>`
`-a, --agreement [agreementId]`

- **downloadJobResults:**
`-j, --job <jobId>`
`-i, --index <index>`
`-f, --folder [destinationFolder]`

- **mintOcean:**
No options/arguments required.

---

**Note:**
- When using **named options**, you can write them in any order.
- When relying on **positional arguments**, ensure they follow the exact order as defined by the command.

This flexible approach lets you use the style that best suits your workflow while remaining fully backwards compatible.

## 🏛 License

```
Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@oasisprotocol/sapphire-paratime": "^1.3.2",
"@oceanprotocol/contracts": "^2.0.4",
"@oceanprotocol/lib": "^3.4.6",
"commander": "^13.1.0",
"cross-fetch": "^3.1.5",
"crypto-js": "^4.1.1",
"decimal.js": "^10.4.1",
Expand Down
Loading

0 comments on commit 1cae4d4

Please sign in to comment.