Skip to content

Commit

Permalink
Remove private and publish args
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed May 15, 2024
1 parent 2cca0f6 commit ac6703a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 58 deletions.
9 changes: 0 additions & 9 deletions src/cli/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ module.exports = ({ commandProcessor, root }) => {
commandProcessor.createCommand(root, 'publish', 'Publish an event to the cloud', {
params: '<event> [data]',
options: {
'private': {
boolean: true,
default: true,
description: 'Publish to the private stream'
},
'public': {
boolean: true,
description: 'Publish to the public stream'
},
'product': {
description: 'Publish to the given Product ID or Slug\'s stream'
}
Expand Down
6 changes: 1 addition & 5 deletions src/cli/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ describe('Publish Command-Line Interface', () => {
});

it('Parses options', () => {
const argv = commandProcessor.parse(root, ['publish', 'my-event', '--private', '--public', '--product', '12345']);
const argv = commandProcessor.parse(root, ['publish', 'my-event', '--product', '12345']);
expect(argv.clierror).to.equal(undefined);
expect(argv.params).to.eql({ event: 'my-event', data: undefined });
expect(argv.private).to.equal(true);
expect(argv.public).to.equal(true);
expect(argv.product).to.equal('12345');
});

Expand All @@ -56,8 +54,6 @@ describe('Publish Command-Line Interface', () => {
'Usage: particle publish [options] <event> [data]',
'',
'Options:',
' --private Publish to the private stream [boolean] [default: true]',
' --public Publish to the public stream [boolean]',
' --product Publish to the given Product ID or Slug\'s stream [string]',
'',
'Examples:',
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ module.exports = class ParticleApi {
);
}

publishEvent(name, data, isPrivate, product){
publishEvent(name, data, product){
return this._wrap(
this.api.publishEvent({
name,
data,
product,
isPrivate,
isPrivate: true,
auth: this.accessToken
})
);
Expand Down
8 changes: 3 additions & 5 deletions src/cmd/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ module.exports = class PublishCommand extends CLICommandBase {
super(...args);
}

publishEvent({ private: isPrivate, public: isPublic, product, params: { event, data } }){
isPrivate = (isPublic && !product) ? false : isPrivate; // `isPrivate: true` by default see: src/cli/publish.js
const visibility = isPrivate ? 'private' : 'public';
let epilogue = `${visibility} event: ${event}`;
publishEvent({ product, params: { event, data } }){
let epilogue = `private event: ${event}`;

if (product){
epilogue += ` to product: ${product}`;
}

const publishEvent = createAPI().publishEvent(event, data, isPrivate, product);
const publishEvent = createAPI().publishEvent(event, data, product);
return this.ui.showBusySpinnerUntilResolved(`Publishing ${epilogue}`, publishEvent)
.then(() => this.ui.stdout.write(`Published ${epilogue}${os.EOL}${os.EOL}`))
.catch(error => {
Expand Down
10 changes: 3 additions & 7 deletions src/lib/api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ module.exports = class ApiClient {
});
}

publishEvent(eventName, data, setPrivate){
publishEvent(eventName, data){
const { request, _access_token: token } = this;
let self = this;

Expand All @@ -959,7 +959,7 @@ module.exports = class ApiClient {
name: eventName,
data: data,
access_token: token,
private: setPrivate
private: true
}
};

Expand All @@ -977,11 +977,7 @@ module.exports = class ApiClient {
return reject(body);
}

console.log(
`Published ${setPrivate ? 'private' : 'public'}`,
'event:',
eventName
);
console.log(`Published private event: ${eventName}`);
console.log('');
resolve(body);
});
Expand Down
31 changes: 1 addition & 30 deletions test/e2e/publish.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ describe('Publish Commands', () => {
'',
'Options:',
' --private Publish to the private stream [boolean] [default: true]',
' --public Publish to the public stream [boolean]',
' --product Publish to the given Product ID or Slug\'s stream [string]',
'',
'Examples:',
' particle publish temp 25.0 Publish a temp event to your private event stream',
Expand Down Expand Up @@ -66,24 +64,6 @@ describe('Publish Commands', () => {
expect(exitCode).to.equal(0);
});

it('Publishes a private event', async () => {
const args = ['publish', eventName, '--private'];
const { stdout, stderr, exitCode } = await cli.run(args);

expect(stdout).to.include(`Published private event: ${eventName}${os.EOL}`);
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

it('Publishes a public event', async () => {
const args = ['publish', eventName, '--public'];
const { stdout, stderr, exitCode } = await cli.run(args);

expect(stdout).to.include(`Published public event: ${eventName}${os.EOL}`);
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

it('Publishes a product event', async () => {
const args = ['publish', eventName, '--product', PRODUCT_01_ID];
const { stdout, stderr, exitCode } = await cli.run(args);
Expand All @@ -94,16 +74,7 @@ describe('Publish Commands', () => {
});

it('Publishes a private product event', async () => {
const args = ['publish', eventName, '--product', PRODUCT_01_ID, '--private'];
const { stdout, stderr, exitCode } = await cli.run(args);

expect(stdout).to.include(`Published private event: ${eventName} to product: ${PRODUCT_01_ID}${os.EOL}`);
expect(stderr).to.equal('');
expect(exitCode).to.equal(0);
});

it('Ignores `--public` flag when publishing a product event', async () => {
const args = ['publish', eventName, '--product', PRODUCT_01_ID, '--public'];
const args = ['publish', eventName, '--product', PRODUCT_01_ID];
const { stdout, stderr, exitCode } = await cli.run(args);

expect(stdout).to.include(`Published private event: ${eventName} to product: ${PRODUCT_01_ID}${os.EOL}`);
Expand Down

0 comments on commit ac6703a

Please sign in to comment.