2 Star 0 Fork 0

mirrors_kolodny/bash-args-compiler

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

bash-args-compiler

Usage

node compile.js template.sh > result.sh

A template file needs to have it's flags area demilited by:

<<"FLAGS"
FLAGS

A flag line takes the following format. Note that a boolean flag ends with an ! and that the shortname is optional:

foo=f
boolean_with_no_short_name!
another_bool=b!

Here's an example input:

#!/usr/bin/env bash

set -euo pipefail

<<"FLAGS"
extension=e
boolean=b!
another_boolean!
FLAGS

echo "extension is $extension"
echo "boolean is $boolean"
echo "another_boolean is $another_boolean"
if [ "${args-}" != "" ]; then
    for arg in "${args[@]}"; do
        echo "arg is $arg ok"
    done
fi

echo test

Here's the output of that:

#!/usr/bin/env bash

set -euo pipefail

args=()
extension=
boolean=
another_boolean=
while [[ $# -gt 0 ]]; do
    key=$1
    case $key in

        -e=*|--extension=*)
        extension="${key#*=}"
        shift
        ;;

        -e|--extension)
        if [ ! $# -gt 1 ]; then
            echo "option requires an argument -- $key" >&2
            exit 1
        fi
        extension=$2
        shift
        shift
        ;;

        -b|--boolean)
        boolean=1
        shift
        ;;

        --another_boolean)
        another_boolean=1
        shift
        ;;

        *)
        args+=("$key")
        shift
        ;;

    esac
done

echo "extension is $extension"
echo "boolean is $boolean"
echo "another_boolean is $another_boolean"
if [ "${args-}" != "" ]; then
    for arg in "${args[@]}"; do
        echo "arg is $arg ok"
    done
fi

echo test

空文件

简介

取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_kolodny/bash-args-compiler.git
git@gitee.com:mirrors_kolodny/bash-args-compiler.git
mirrors_kolodny
bash-args-compiler
bash-args-compiler
master

搜索帮助