1.1.1 • Published 7 years ago

c-global v1.1.1

Weekly downloads
6
License
ISC
Repository
github
Last release
7 years ago

C

A global framework for creating cli commands

Install

$ npm install -g c-global

Commands

Just type in c in the console and it will list all available commands

Creating a command

$ c make:command foo

This will create a new file FooCommand in current directory.

class FooCommand {
    constructor() {
        this.command = "foo";
        this.description = "My awesome description!";
    }
    
    handle() {
	console.log('Hello world!');
    }
}
module.exports = FooCommand;

To execute the command just type c foo in the console.

Describing arguments and options

class MakeUserCommand {
    constructor() {
        this.command = "make:user";
        this.description = "My awesome description!";
        
        this.arguments = [
            {
                key: 'name',
                required: true,
                description: 'User name',
                default: 'John' //if default is set required is ignored 
            },
        ];
        
        this.options = [
            {
                key: '--lastname', 
                short: '-l', 
                default: 'Doe', //if default is set required is ignored 
                required:false, 
                description: 'Users last name',
            }
        ];
    }   
    
    handle() {
        
        // all input is held in this.input
        
        console.log(this.input.name);
        console.log(this.input.lastname);
        
    }
}
module.exports = MakeUserCommand;

Passing options to command

The above command accepts one lastname option. There are multiple ways of passing it:

$ c make:user John --lastname Doe 
$ c make:user John --lastname=Doe 
$ c make:user John --lastname="Doe Doee" 
$ c make:user John -l Doe 
$ c make:user John -l=Doe 
$ c make:user John -l="Doe Doee" 

It does not matter witch option you use, all of them will store the value into this.input.lastname variable

List

To display the list of available commands just type c with no parameters. All commands are 'namespaced', when creating a command like make:user make will be the namespace. It has no real purpose except for looking nice in list of commands.

Cache

Using c make:command <name> command will create and automatically put the command to cache, To cache the commands your self you can use c cache:dir comamand, it will cache all commands in the current directory. To remove commands that no longer exist use c cache:clear command.

Tests

$ npm test
1.1.1

7 years ago

1.1.0

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago