Skip to content

Commit

Permalink
cli: cloud: Add examples to the commands
Browse files Browse the repository at this point in the history
  • Loading branch information
João Neto authored and netoax committed Jul 2, 2021
1 parent c3e2f99 commit 267000f
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 17 deletions.
8 changes: 7 additions & 1 deletion src/cmds/cloud/createThing.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ yargs
_yargs
.options(options.amqp)
.options(options.http)
.options(options.basic);
.options(options.basic)
.example([
[
'$0 create-thing 0c2958525df5dc3c thing-example --amqp-server api.fog <user-token>',
'Create a new thing with id `0c2958525df5dc3c` and name `thing-example`.',
],
]);
},
handler: async (args) => {
try {
Expand Down
14 changes: 12 additions & 2 deletions src/cmds/cloud/createToken.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-console */
/* eslint-disable no-console, no-multi-str */
import yargs from 'yargs';
import chalk from 'chalk';
import { Authenticator } from '@cesarbr/knot-cloud-sdk-js';
Expand All @@ -18,7 +18,17 @@ yargs.command({
command: 'create-token <email> <credential> <type>',
desc: 'Create a new user or app token',
builder: (_yargs) => {
_yargs.options(options.http);
_yargs.options(options.http).example([
[
'$0 create-token [email protected] strong@password! user --http-server api.fog',
'Create a new `user` token for the `[email protected]` user.',
],
[
'$0 create-token [email protected] <user-token> app --http-server api.fog',
'Create a new `app` token for the `[email protected]` user. The \
`user` token previously created must by passed as password for creating an `app` token.',
],
]);
},
handler: async (args) => {
try {
Expand Down
8 changes: 7 additions & 1 deletion src/cmds/cloud/createUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ yargs.command({
desc: 'Create a new user',
builder: (_yargs) => {
_yargs
.options(options.http);
.options(options.http)
.example([
[
'$0 create-user [email protected] strong@password! --http-server api.fog',
'Create a new user with e-mail `[email protected]` and password `strong@password!`',
],
]);
},
handler: async (args) => {
await createUser(args);
Expand Down
8 changes: 7 additions & 1 deletion src/cmds/cloud/deleteThing.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ yargs
.options(options.basic)
.positional('id', {
describe: 'Thing ID',
});
})
.example([
[
'$0 delete-thing 0c2958525df5dc3c --amqp-server api.fog --token <user-token>',
'Delete the thing `0c2958525df5dc3c`.',
],
]);
},
handler: async (args) => {
try {
Expand Down
8 changes: 7 additions & 1 deletion src/cmds/cloud/getData.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ yargs
})
.positional('sensor-id', {
describe: 'ID of the sensor to request the data',
});
})
.example([
[
'$0 get-data 0c2958525df5dc3c 0 --amqp-server api.fog --token <user-token>',
'Request a new data sample from the sensor `0` of thing `0c2958525df5dc3c`.',
],
]);
},
handler: async (args) => {
try {
Expand Down
8 changes: 7 additions & 1 deletion src/cmds/cloud/listThings.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ yargs
_yargs
.options(options.amqp)
.options(options.http)
.options(options.basic);
.options(options.basic)
.example([
[
'$0 list-things --amqp-server api.fog --token <user-token>',
'List the registered things.',
],
]);
},
handler: async (args) => {
try {
Expand Down
8 changes: 7 additions & 1 deletion src/cmds/cloud/publishData.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ yargs

return parseFloat(value);
},
});
})
.example([
[
'$0 publish-data 0c2958525df5dc3c 0 true --amqp-server api.fog --token <user-token>',
'Publish the value `true` as the sensor `0` on behalf of thing `0c2958525df5dc3c`.',
],
]);
},
handler: async (args) => {
try {
Expand Down
8 changes: 7 additions & 1 deletion src/cmds/cloud/setData.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ yargs

return parseFloat(value);
},
});
})
.example([
[
'$0 set-data 0c2958525df5dc3c 0 true --amqp-server api.fog --token <user-token>',
'Set a custom value `true` to the sensor `0` of thing `0c2958525df5dc3c`.',
],
]);
},
handler: async (args) => {
try {
Expand Down
11 changes: 9 additions & 2 deletions src/cmds/cloud/signin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-console */
/* eslint-disable no-console, no-multi-str */
import yargs from 'yargs';
import { Authenticator } from '@cesarbr/knot-cloud-sdk-js';
import os from 'os';
Expand Down Expand Up @@ -71,7 +71,14 @@ yargs.command({
.positional('password', {
describe: "User's password",
demandOption: true,
});
})
.example([
[
'$0 login --http-server api.fog',
'Login to the KNoT Cloud and create a token that will automatically be imported by the \
operations.',
],
]);
},
handler: async (args) => {
login(args);
Expand Down
3 changes: 2 additions & 1 deletion src/cmds/cloud/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ yargs
_yargs
.options(options.amqp)
.options(options.http)
.options(options.basic);
.options(options.basic)
.example([['$0 on data --http-server api.fog', 'Subscribe for receiving `data` events.']]);
},
handler: async (args) => {
try {
Expand Down
8 changes: 7 additions & 1 deletion src/cmds/cloud/updateConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ yargs
})
.options(options.amqp)
.options(options.http)
.options(options.basic);
.options(options.basic)
.example([
[
'$0 update-config <path>/config.json --amqp-server api.fog --token $USER_TOKEN',
'Update thing `9d3b2e867d483c80` sensor `0` config, which is imported from a JSON file.',
],
]);
},
handler: async (args) => {
try {
Expand Down
12 changes: 10 additions & 2 deletions src/cmds/cloud/updateConfigEvent.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-console */
/* eslint-disable no-console, no-multi-str */
import yargs from 'yargs';
import fs from 'fs';
import chalk from 'chalk';
Expand Down Expand Up @@ -87,7 +87,15 @@ yargs
describe: 'send data to the cloud if it is upper than this threshold',
demandOption: false,
default: 3000,
});
})
.example([
[
'$0 update-config-event 9d3b2e867d483c80 0 true 10 3000 4000 \
--amqp-server api.fog --token <user-token>',
'Update thing `9d3b2e867d483c80` sensor `0` config event with \
change=true, timeSec=10, lowerThreshold=3000, upperThreshold=4000',
],
]);
},
handler: async (args) => {
try {
Expand Down
12 changes: 10 additions & 2 deletions src/cmds/cloud/updateConfigSchema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-console */
/* eslint-disable no-console, no-multi-str */
import yargs from 'yargs';
import fs from 'fs';
import chalk from 'chalk';
Expand Down Expand Up @@ -86,7 +86,15 @@ yargs
describe: 'Sensor name',
demandOption: false,
default: 'Development Thing',
});
})
.example([
[
'$0 update-config-schema 9d3b2e867d483c80 0 2 0 65521 light-bulb \
--amqp-server api.fog --token $USER_TOKEN',
'Update thing `9d3b2e867d483c80` sensor `0` config schema with \
valueType=2, unit=0, typeId=65521, name=light-bulb',
],
]);
},
handler: async (args) => {
try {
Expand Down

0 comments on commit 267000f

Please sign in to comment.