php根據(jù)命令行參數(shù)生成配置文件詳解
像npm, composer等工具,在開始使用的使用,都需要初始化項目,生成一個項目的配置文件。這種功能的原理是怎么實現(xiàn)的呢?
比如:
D:\>npm init --yes Wrote 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解釋命令行的參數(shù)的基礎(chǔ)上,加上下面的init分支,即可實現(xiàn)類似的功能
#!/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$ ls go2 ghostwu@ghostwu:~/mybin$ go2 init 2bytes has written.config file has created ghostwu@ghostwu:~/mybin$ ls go2 go.json ghostwu@ghostwu:~/mybin$ cat go.json {}ghostwu@ghostwu:~/mybin$
以上所述是小編給大家介紹的php根據(jù)命令行參數(shù)生成配置文件詳解整合,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
原生JavaScript+PHP多圖上傳實現(xiàn)示例
這篇文章主要為大家介紹了原生JavaScript+PHP多圖上傳實現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-08-08php使用PDO事務(wù)配合表格讀取大量數(shù)據(jù)插入操作實現(xiàn)方法
這篇文章主要介紹了php使用PDO事務(wù)配合表格讀取大量數(shù)據(jù)插入操作實現(xiàn)方法,涉及php使用excel_reader操作Excel文件及PDO操作數(shù)據(jù)庫的相關(guān)技巧,需要的朋友可以參考下2017-02-02Ubuntu server 11.04安裝memcache及php使用memcache來存儲session的方法
這篇文章主要介紹了Ubuntu server 11.04安裝memcache及php使用memcache來存儲session的方法,涉及memcache服務(wù)器的安裝及php操作memcache存儲session的相關(guān)技巧,需要的朋友可以參考下2016-05-05