#/bin/bash
#set -x
set -e usage()
{
cat <<EOF
Usage:
`basename $` [OPTIONS] <non-option arguments> Purpose:
  xxxxxxxxxxxx Description:
  None Parameters:   OPTIONS
    -i image -- images, registry: by default
    -p -- host port, by default   <non-option arguments> Author:
  anor@xxxx.com Revision:
  -- Anor Initial Versiona EOF
exit
} ############################################
#declare options string including optional
#argument names separated from withsapce.
#g_opt_name includs optional arg names
#g_opt_<g_opt_name>, just holds optional arg value
#for example,
# Given optional args, -i, -p,
# the option arg variables respectivly should be as,
# g_opt_i
# g_opt_p
############################################
declare -a g_opt_names=(i: p:) ############################################
#init_args()
#initialize arguments before set them with
#command line values
############################################
init_args()
{
g_opt_i="registry:2" # the registry image from hub.docker.com
g_opt_p=
} ############################################
#parse_non_option_args()
#parse non option arguments here
############################################
parse_non_option_args()
{
#//TODD add your code to parse non-option arguments here. return ;
} ############################################
#main()
#add business logics in this [main] function
############################################
main()
{
#//TODD add your bussiness code here return ;
} #*******************************************************
########################################################
### Common functions here
########################################################
#*******************************************************
parse_args()
{ #check if showing usage
if [ "$1" == "--help" ]; then usage; fi init_args parse_options "$@" parse_non_option_args "$@"
}
parse_options()
{
local opt_names="${g_opt_names[@]}" local opt_string="$(echo -e "$opt_names" | tr -d '[[:space:]]')" log "opt_string=$opt_string" if [ -n "$opt_names" ]; then
while getopts $opt_string opt
do
for i in "${g_opt_names[@]}"
do
local opt_name=${i::}
local opt_var_name=g_opt_$opt_name
case $opt in
$opt_name )
if [ -z "$OPTARG" ]
then
eval $opt_var_name=
else
eval $opt_var_name=\"$OPTARG\"
fi
log "$opt_var_name=${!opt_var_name}"
;;
h ) usage ;;
\?) usage ;;
esac
done
done
fi
} #Purpose:
# echo log message
#
#Parameters:
# @.... -- log messages
#
log()
{
echo "[`date +'%Y-%m-%d %H:%M:%S'` $0]" "${@:1}"
} _main()
{ #parse optional
parse_args "$@" #main routine
main "$@" #successful log
log "Done!"
} _main "$@"

最新文章

  1. Lintcode 150.买卖股票的最佳时机 II
  2. MySQL数据库备份--mysqldump用法
  3. 《Python核心编程》18.多线程编程(二)
  4. redis-3.2.5 make 报错
  5. 在android 中开发java.net.SocketException: socket failed: EACCES (Permission denied) 报错
  6. arp命令
  7. PHP操作mysql数据库:[2]查询数据听语音
  8. binarySearch二分查找——Javascript实现
  9. 搭建golang的beego注意事项
  10. C#整理7——函数
  11. 百度ueditor富文本编辑器的使用
  12. use EXPORT和use EXPORT_OK
  13. shell 字符串包含
  14. 从零一起学Spring Boot之LayIM项目长成记(六)单聊群聊的实现
  15. android:shape 设置圆形
  16. 华为QUIDWAY系列路由器的单臂路由配置案例
  17. SpringIOC框架详解
  18. User模型扩展和自定义
  19. Github介绍
  20. 添加JavaDoc

热门文章

  1. 实现静默安装APK的方法
  2. Java 并发 —— 读写锁(ReadWriteLock)
  3. Lightoj 1140(数位DP)
  4. Are you sure you want to continue connecting etc ssh ssh_config StrictHostKeyChecking no
  5. 【192】PowerShell 相关知识
  6. asp.net mvc razer
  7. 10款Web开发最佳的Python框架
  8. CodeForces 722C Destroying Array (并查集)
  9. [笔记]如何将已存在的JAVA添加到当前ECLIPSE JAVA工程中
  10. TransposonPSI——转座子分析的入门自学