diff --git a/cli.js b/cli.js index 1d97c02..edd82be 100755 --- a/cli.js +++ b/cli.js @@ -1,42 +1,42 @@ #!/usr/bin/env node var Blipper = require('./index.js') -var _ = require('highland') var client = new Blipper() -var command = process.argv[2] || 'help' - -var commands = { - profile: function () { - return client.getProfile().map(function (profile) { - return 'name: ' + profile.username + '\n' + - 'about: ' + profile.about + '\n' + - 'id: ' + profile.id - }) - }, - name: client.setUsername, - about: client.setAbout, - say: client.post, - add: client.addFollowee, - feed: function () { - return client.getFeed().map(function (post) { - return (post.author.username || post.author.id) + ' - ' + (new Date(post.time)).toString() + '\n' + - ' ' + post.content + '\n' - }) - }, - help: function () { - return _.of( - 'usage: blipper []\n' + - 'commands:\n' + - ' name Set your username\n' + - ' about Set your about info\n' + - ' profile View our username, about, and unique node id\n' + - ' say Say something which your followers will see in their feeds\n' + - ' add Add unique id of another node to follow\n' + - ' feed Show your feed of your posts and posts by nodes you follow\n' - ) - } -} - -commands[command].apply(client, process.argv.slice(3)).invoke('toString').append('\n').pipe(process.stdout) +const arg = require('yargs') + .usage('Usage: $0 [options]') + .command('name ', 'Set your username') + .command('about ', 'Set your about info') + .command('profile', 'View our username, about, and unique node id') + .command('say ', 'Say something which your followers will see in their feeds') + .command('add ', 'Add unique id of another node to follow') + .command('feed', 'Show your feed of your posts and posts by nodes you follow') + + .example('$0 name konsumer', 'Set your name to "konsumer"') + .example('$0 about "Mostly human"', 'Set your about-text') + .example('$0 say "Hey planet!"', 'Say something') + .example('$0 add QmUNfYBRgXqV1NDDiTws9vvFWtijZwMZCu6KENEVWGcG7k', 'Follow @protometa') + + .help('h') + .alias('h', 'help') + .demandCommand(2) + .argv + +const commands = {} + +commands.profile = () => client.getProfile().map(profile => `name: ${profile.username} +about: ${profile.about} +id: ${profile.id} +`) + +commands.feed = () => client.getFeed().map(post => (`${post.author.username || post.author.id} - ${new Date(post.time)} +${post.content} +`)) + +commands.name = () => client.setUsername(arg.your_username) +commands.about = () => client.setAbout(arg.info) +commands.say = () => client.post(arg.your_message) +commands.add = () => client.addFollowee(arg.friend_id) + +commands[arg._]().invoke('toString').append('\n').pipe(process.stdout) diff --git a/package.json b/package.json index 64d0307..9963fa3 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ }, "dependencies": { "highland": "^2.10.2", - "superagent": "^3.0.0" + "superagent": "^3.0.0", + "yargs": "^7.0.2" } }