#config-toml #replace #find #toml #config #cli

app rhep

一个用于配置准备目的轻松查找/替换文本的工具

1 个不稳定版本

0.1.0 2022年5月26日

#45 in #config-toml

MIT 许可证

12KB
92

rhep

一个用于配置准备目的轻松查找/替换文本的工具。

简介

基本上,假设你想以某种类似 handlebars 的方式轻松地进行自己的配置管理,等等,但这所有东西都是过度设计的。此实用程序使您能够轻松地使用您想要的任何前缀/后缀创建自己的配置管理系统,并且它不会带来很多其他负担,只是使该过程快一点。

安装

cargo install rhep

用法

rhep 0.1.0
Aaron Roney <twitchax@gmail.com>
A tool to easily find / replace text for config preparation purposes.

USAGE:
    rhep.exe [OPTIONS] --glob <GLOB> --destination <DESTINATION>

OPTIONS:
    -d, --destination <DESTINATION>
            The directory to write the results to

    -e, --end-sentinel <END_SENTINEL>
            The substring to find which indicates the start of a "sentinel" (The starting token for
            a replacement) [default: }}]

    -g, --glob <GLOB>
            The [glob](https://github.com/rust-lang-nursery/glob) of the files you want to interact
            with

    -h, --help
            Print help information

    -q, --quiet
            Suppress log output

    -r, --replacements <REPLACEMENTS>
            The set of replacements to make

    -s, --start-sentinel <START_SENTINEL>
            The substring to find which indicates the start of a "sentinel" (The starting token for
            a replacement) [default: {{]

    -V, --version
            Print version information

示例

假设你有一个 fly.toml,看起来像这样(它只是几个之一,因为你可能还会有一个数据库等)。

app = "twitchax-app"

kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  image = "repo/the-app"

[env]
  APP_URI="https://app.twitchax.com"
  APP_SERVER_PORT=8082
  APP_STATIC_LOCATION="/static"

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 8082
  processes = ["app"]
  protocol = "tcp"
  script_checks = []

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

但你真正想要的是不通过使用某种重型配置语言来通用化它。那么,发明你想要的任何替换,并使用 rhep 来实现它。

这是 的 TOML,在 config/app/fly.toml 中(再次,你将会有另一个类似的,比如 config/db/fly.toml)。

app = "{{username}}-app"

kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  image = "repo/the-app"

[env]
  APP_URI="https://app.{{username}}.com"
  APP_SERVER_PORT={{internal_port}}
  APP_STATIC_LOCATION="/static"

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = {{internal_port}}
  processes = ["app"]
  protocol = "tcp"
  script_checks = []

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

我们假设你的朋友想要复制这个配置,他很高兴有一个 username.com。那么,你的朋友可以获取你的配置的压缩包,并运行...

rhep -g config/**/*.toml -d my_config -s "{{" -e "}}" -r username=foobar -r internal_port=8080

Et voilà,他们将得到(包括匹配该通配符的其他 TOML 文件中的替换)...

app = "foobar-app"

kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[build]
  image = "repo/the-app"

[env]
  APP_URI="https://app.foobar.com"
  APP_SERVER_PORT=8080
  APP_STATIC_LOCATION="/static"

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 8080
  processes = ["app"]
  protocol = "tcp"
  script_checks = []

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

测试

是的,还没有。

许可证

Copyright (c) 2022 Aaron Roney

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

依赖项

~6MB
~107K SLoC