像npm, composer等工具,在開始使用的使用,都需要初始化項目,生成一個項目的配置文件。這種功能的原理是怎么實現的呢?
比如:
D:/>npm init --yesWrote to D:/package.json:{ "name": "", "version": "1.0.0", "description": "", "main": "index.js", "directories": { "doc": "doc" }, "scripts": { "test": "echo /"Error: no test specified/" && exit 1" }, "keywords": [], "author": "", "license": "ISC"
其實很簡單,在之前這篇文章php解釋命令行的參數的基礎上,加上下面的init分支,即可實現類似的功能
#!/usr/bin/php<?php function init(){ return file_put_contents( getcwd() . '/go.json', '{}' ) . 'bytes has written.' . 'config file has created'; } $res = ''; if( $argc >= 2 ) { $argv[1] == '-v' && $res = 'go version is 1.0'; $argv[1] == 'init' && $res = init(); } echo $res . PHP_EOL;
ghostwu@ghostwu:~/mybin$ lsgo2ghostwu@ghostwu:~/mybin$ go2 init2bytes has written.config file has createdghostwu@ghostwu:~/mybin$ lsgo2 go.jsonghostwu@ghostwu:~/mybin$ cat go.json{}ghostwu@ghostwu:~/mybin$
以上所述是小編給大家介紹的php根據命令行參數生成配置文件詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VeVb武林網網站的支持!
新聞熱點
疑難解答
圖片精選