Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Command Line Library
#1

[eluser]Unknown[/eluser]
Hello, guys!

A few months ago I was developing some command line backend for some of my projects and was quite disappointed with fact that php getopt function doesn't work with CodeIgniter properly, and actually not so convenient.

That came into the small library, that I'm presenting to you nowadays.

It is quite simple - actually it does only a few things:

- It allows you to use Codeigniter's controlles in the UNIX cli way.
- It has several built in types of arguments: optional, required and boolean (flags).
- It validates your requests based on selected arguments types.
- It can print help message when there are no arguments set in the query.

Check it out on github, where also is a short documentation with examples:
https://github.com/TrueDrago/CodeIgniter...brary-CCLL

PS: It was made on the knee and it can possible be unstable or contain bugs, so feel free to submit bug reports or contribute to it!
#2

[eluser]CroNiX[/eluser]
How is this an improvement over how CI natively works via the CLI?
http://ellislab.com/codeigniter/user-gui...l/cli.html
#3

[eluser]Unknown[/eluser]
CI's native cli implementation works a little bit different - it's just a way of calling controllers from command line - nothing more.
I'm suggesting some improvements such as built in validation of parameters, printing help messages for script usage. And it all has interface like standart linux programs.

For example you want to write and then use a simple email sending script that accepts theese parameters:
- file with email adresses (required),
- hmtl template (required),
- subject (required),
- importance (optional),
- logging option (flag),
- forcing the sending for those, who already got it (flag).

In native implementation you'll probably will need to worry about order of parameters in cli, validation of them - you will need to write more code and your request might be like this:
Code:
php /%indexdir%/index.php "emails.txt" "mail.phtml" "Hello" FALSE FALSE TRUE

When with this library you will just init the config array for the possible parameters and could write this request in more traditional way:
Code:
php /%indexdir%/index.php --subject Hello -t "mail.phtml" -f "emails.txt" --force
More of that, if you miss for example the -f and\or -t args, you will be able to get error message with only 1 line of code, that also can explain the usage of your script when called without aguments:
Code:
print $this->command_line->get_help();
#4

[eluser]CroNiX[/eluser]
Yeah, I've always used this method instead of CI's native CLI methods, which allow you to do things like set the name of the server and other variables at run time. Very easy to add your own stuff or modify it as well.
http://ellislab.com/forums/viewthread/88635/




Theme © iAndrew 2016 - Forum software by © MyBB