1
0
mirror of https://github.com/fazo96/homework-cli.git synced 2025-05-08 06:48:40 +02:00

first commit

This commit is contained in:
Enrico Fasoli 2015-03-09 10:05:40 +01:00
commit d310243e8f
3 changed files with 69 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

47
homework.js Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env node
var request = require('request')
var chalk = require('chalk')
var cli = require('commander')
var moment = require('moment')
cli
.version('1.3.0')
.usage('command [arguments]')
.option('-k, --key [apikey]','use given api key')
.option('-u, --url [endpoint]','use given api endpoint')
.option('-v, --verbose', 'be more verbose')
.option('-i, --id', 'show item IDs')
.parse(process.argv)
if(!cli.key){
console.log(chalk.red("Invalid API key"));
process.exit(1)
}
var url = (cli.url || 'http://homework.meteor.com/api') + '/' + cli.key
if(cli.verbose) console.log(chalk.bold('URL: ') + url)
function notes(archived,callback){
request(url, function(error,response,body){
if(error)
console.log(chalk.red("Error: ") + chalk.bold(error))
else
if(cli.verbose) console.log(chalk.bold("Response: ") + body)
var obj = JSON.parse(body)
var ret = ""
if(obj.forEach){
obj.forEach(function(x){
var date = x.date
if(date != false) date = moment.unix(x.date).format('DD/MM/YYYY')
var str = '\n' + chalk.green('- ') + chalk.bold(x.title)
if(date != false) str += ' (' + chalk.yellow("Due: ") + chalk.underline(date) + ')'
if(cli.id) str += ' (' + chalk.bold('ID: ') + chalk.underline(x._id) + ')'
if(x.content) str += '\n\t' + chalk.green(x.content)
ret += str.substring(1) + '\n'
})
} else callback(body)
callback(ret)
})
}
notes(false,function(x){console.log(x)})

21
package.json Normal file
View File

@ -0,0 +1,21 @@
{
"name": "homework-cli",
"version": "1.3.0",
"description": "command line client for Homework",
"repository": {
"type": "git",
"url": "http://github.com/fazo96/homework-cli"
},
"author": "Enrico Fasoli (fazo96)",
"license": "MIT",
"bugs": {
"url": "https://github.com/fazo96/homework-cli/issues"
},
"homepage": "https://github.com/fazo96/homework-cli",
"dependencies": {
"chalk": "^1.0.0",
"commander": "^2.6.0",
"moment": "^2.9.0",
"request": "^2.53.0"
}
}