getopts命令是用来解析Shell脚本命令行参数的工具

 

 

 

 

#!/bin/bash
set -e
set -x

## Global variables
workspace=$PWD/$(dirname $0)
readonly workspace=${workspace%%lite/tools*}
WITH_LOG=OFF
WITH_CV=ON
WITH_EXTRA=ON
WITH_EXCEPTION=ON
WITH_METAL=OFF
MODEL_DIR=""

function print_usage() {
    echo "----------------------------------------------------------------------------------------------------------------------------------------"
    echo -e "| Methods of compiling Padddle-Lite iOS library:                                                                                       |"
    echo "----------------------------------------------------------------------------------------------------------------------------------------"
    echo -e "|  compile iOS armv8+armv7 library:                                                                                                    |"
    echo -e "|     ./lite/tools/build_ios_by_models.sh --model_dir=${model_dir}                                                                   |"
    echo -e "|  compile iOS armv8+armv7 library for GPU:                                                                                            |"
    echo -e "|     ./lite/tools/build_ios_by_models.sh  --with_metal=ON --model_dir=${model_dir}                                                  |"
    echo -e "|  print help information:                                                                                                             |"
    echo -e "|     ./lite/tools/build_ios_by_models.sh help                                                                                         |"
    echo -e "|                                                                                                                                      |"
    echo -e "|  optional argument:                                                                                                                  |"
    echo -e "|     --with_metal: (ON|OFF), controls whether to use metal default is OFF                                                             |"
    echo -e "|     --model_dir: (absolute path to optimized model dir) required when compiling striped library                                      |"
    echo -e "|     --with_cv: (OFF|ON); controls whether to compile cv functions into lib, default is OFF                                           |"
    echo -e "|     --with_extra: (OFF|ON); controls whether to publish extra operators and kernels for (sequence-related model such as OCR or NLP)  |"
    echo -e "|     --with_log: (OFF|ON); controls whether to print log information, default is ON                                                   |"
    echo -e "|     --with_exception: (OFF|ON); controls whether to throw the exception when error occurs, default is OFF                            |"
    echo "----------------------------------------------------------------------------------------------------------------------------------------"
}

# parse command
function init() {
  for i in "$@"; do
    case $i in
      --with_cv=*)
          WITH_CV="${i#*=}"
          shift
          ;;
      --with_extra=*)
          WITH_EXTRA="${i#*=}"
          shift
          ;;
      --with_log=*)
          WITH_LOG="${i#*=}"
          shift
          ;;
      --with_exception=*)
          WITH_EXCEPTION="${i#*=}"
          shift
          ;;
      --with_metal=*)
          WITH_METAL="${i#*=}"
          shift
          ;;
      --model_dir=*)
          MODEL_DIR="${i#*=}"
          shift
          ;;
      help)
          print_usage
          exit 0
          ;;
      *)
          # unknown option
          print_usage
          exit 1
          ;;
    esac
  done
}

init $@

 

https://github.com/PaddlePaddle/Paddle-Lite/blob/develop/lite/tools/build_ios_by_models.sh

 

原文地址:http://www.cnblogs.com/sinferwu/p/16824825.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性