Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
🌱 Add get node status command
Browse files Browse the repository at this point in the history
  • Loading branch information
shuse2 committed May 30, 2018
1 parent 0063a62 commit 2447b97
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
64 changes: 64 additions & 0 deletions src/commands/get_node_status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* LiskHQ/lisk-commander
* Copyright © 2017–2018 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
import { createCommand } from '../utils/helpers';
import getAPIClient from '../utils/api';

const description = `Gets information about a node.
Examples:
- get node status
- get node status --forging
`;

const forgingDescription = `Additionally provides information about forging status
Examples:
- --forging
`;

export const actionCreator = () => async ({ options }) => {
const client = getAPIClient();

return Promise.all([client.node.getConstants(), client.node.getStatus()])
.then(([constantsResponse, statusResponse]) =>
Object.assign({}, constantsResponse.data, statusResponse.data),
)
.then(nodeStatus => {
if (options.forging) {
return client.node
.getForgingStatus()
.then(forgingResponse =>
Object.assign({}, nodeStatus, {
forgingStatus: forgingResponse.data,
}),
)
.catch(error =>
Object.assign({}, nodeStatus, { forgingStatus: error.message }),
);
}
return nodeStatus;
});
};

const get = createCommand({
command: 'get node status',
description,
actionCreator,
options: [['--forging', forgingDescription]],
errorPrefix: 'Could not get node status',
});

export default get;
7 changes: 6 additions & 1 deletion src/utils/tablify.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ const getKeyValueObject = object => {
.join('\n');
};

const getKeyValueArray = array =>
array && array.length > 0 && typeof array[0] !== 'object'
? array.join('\n')
: array.map(element => getKeyValueObject(element)).join('\n');

const addValuesToTable = (table, data) => {
Object.entries(data).forEach(([key, values]) => {
const strValue = Array.isArray(values)
? values.join('\n')
? getKeyValueArray(values)
: getKeyValueObject(values);
table.push({ [key]: strValue });
});
Expand Down

0 comments on commit 2447b97

Please sign in to comment.