Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions cli.js
Original file line number Diff line number Diff line change
@@ -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 <command> [<arg>]\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 <command> [options]')
.command('name <your_username>', 'Set your username')
.command('about <info>', 'Set your about info')
.command('profile', 'View our username, about, and unique node id')
.command('say <your_message>', 'Say something which your followers will see in their feeds')
.command('add <friend_id>', '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)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"highland": "^2.10.2",
"superagent": "^3.0.0"
"superagent": "^3.0.0",
"yargs": "^7.0.2"
}
}