Coder Social home page Coder Social logo

clip's Introduction

Clip is a port of most of the featutty of Express to CLI programming.

Many times we want to have complex use cases that are hard to express and routing along Express and Sugarskull seem to be an apt way of doing this. Another thing that we want to do in CLI programming often is use configuration files, flags, and parameters.

Why

Sharing routes between express and cli, since most often they should look the same Some basic things should be done for you. Configuration files.

Help for commands should always use the same flags.

No repl?

You can make a repl by posting urls, not too hard. Most applications should not need internal repls.

URLs

Urls are partitioned with '/' with a starting '/' at all times, they are url encoded, and accept ':param' and '*'

Requests

Request follow the cmd,tty,next methodology except with cmd,tty,next since we are talking about command information, the terminal, and next stays the same. In the future chaining CLI requests should be easier (ie a clean + build could be done through clip by calling the corresponding urls).

Basic idea of handler arguments

cmd.env = process.env
cmd.flags = require('optimist').argv
cmd.config = require('nconf') + app.config(...)
cmd.prompt = require('prompt')
cmd.params = app.cli(':param') ...

tty = require('winston') + require('cliff')

require('clip')() -> app

app.config

Determines where to find the config property for requests, uses reconf

app.flag(flag, handler)

Uses a middleware if a flag is set, uses optimist

app.cli(path||[path0,...],handler)

Executes a handler if the path is matched

app.param

CLI parameter preconditions ala express

#!/usr/local/bin/node

var clip = require('../');
var app = new clip();
var version = '0.0.1';
//
// SETUP
//
// Recursively find an 'app.json' file with reconf and add it to cmd.config
app.config('app.json',{flags:['conf']});
// Dont print stuff to console if --silent is set
app.flag('silent',function(cmd,tty,next){
  tty.remove(tty.transports.Console);
  next();
});
// Always print out the app info (middleware)
app.use(function(cmd,tty,next){
  tty.info('App.js '+version);
  next();
});

app.usage(function(cmd,tty,next) {
  tty.info('commands: helloworld, info');
});

app.cli(['/hello','/helloworld'], function(cmd,tty,next) {
  tty.info('hello world!');
});

var utils = require('util');
app.cli(['/info','/dump'], function(cmd,tty,next) {
  tty.data(utils.inspect(cmd));
});

app.run();

clip's People

Contributors

bmeck avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

stolsma

clip's Issues

cmd.params doesn't have named params anymore

I don't know if you take issues but the last version doesn't have named params anymore. i.e. cmd.params.id doesn't exists when the route is /apps/clean/:id.

I backtracked it to ebb5e62#L0R159 but I don't know what your intention was here.

Can you please take a look ??

Thanks!!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.