#bash #bundler #shell #source-file #toml-config

程序 bash_bundler

将 bash 文件收集/打包成一个文件

2 个版本

0.1.1 2021 年 5 月 24 日
0.1.0 2021 年 5 月 24 日

#1762开发工具

无许可

16KB
320

bash_bundler

Crates.io Documentation Crates.io

将 bash 文件收集/打包成一个文件。

默认使用保存器 # import ./filename.sh 语法来包含其他 bash 文件。但也可以设置为使用已经存在的 source ./filename.sh 语法。

入门指南

cargo install bash_bundler

安装后

bash_bundler your-main-file.sh > bundled.sh

或使用配置文件

bash_bundler --config your-config.toml > bundled.sh

示例和风格差异

import 和 source 导入语句之间存在差异。import 是相对于当前文件的,但 source 是相对于基础/根文件的。

例如:您的根文件在 src/my_project.sh,看起来像这样

# import ./utils/utils.sh

my_func "hallo"

而 utils.sh 看起来像这样

# import ./other.sh # other contains the my_func

这将导入来自文件 ./src/utils/other.sh

使用 source 它是相对于根文件的,所以像这样

source ./utils/utils.sh

my_func "hallo"

utils.sh 看起来像这样

source ./utils/other.sh # other contains the my_func

这样做是为了让包含 source 的文件可以在正常 bash 中使用。

cd src
./my_project.sh

查看 tests 文件夹以获取更多直接示例。

配置

配置可用于覆盖/保存参数。配置应如下所示


[bundler]
replace_source = true
replace_comment = false
root_path = "./tests/source.sh"

CLI 帮助文本

USAGE:
    bash_bundler [FLAGS] [OPTIONS] <root-path>

FLAGS:
    -h, --help
            Prints help information

        --disable-comment
            disable the '# import ./file.sh` syntax

        --enable-source
            enable the 'source ./file.sh` syntax

    -V, --version
            Prints version information


OPTIONS:
    -c, --config <config>
            path to your toml config


ARGS:
    <root-path>
            starting or `main` bash file

依赖项

~3MB
~58K SLoC