0.2.3 • Published 8 years ago

nutty v0.2.3

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

nutty

npm npm npm

A small and minimal CLI framework

Install

Install the package using NPM:

npm install nutty

Example

//Import nutty
var nutty = require('nutty');

//Set the CLI name
nutty.set('name', 'hello');

//Set the CLI description
nutty.set('description', 'Say hello');

//Set the CLI version
nutty.set('version', '1.0.0');

//Use a middleware
nutty.use(function(args, next)
{
  //Get the name
  var name = args.arguments[0];

  //Get the hello word
  var hello = (args.options.idiom === 'spanish') ? 'Hola' : 'Hello';

  //Display in console
  console.log('>>>>>>> ' + hello + ' ' + name + '!');
});

//Run the CLI
nutty.run();

Simple usage:

$ hello John
>>>>>>> Hello John!

Use it with options:

$ hello Susan --idiom spanish
>>>>>>> Hola Susan!

API

nutty.set(key, value)

Assigns the value of the setting variable called key to value.

nutty.set('name', 'my-app'); //Initialize the 'name' variable to 'my-app'
nutty.get('name'); //--> Return: ' my-app'
keydescriptiontypedefault
nameThe CLI namestring''
descriptionThe CLI descriptionstring''
versionThe CLI versionstring''

nutty.get(key)

Returns the value of the setting variable called key.

nutty.use(fn)

Add a new middleware to the CLI. Nutty is based on middlewares, that are functions that have access to the arguments object and the next function.

Example:

nutty.use(function(args, next)
{
  // Do your magic
  // ....

  //Next middleware
  return next();
});

args

Args is an object with all the arguments of the CLI. It has the following keys:

  • args.options: an object with all the options with the format key = value.
  • args.arguments: a list with all the arguments that didn't have an option associated with them.

Example:

myapp argument1 argument2 --option1 argument3 --option2 --option3 3.123

Then the args object will has the following structure:

{
  "arguments": [ "argument1", "argument2" ],
  "options":
  {
    "option1": "argument3",
    "option2": true,
    "option3": "3.123"
  }
}

next

The next argument is a function that will call the next middleware on the list when is invoked.

nutty.run()

Run the CLI.

Related

License

MIT LICENSE.

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.9

9 years ago

0.1.8

9 years ago

0.1.7

9 years ago

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago