Skip to content

Commit

Permalink
Add in list command
Browse files Browse the repository at this point in the history
  • Loading branch information
keithwhor committed Aug 12, 2016
1 parent b810bd3 commit fcf89ce
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
20 changes: 20 additions & 0 deletions LICENSE
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2016 Polybit Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
61 changes: 61 additions & 0 deletions cli/commands/f/list.js
@@ -0,0 +1,61 @@
'use strict';

const Command = require('cmnd').Command;
const path = require('path');
const fs = require('fs');
const async = require('async');
const APIResource = require('api-res');
const Credentials = require('../../credentials.js');
const tabler = require('../../tabler.js');

class FListCommand extends Command {

constructor() {

super('f', 'list');

}

help() {

return {
description: 'Lists your <stdlib> functions'
};

}

run(params, callback) {

let host = 'api.polybit.com';
let port = 443;

let hostname = (params.flags.h && params.flags.h[0]) || '';
let matches = hostname.match(/^(https?:\/\/)?(.*?)(:\d+)?$/);

if (hostname && matches) {
host = matches[2];
port = parseInt((matches[3] || '').substr(1) || (hostname.indexOf('https') === 0 ? 443 : 80));
}

let resource = new APIResource(host, port);
resource.authorize(Credentials.read('ACCESS_TOKEN'));

let name = params.args[0];
let obj = {};
name && (obj.name = name);

return resource.request('v1/functions').index(obj, (err, response) => {

if (err) {
return callback(err);
}

callback(null, tabler(['command', 'url'], response.data));

});

}

}

module.exports = FListCommand;
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "stdlib.com",
"version": "0.1.1",
"version": "0.1.2",
"description": "The Standard Library of the Internet",
"main": "index.js",
"scripts": {
Expand All @@ -16,7 +16,7 @@
"f": "cli/f_bin.js"
},
"dependencies": {
"api-res": "0.0.4",
"api-res": "0.0.5",
"async": "^2.0.1",
"cmnd": "~0.1.1",
"inquirer": "~0.11.3"
Expand Down

0 comments on commit fcf89ce

Please sign in to comment.