@coboxcoop/cli
Advanced tools
Comparing version 1.0.4-alpha.1 to 1.0.5-alpha.1
@@ -44,3 +44,3 @@ const Client = require('@coboxcoop/client') | ||
space = responses[0] | ||
print(space) | ||
printSpace(space) | ||
} | ||
@@ -52,3 +52,2 @@ } | ||
print(space) | ||
console.log() | ||
} |
@@ -18,3 +18,3 @@ const Client = require('@coboxcoop/client') | ||
let spaces = await client.get('spaces') | ||
if (!spaces.length) return console.log(`! ${chalk.bold(`you have no folders`)} create one with\n${chalk.hex('#ACFFAC')(`folders up --name <name>`)}`) | ||
if (!spaces.length) return console.log(`! ${chalk.bold(`you have no folders`)} create one with\n${chalk.hex('#ACFFAC')(`cobox folders up --name <name>`)}`) | ||
spaces.forEach(printSpace) | ||
@@ -29,3 +29,2 @@ } catch (err) { | ||
print(space) | ||
console.log() | ||
} |
@@ -49,3 +49,3 @@ const Client = require('@coboxcoop/client') | ||
space = responses[0] | ||
print(space) | ||
printSpace(space) | ||
} | ||
@@ -57,3 +57,2 @@ } | ||
print(space) | ||
console.log() | ||
} |
const constants = require('@coboxcoop/constants') | ||
const options = require('./options') | ||
const DEFAULT_COLOUR = '#ACFFAC' | ||
const chalk = require('chalk') | ||
@@ -29,3 +30,10 @@ const { | ||
if (!Array.isArray(errors)) return console.log(UNHANDLED_SERVER_ERROR(err)) | ||
errors.forEach((err) => process.stderr.write(err.msg)) | ||
errors.forEach((err) => { | ||
if (err.param) { | ||
let msg = `${chalk.hex('#ACFFAC')(err.param)} ${err.msg}` | ||
console.log(msg) | ||
} else { | ||
console.log(err.msg) | ||
} | ||
}) | ||
} else if (err.request) { | ||
@@ -32,0 +40,0 @@ // the request was made but no response received, could have been a timeout, or the wrong port was specified |
@@ -6,3 +6,3 @@ const Client = require('@coboxcoop/client') | ||
exports.command = 'login <password>' | ||
exports.desc = 'unlock your cobox spaces' | ||
exports.desc = 'login (or register) to unlock your cobox spaces' | ||
exports.builder = getDefaultOpts() | ||
@@ -17,4 +17,13 @@ exports.handler = login | ||
} catch (err) { | ||
handleAjaxErrors(err) | ||
if (err.response && err.response.status === 404) { | ||
try { | ||
await client.post('register', {}, { password: argv.password }) | ||
console.log('registered and logged in to cobox') | ||
} catch (err) { | ||
handleAjaxErrors(err) | ||
} | ||
} else { | ||
handleAjaxErrors(err) | ||
} | ||
} | ||
} |
@@ -1,6 +0,5 @@ | ||
const axios = require('axios') | ||
const Client = require('@coboxcoop/client') | ||
const { buildBaseURL } = require('@coboxcoop/client/util') | ||
const print = require('pretty-print') | ||
const path = require('path') | ||
const { getDefaultOpts, handleAjaxErrors } = require('./lib/util') | ||
const { getHeaders, buildBaseURL } = require('../util') | ||
@@ -13,14 +12,8 @@ exports.command = 'nickname <name>' | ||
async function nickname (argv) { | ||
const endpoint = buildBaseURL(argv) | ||
const client = new Client({ endpoint: buildBaseURL(argv) }) | ||
const name = argv.name | ||
try { | ||
var data = await axios.request({ | ||
url: path.join(endpoint, 'api', 'profile'), | ||
params: { name }, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
...getHeaders(argv) | ||
} | ||
}) | ||
const id = await client.get('identities/current') | ||
const data = await client.patch(`identities/${id.publicKey}`, {}, { name }) | ||
print(data) | ||
@@ -27,0 +20,0 @@ } catch (err) { |
@@ -43,3 +43,2 @@ const Client = require('@coboxcoop/client') | ||
print(seeder) | ||
console.log() | ||
} |
@@ -17,6 +17,3 @@ const Client = require('@coboxcoop/client') | ||
const client = new Client({ endpoint: buildBaseURL(argv) }) | ||
const name = opts.name, | ||
address = opts.address, | ||
encryptionKey = opts.key | ||
code = opts.code | ||
const code = opts.code | ||
@@ -27,9 +24,12 @@ try { | ||
return await onceSeeder(seeder) | ||
} | ||
} else { | ||
let seeders = await client.get(['admin', 'seeders']) | ||
let seeders = await client.get(['admin', 'seeders']) | ||
if (!seeders.length) { | ||
return console.log(`! ${chalk.bold(`you have no registered seeders`)}, join one with\n${chalk.hex('#ACFFAC')(`seeders up --code <code>`)}`) | ||
} | ||
if (!seeders.length) return console.log(`! ${chalk.bold(`you have no registered seeders`)}, join one with\n${chalk.hex('#ACFFAC')(`seeders up --code <code> or seeders up --name <name> --address <address> --key <key>`)}`) | ||
seeders = await client.post(['admin', 'seeders', 'connections']) | ||
seeders.forEach(printSeeder) | ||
seeders = await client.post(['admin', 'seeders', 'connections']) | ||
seeders.forEach(printSeeder) | ||
} | ||
} catch (err) { | ||
@@ -48,14 +48,2 @@ return handleAjaxErrors(err) | ||
print(seeder) | ||
console.log() | ||
} | ||
// removed temporaily, seeders can only be joined in the app via an invite code | ||
// if (name || address || encryptionKey) { | ||
// let seeder = seeders.find((seeder) => seeder.name === name || seeder.address === address) | ||
// if (seeder) return await onceSeeder(seeder) | ||
// if (!(name && address && encryptionKey)) return console.log(`! ${chalk.bold(`name, address and key required`)}, use the following command:\n${chalk.hex('#ACFFAC')(`seeders up --name <name> --address <address> --key <key>`)}`) | ||
// seeder = await client.post(['admin', 'seeders'], {}, { name, address, encryptionKey }) | ||
// await onceSeeder(seeder) | ||
// } else { |
@@ -21,3 +21,3 @@ const Client = require('@coboxcoop/client') | ||
if (!name && !address) { | ||
var replicators = await client.delete(['replicators', 'connections']) | ||
var replicators = await client.delete('replicators/connections') | ||
replicators.forEach(printReplicator) | ||
@@ -35,3 +35,5 @@ } else { | ||
async function onceReplicator (replicator) { | ||
await client.delete(['replicators', replicator.address, 'connections'], { id: replicator.address }, replicator) | ||
await client.delete(`replicators/${replicator.address}/connections`, { | ||
id: replicator.address | ||
}, replicator) | ||
print(replicator) | ||
@@ -42,4 +44,4 @@ } | ||
function printReplicator (replicator) { | ||
console.log() | ||
print(replicator) | ||
console.log() | ||
} |
@@ -17,2 +17,3 @@ const Client = require('@coboxcoop/client') | ||
let replicators = await client.get('replicators') | ||
if (!replicators.length) return console.log(`! ${chalk.bold(`you are not seeding any addresses`)}\nget an address to start backing up someone's folder:\n${chalk.hex('#ACFFAC')(`cobox seeds up --address <address>`)}`) | ||
replicators.forEach(printReplicator) | ||
@@ -19,0 +20,0 @@ } catch (err) { |
@@ -47,3 +47,2 @@ const Client = require('@coboxcoop/client') | ||
print(replicator) | ||
console.log() | ||
} |
const Client = require('@coboxcoop/client') | ||
const { buildBaseURL } = require('@coboxcoop/client/util') | ||
const pick = require('lodash.pick') | ||
const chalk = require('chalk') | ||
const print = require('pretty-print') | ||
@@ -9,3 +7,3 @@ const { getDefaultOpts, handleAjaxErrors } = require('./lib/util') | ||
exports.command = 'whoami' | ||
exports.desc = 'display your nickname and cobox key' | ||
exports.desc = 'display your public name and cobox key' | ||
exports.builder = getDefaultOpts() | ||
@@ -12,0 +10,0 @@ exports.handler = whoami |
@@ -9,3 +9,2 @@ #!/usr/bin/env node | ||
const config = require('@coboxcoop/config') | ||
const { loadSession } = require('./util') | ||
@@ -12,0 +11,0 @@ const args = yargs |
{ | ||
"name": "@coboxcoop/cli", | ||
"version": "1.0.4-alpha.1", | ||
"version": "1.0.5-alpha.1", | ||
"description": "command line client for the cobox app", | ||
@@ -5,0 +5,0 @@ "main": "cli.js", |
72421
964