Management script for generating code using thritidl

Source: Internet
Author: User
As the number of projects increases, the management of thritidl Generation Code becomes more complex. This tool is used to generate thrift code. It should be scripted, configurable, and automated as much as possible. None #! Usrbinenvphp? With the increase of php *** projects, the management of thritidl code generation is also more complex. * This tool is used to generate thrift code and make it scripted as much as possible.

As the number of projects increases, the management of thritidl Generation Code becomes more complex. This tool is used to generate thrift code. It should be scripted, configurable, and automated as much as possible. None #! /Usr/bin/env php? Php/*** as the number of projects increases, the more complicated thrift IDL code generation management is. * This tool is used to generate thrift code and make it scripted as much as possible.

As the number of projects increases, the management of thrift IDL Generation Code is also more complex. This tool is used to generate thrift code. It should be scripted, configurable, and automated as much as possible. <无>
#! /Usr/bin/env php
  'Thrift -- gen {gen}-out "{out}" {idl }"', 'project' => array ('cms-exmaple' => array ('gen' => 'php', // Code target language, -- gen option for thrift 'out' => '/path/to/output', // code output directory, used for thrift's -- out option 'idl _ git_url' =>' https://git-url ', // Indicates whether the IDL uses git management. If it is set, pull is automatically executed. // For example: https://github.com/my/thrift-idl.git 'Idl _ git_pre '=>'/src/Master', // git URL prefix of the idl file. In this example: // assume that idl_git_url is https://github.com/my/thrift-idl.git // The IDL path is/path/to/cms. thrift, And the idl_root_path is/root/thrift/idl //. the full path of git is https://github.com/my/thrift-idl/src/master/path/to/cms.thrift // The local path is/root/thrift/idl/path/to/cms. thrift 'idl _ root_path '=>'/path/to/idl ', // The idl root directory, which is spliced with idls. If git exists, this directory should be set as the root directory of git (including. git directory) 'idls' => array (// directory or file where IDL is located '/path/to/idl/1 ', '/path/to/idl/2',),); ** Author: https://github.com/heiing * Date: 2015-03-06T11: 06 + 08: 00 */define ("VERSION", "0.1.0"); function usage ($ self, $ ln = PHP_EOL) {echo "Usage: {$ self} project-name config-file [idl-git-url] {$ ln} "; echo" project-name Project name {$ ln }"; echo "config-file Config file path {$ ln}"; echo "idl-git-url IDL git url {$ ln}"; echo "{$ ln }"; echo "config-file example: {$ ln}"; echo"
  'Thrift -- gen {gen}-out \ "{out} \" \ "{idl} \" ', {$ ln }"; echo "'project' => array ({$ ln}"; echo "'cms-exmaple' => array ({$ ln }"; echo "'gen' => 'php', // Code target language, used for thrift's -- gen option {$ ln }"; echo "'out' => '/path/to/output', // code output directory for thrift's -- out option {$ ln }"; echo "'idl _ git_url '=>' https://git-url ', // Indicates whether the IDL uses git management. If it is set, pull, {$ ln} "; echo" // for Example https://github.com/my/thrift-idl.git {$ Ln} "; echo" 'idl _ git_pre '=>'/src/Master', // git URL prefix of the idl file. In this example: {$ ln} "; echo" // assume that idl_git_url is https://github.com/my/thrift-idl.git {$ Ln} "; echo" // The IDL path is/path/to/cms. thrift, idl_root_path is/root/thrift/idl {$ ln} "; echo" // the full path of git is https://github.com/my/thrift-idl/src/master/path/to/cms.thrift {$ Ln} "; echo" // The local path is/root/thrift/idl/path/to/cms. thrift {$ ln} "; echo" 'idl _ root_path '=>'/path/to/idl ', // idl root directory, spliced with idls. If git exists, this directory should be set as the root directory of git (including. git directory) {$ ln} "; echo" 'idls' => array (// directory or file where IDL is located {$ ln }"; echo "'/path/to/idl/1', {$ ln}"; echo "'/path/to/idl/2', {$ ln }"; echo "), {$ ln}"; echo "); {$ ln }"; echo "// -------- end of config-file {$ ln}"; echo "{$ ln}"; echo "usage example: {$ ln}"; echo "1. {$ self} cms-example/root/cthrift/config. php {$ ln} "; echo" 2. {$ self} cms-example/root/cthrift/config. php https://github.com/my/thrift-idl/src/master/cms.thrift {$ Ln} "; echo" {$ ln} "; echo" good luck {$ ln} "; echo" {$ ln} "; exit (1 );} function error ($ message, $ ln = PHP_EOL) {echo "Error: {$ message} {$ ln}"; exit (1) ;} function info ($ message, $ ln = PHP_EOL) {echo "{$ message} {$ ln}";} function config ($ name, $ value = null) {static $ pool = array (); if ($ value = null) {return isset ($ pool [$ name])? $ Pool [$ name]: null;} $ pool [$ name] = $ value;} function retend_config ($ name, $ value) {if (! Is_array ($ value) | is_numeric (implode ('', array_keys ($ value) {return config ($ name, $ value );} foreach ($ value as $ n =>$ v) {retend_config ($ name. '/'. $ n, $ v) ;}} function load_config () {$ file = config ('/config-file'); info ('Load config :'. $ file); if (! Is_file ($ file) {error ('config file not exists! ') ;}$ Configs = include $ file; if (! Isset ($ configs ['project']) {error ('invalid config! ');} If (! Isset ($ configs ['project'] [config ('/project-name')]) {error ('Project not set! ');} Foreach ($ configs as $ name => $ value) {if (! Is_array ($ value) {config ($ name, $ value);} else {retend_config ($ name, $ value) ;}} function do_command ($ cmd, $ argv, $ exit_on_error = true) {foreach ($ argv as $ name => $ value) {$ cmd = str_replace ('{'. $ name. '}', $ value, $ cmd);} info ($ cmd); $ ret = 0; passthru ($ cmd, $ ret); if ($ ret! = 0 & $ exit_on_error) {error ('faild! ');} Return $ ret;} function process_project () {$ pre = 'projects /'. config ('/project-name'); $ out = config ("{$ pre}/out "); if (null = ($ cmd = config ('thrift _ command') {$ cmd = 'thrift -- gen {gen }'. ($ out? '-- Out {out }':''). '{idl}';} if (null = ($ gen = config ("{$ pre}/gen") {error ('gen not set! ');} If (null = ($ path = config ("{$ pre}/idl_root_path") {error ('idl _ root_path not set! ');} If (! Is_dir ($ path) {error ('idl _ root_path not exists! ') ;}$ Path = rtrim ($ path,'/\ '); $ git = rtrim (config ("{$ pre}/idl_git_url "), '/'); if (! Empty ($ git) {do_command ("cd {$ path}; git pull;", array (), true) ;}if (null! = ($ Url = config ('/idl-git-url') {$ git = (strtolower (substr ($ git,-4) = '. git '? Substr ($ git, 0,-4): $ git). config ("{$ pre}/idl_git_pre"); if ($ git! = Substr ($ url, 0, strlen ($ git) {error ('invalid git url! ') ;}$ Idls = array (substr ($ url, strlen ($ git )));} else if (null ===( $ idls = config ("{$ pre}/idls") | empty ($ idls )) {error ('idls not set or empty! ');} Foreach ($ idls as $ idl) {$ idl = "{$ path} {$ idl}"; if (is_dir ($ idl )) {$ idl_files = glob ("{$ idl }/*. thrift ");} else if (is_file ($ idl) {$ idl_files = array ($ idl);} else {info (" Not Found: {$ idl }"); continue;} foreach ($ idl_files as $ file) {do_command ($ cmd, array ('gen' => $ gen, 'out' => $ out, 'idl '=> $ file,), true) ;}} function run ($ argv) {info ("Thrift Creator ". VERSION); if (! Isset ($ argv [2]) {usage ($ argv [0]);} config ('/config-file', $ argv [2]); config ('/project-name', $ argv [1]); if (isset ($ argv [3]) {config ('/idl-git-url ', $ argv [3]);} load_config (); process_project (); info ('done. ');} run ($ argv );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.