Skip to content

Commit

Permalink
feat(xo-cli): support REST PUT method
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-f committed Nov 23, 2023
1 parent aeb22d6 commit 0d96d59
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- @xen-orchestra/cr-seed-cli major
- @xen-orchestra/vmware-explorer patch
- xen-api major
- xo-cli minor
- xo-server minor
- xo-server-netbox minor
- xo-vmdk-to-vhd patch
Expand Down
13 changes: 13 additions & 0 deletions packages/xo-cli/.USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Usage:
Examples:
xo-cli rest del tasks/<task id>
xo-cli rest del vms/<vm id>/tags/<tag>
xo-cli rest get <collection> [fields=<fields>] [filter=<filter>] [limit=<limit>]
List objects in a REST API collection.
Expand Down Expand Up @@ -122,6 +123,18 @@ Usage:
Examples:
xo-cli rest post tasks/<task id>/actions/abort
xo-cli rest post vms/<VM UUID>/actions/snapshot name_label='My snapshot'
xo-cli rest put <collection>/<item id> <name>=<value>...
Put a item in a collection
<collection>/<item id>
Full path of the item to add
<name>=<value>...
Properties of the item
Examples:
xo-cli rest put vms/<vm id>/tags/<tag>
```

#### Register your XO instance
Expand Down
13 changes: 13 additions & 0 deletions packages/xo-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Usage:
Examples:
xo-cli rest del tasks/<task id>
xo-cli rest del vms/<vm id>/tags/<tag>
xo-cli rest get <collection> [fields=<fields>] [filter=<filter>] [limit=<limit>]
List objects in a REST API collection.
Expand Down Expand Up @@ -140,6 +141,18 @@ Usage:
Examples:
xo-cli rest post tasks/<task id>/actions/abort
xo-cli rest post vms/<VM UUID>/actions/snapshot name_label='My snapshot'
xo-cli rest put <collection>/<item id> <name>=<value>...
Put a item in a collection
<collection>/<item id>
Full path of the item to add
<name>=<value>...
Properties of the item
Examples:
xo-cli rest put vms/<vm id>/tags/<tag>
```

#### Register your XO instance
Expand Down
13 changes: 13 additions & 0 deletions packages/xo-cli/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ const help = wrap(
Examples:
$name rest del tasks/<task id>
$name rest del vms/<vm id>/tags/<tag>
$name rest get <collection> [fields=<fields>] [filter=<filter>] [limit=<limit>]
List objects in a REST API collection.
Expand Down Expand Up @@ -347,6 +348,18 @@ const help = wrap(
$name rest post tasks/<task id>/actions/abort
$name rest post vms/<VM UUID>/actions/snapshot name_label='My snapshot'
$name rest put <collection>/<item id> <name>=<value>...
Put a item in a collection
<collection>/<item id>
Full path of the item to add
<name>=<value>...
Properties of the item
Examples:
$name rest put vms/<vm id>/tags/<tag>
$name v$version`.replace(/<([^>]+)>|\$(\w+)/g, function (_, arg, key) {
if (arg) {
return '<' + chalk.yellow(arg) + '>'
Expand Down
12 changes: 12 additions & 0 deletions packages/xo-cli/rest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ const COMMANDS = {

return stripPrefix(await response.text())
},

async put([path, ...params]) {
const response = await this.exec(path, {
body: JSON.stringify(parseParams(params)),
headers: {
'content-type': 'application/json',
},
method: 'PUT',
})

return stripPrefix(await response.text())
},
}

export async function rest(args) {
Expand Down

0 comments on commit 0d96d59

Please sign in to comment.