From 8ce1fb2e95bf4154db9109069127b8179254c304 Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Wed, 1 Apr 2015 09:15:09 -0400 Subject: [PATCH] actually implement cli for timeboards --- lib/api/timeboard.js | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/lib/api/timeboard.js b/lib/api/timeboard.js index 1ec50db..c2c4e18 100644 --- a/lib/api/timeboard.js +++ b/lib/api/timeboard.js @@ -230,16 +230,45 @@ module.exports = { return [ "Timeboard:", " Subcommands:", - " get ", - " getall", - " remove ", - " create <description> <graphs>", - " update <dash-id> <title> <description> <graphs>", + " get <dash-id> get an existing timeboard", + " getall get all existing timeboards", + " remove <dash-id> remove an existing timeboard", + " create <title> <description> <graphs> create a new timeboard, <graphs> is a json of the graphs definition", + " update <dash-id> <title> <description> <graphs> update an existing timeboard, <graphs> is a json of the graphs definition", " Options:", - " --tmpvars <templateVariables>" + " --tmpvars <templateVariables> a json representation of the template variables definition" ]; }, handleCli: function(subcommand, args, callback){ + if(subcommand === "get"){ + get(args._[4], callback); + } else if(subcommand === "getall"){ + getAll(callback); + } else if(subcommand === "remove"){ + remove(args._[4], callback); + } else if(subcommand === "create"){ + var title = args._[4]; + var description = args._[5]; + var graphs = JSON.parse(args._[6]); + var templateVariables = []; + if(args["tmpvars"]){ + templateVariables = JSON.parse(args["tmpvars"]); + } + create(title, description, graphs, templateVariables, callback); + } else if(subcommand === "update"){ + var dashId = parseInt(args._[4]); + var title = args._[5]; + var description = args._[6]; + var graphs = JSON.parse(args._[7]); + var templateVariables = []; + if(args["tmpvars"]){ + templateVariables = JSON.parse(args["tmpvars"]); + } + + update(dashId, title, description, graphs, templateVariables, callback); + } else { + callback("unknown subcommand or arguments try `dogapi timeboard --help` for help", false); + } } };