Merge pull request #13 from p2p-org/dshackle-cli-tool
dshackle cli tool
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -11,4 +11,5 @@ testsetup/
|
||||
*.iws
|
||||
|
||||
# nix
|
||||
env
|
||||
env
|
||||
/dshackle-cli/node_modules/
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
||||
[submodule "emerald-java-client"]
|
||||
path = emerald-java-client
|
||||
url = git@github.com:p2p-org/emerald-java-client.git
|
||||
[submodule "dshackle-cli/grpc"]
|
||||
path = dshackle-cli/grpc
|
||||
url = https://github.com/emeraldpay/emerald-grpc.git
|
||||
|
||||
21
dshackle-cli/README.md
Normal file
21
dshackle-cli/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
# DSHACKLE CLI
|
||||
|
||||
A CLI tool to verify the [dshacle](https://github.com/emeraldpay/dshackle) installation.
|
||||
|
||||
## Usage
|
||||
```
|
||||
npx dchackle-cli-tool [-p|--print] <dshackle instance url>
|
||||
```
|
||||
|
||||
### Options
|
||||
-p | --print - will print the describe response as is
|
||||
|
||||
## Example
|
||||
|
||||
```
|
||||
> dchackle-cli-tool localhost:2449
|
||||
Connecting to: localhost:2449...
|
||||
Connected to localhost:2449
|
||||
CHAIN_ETHEREUM -> AVAIL_OK
|
||||
CHAIN_KOVAN -> AVAIL_OK
|
||||
```
|
||||
4
dshackle-cli/bin/dshackle-cli-tool
Executable file
4
dshackle-cli/bin/dshackle-cli-tool
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require = require('esm')(module /*, options*/);
|
||||
require('../src/cli').cli(process.argv);
|
||||
1
dshackle-cli/grpc
Submodule
1
dshackle-cli/grpc
Submodule
Submodule dshackle-cli/grpc added at 0d32b45d00
1783
dshackle-cli/package-lock.json
generated
Normal file
1783
dshackle-cli/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
dshackle-cli/package.json
Normal file
29
dshackle-cli/package.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "dshackle-cli-tool",
|
||||
"version": "1.0.4",
|
||||
"description": "",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"bin": {
|
||||
"@mfomenkov/dshackle-cli-tool": "bin/dshackle-cli-tool",
|
||||
"dshackle-cli-tool": "bin/dshackle-cli-tool"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@grpc/grpc-js": "^1.6.12",
|
||||
"@grpc/proto-loader": "^0.7.2",
|
||||
"arg": "^5.0.2",
|
||||
"cli-color": "^2.0.3",
|
||||
"esm": "^3.2.25",
|
||||
"inquirer": "^9.1.1"
|
||||
},
|
||||
"files": [
|
||||
"bin/",
|
||||
"src/",
|
||||
"grpc/"
|
||||
]
|
||||
}
|
||||
57
dshackle-cli/src/cli.js
Normal file
57
dshackle-cli/src/cli.js
Normal file
@@ -0,0 +1,57 @@
|
||||
import {describe} from "./grpc-clent";
|
||||
import arg from 'arg';
|
||||
import clc from "cli-color";
|
||||
import util from "util";
|
||||
|
||||
export function cli(args) {
|
||||
let opts = parseArgumentsIntoOptions(args);
|
||||
if (!opts.url) {
|
||||
console.log("Err: URL not specified!")
|
||||
return
|
||||
}
|
||||
describe(opts.url, (error, response) => {
|
||||
if (error) {
|
||||
console.error(clc.red('Connection to ' + opts.url + ' failed! [' + error.message + ']'));
|
||||
} else {
|
||||
console.error(clc.green('Connected to ', opts.url));
|
||||
if (opts.print) {
|
||||
console.log(util.inspect(response, false, null, true /* enable colors */));
|
||||
} else {
|
||||
response.chains.forEach(function (item) {
|
||||
var state = item.status.availability;
|
||||
|
||||
switch (state) {
|
||||
case 'AVAIL_OK':
|
||||
state = clc.green(state);
|
||||
break
|
||||
case 'AVAIL_UNKNOWN':
|
||||
case 'AVAIL_UNAVAILABLE':
|
||||
state = clc.red(state);
|
||||
break
|
||||
default:
|
||||
state = clc.yellow(state);
|
||||
}
|
||||
console.log(item.status.chain + ' -> ' + clc.bold(state))
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function parseArgumentsIntoOptions(rawArgs) {
|
||||
const args = arg(
|
||||
{
|
||||
'--print': Boolean,
|
||||
'-p': '--print'
|
||||
},
|
||||
{
|
||||
argv: rawArgs.slice(2),
|
||||
}
|
||||
);
|
||||
return {
|
||||
print: args['--print'] || false,
|
||||
url: args._[0]
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
25
dshackle-cli/src/grpc-clent.js
Normal file
25
dshackle-cli/src/grpc-clent.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const grpc = require("@grpc/grpc-js");
|
||||
const path = require('path')
|
||||
const protoLoader = require("@grpc/proto-loader");
|
||||
|
||||
const PROTO_PATH = path.join(__dirname, "../grpc/proto/blockchain.proto");
|
||||
|
||||
const options = {
|
||||
keepCase: true,
|
||||
longs: String,
|
||||
enums: String,
|
||||
defaults: true,
|
||||
oneofs: true,
|
||||
};
|
||||
|
||||
const packageDefinition = protoLoader.loadSync(PROTO_PATH, options);
|
||||
const emerald = grpc.loadPackageDefinition(packageDefinition).emerald
|
||||
|
||||
export function describe(url, handler) {
|
||||
const client = new emerald.Blockchain(
|
||||
url,
|
||||
grpc.credentials.createInsecure()
|
||||
);
|
||||
console.log('Connecting to: ' + url + '...')
|
||||
client.Describe({}, handler);
|
||||
}
|
||||
Reference in New Issue
Block a user