mirror of
https://github.com/fazo96/homework-cli.git
synced 2025-05-11 07:18:39 +02:00
first commit
This commit is contained in:
commit
d310243e8f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
node_modules
|
47
homework.js
Executable file
47
homework.js
Executable 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
21
package.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user