Socket
Socket
Sign inDemoInstall

jubaclient

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jubaclient - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

11

app.js

@@ -7,6 +7,11 @@ const assert = require('assert');

function toCamelCase(value) {
return value.toLowerCase().replace(/_([a-z])/g, (match, group1) => group1.toUpperCase());
return value.replace(/_([a-z])/g, (match, group1) => group1.toUpperCase());
}
exports.toCamelCase = toCamelCase;
function toSnakeCase(value) {
return value.replace(/[A-Z]/g, (match) => '_' + match.toLowerCase());
}
exports.toSnakeCase = toSnakeCase;
function request(service, method, params, rpcClient, name) {

@@ -23,4 +28,4 @@ const serviseName = toCamelCase('_' + service);

function assertServiceMethod(service, method) {
assert.ok(typeof service === 'string', 'service is required.');
assert.ok(typeof method === 'string', 'method is required.');
assert.ok(service && typeof service === 'string', 'service is required.');
assert.ok(method && typeof method === 'string', 'method is required.');

@@ -27,0 +32,0 @@ const serviseName = toCamelCase('_' + service);

@@ -7,2 +7,3 @@ #!/usr/bin/env node

const minimist = require('minimist');
const jubatus = require('jubatus');
const rpc = require('jubatus/lib/msgpack-rpc');

@@ -15,12 +16,51 @@ const app = require('./app');

let count = 0;
const argv = minimist(process.argv.slice(2), { p: 9190, h: 'localhost', n: '', t: 0 });
const { '_': [ service, method ], p: port, h: host, n: name, t: timeout } = argv;
const argsOption = {
boolean: [ 'i' ],
string: [ 'h', 'n', ],
alias : { 'p': 'port', 'h': 'host', 'n': 'name', 't': 'timeout', 'i': 'interactive' },
default: { p: 9199, h: 'localhost', n: '', t: 0, i: false },
unknown: false
};
const args = minimist(process.argv.slice(2), argsOption);
const { p: port, h: host, n: name, t: timeout, i: interactive } = args;
let { '_': [ service, method ] } = args;
app.assertServiceMethod(service, method);
if (typeof port !== 'number') throw new Error('Illegal option: -p');
if (typeof timeout !== 'number') throw new Error('Illegal option: -t');
const client = rpc.createClient(port, host, timeout);
const rl = readline.createInterface({ input: process.stdin })
.on('line', line => {
let completions = Object.keys(jubatus);
const completer = (line) => {
const hits = completions.filter((c) => c.startsWith(line));
return [ hits.length ? hits : completions, line ];
};
const rl = readline.createInterface({ input: process.stdin, output: process.stderr, completer: completer });
function question(rl, message) {
return new Promise(resolve => rl.question(message, resolve));
}
(service || !interactive ? Promise.resolve(service) : question(rl, `service : `)).then(serviceName => {
app.assertServiceMethod(serviceName, 'get_client');
service = serviceName;
rl.setPrompt(`${ service } >`);
const clientClass = jubatus[app.toCamelCase('_' + service).toLowerCase()].client[app.toCamelCase('_' + service)];
const notRPCMethodNames = [ 'getClient', 'getName', 'setName' ];
const methods = Object.keys(clientClass.prototype)
.filter(method => !(notRPCMethodNames.some(notRPCMethod => method === notRPCMethod)))
.map(app.toSnakeCase);
completions = methods;
return (method || !interactive ? Promise.resolve(method) : question(rl, `${ service } method : `));
}).then(methodName => {
method = methodName;
app.assertServiceMethod(service, method);
rl.setPrompt(`${ service }#${ method } > `);
completions = [ '[]' ];
let count = 0;
if (interactive) rl.prompt();
rl.on('line', line => {
debug(`${ ++count }: ${ line }`);
new Promise((resolve, reject) => {

@@ -35,2 +75,4 @@ resolve(JSON.parse(line));

console.log(JSON.stringify(result));
if (interactive) rl.prompt();
}).catch(error => {

@@ -43,2 +85,6 @@ console.error(error);

client.close();
});
});
}).catch(error => {
console.error(error.toString());
process.exit(1);
});
{
"name": "jubaclient",
"version": "0.1.3",
"version": "0.2.0",
"description": "Jubatus CLI client (unofficial)",
"main": "index.js",
"bin": "index.js",
"man" : "./man/jubaclient.1",
"man": "./man/jubaclient.1",
"scripts": {

@@ -9,0 +9,0 @@ "test": "istanbul cover ./node_modules/mocha/bin/_mocha"

@@ -21,3 +21,3 @@ # jubaclient

echo '[ [ [ "baz", [ [ [ "foo", "bar" ] ] ] ] ] ]' \
| jubaclient classifier train -p 9199 -h localhost
| jubaclient classifier train
```

@@ -37,4 +37,6 @@

<code>jubaclient _service_ _method_ [**-p** _port_] [**-h** _host_] [**-n** _name_] [**-t** _timeoutSeconds_]</code>
<code>jubaclient _service_ _method_ [**-p** _port_] [**-h** _hostname_] [**-n** _name_] [**-t** _timeoutSeconds_]</code>
<code>jubaclient -i [_service_] [_method_] [**-p** _port_] [**-h** _hostname_] [**-n** _name_] [**-t** _timeoutSeconds_]</code>
The `jubaclient` command requests JSON received from standard input with the specified method to the Jubatus server, and returns the response to the standard output.

@@ -46,6 +48,7 @@

- <code>_method_</code>: service method (`get_status`, `train`, `get_k_center`, etc.)
- <code>**-p** _port_</code> : port number (default `9190`)
- <code>**-h** _host_</code> : hostname (default `localhost`)
- <code>**-p** _port_</code> : port number (default `9199`)
- <code>**-h** _hostname_</code> : hostname (default `localhost`)
- <code>**-n** _name_</code> : name of target cluster (default `''`)
- <code>**-t** _timeoutSeconds_</code> : timeout (default `0`)
- <code>**-i**</code> : interactive mode

@@ -82,2 +85,6 @@ ## Examples ##

```
## Interactive mode ##
[![asciicast](https://asciinema.org/a/161095.png)](https://asciinema.org/a/161095)
## Tutorial ##

@@ -93,3 +100,3 @@

```bash
jubaclassifier -p 9190 -D --configpath gender.json
jubaclassifier -D --configpath gender.json
```

@@ -131,3 +138,2 @@

training data: `train.csv`

@@ -148,3 +154,2 @@ ```csv

long,shirt,skirt,1.50
```
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc