1 个不稳定发布

0.1.0 2022年7月24日

#278 in 模板引擎

Apache-2.0

31KB
513

Build

🏷️ 保持您的客户最新
🙈 背景运行
⌛ 限制后台任务


upversion

upversion 当新版本发布时通知您的客户,并显示最新的下载链接。

$ ./test-tool
==> 🙆‍♂️ Newer <tool-name> version available: <user-version> (currently running: 0.5.2) | Link: <dynamic-link>

工作原理

upversion 作为后台进程运行,不会影响您的工具性能。

  1. 您可以选择何时显示新版本
  2. 如果您的进程在 upversion 之前完成,则可以跳过消息通知

用法

将此添加到Cargo.toml

[dependencies]
upversion = { version = "0.1" }

供应商

  • GitHub发布
  • 自定义RestAPI

GitHub示例

use anyhow::Result;
use upversion::vendors::GitHubVendor;
use upversion::CheckVersion;

fn main() -> Result<()> {
    let github = Box::new(GitHubVendor::new("kaplanelad", "shellfirm"));
    let timeout = 2; // in seconds
    let version_context = CheckVersion::new("app-name", github, timeout)?;

    // run command execute upversion check in the background and finish immediately.
    version_context.run("0.0.1")?;

    // sleep here simulator your program
    std::thread::sleep(std::time::Duration::from_secs(3));

    // at the end of your program, you can call printstd to print to the STDOUT a alert information for a new version which released
    version_context.printstd();
    Ok(())
}

自定义API

如果您在内部管理程序版本,您可以通过自定义逻辑通过rest API提供新版本,而 upversion 将查询您的端点。

use anyhow::Result;
use upversion::vendors::Api;
use upversion::CheckVersion;

fn main() -> Result<()> {
    // server json response: { "version": "", "release_downloads": [] }
    let api = Box::new(Api::new("http://127.0.0.1:3000"));
    let timeout = 2; // in seconds
    let version_context = CheckVersion::new("app-name", api, timeout)?;

    // run command execute upversion check in the background and finish immediately.
    version_context.run("0.0.1")?;

    // sleep here simulator your program
    std::thread::sleep(std::time::Duration::from_secs(3));

    // at the end of your program, you can call printstd to print to the STDOUT a alert information for a new version which released
    version_context.printstd();
    Ok(())
}

更多示例

您可以在此处找到更多示例,或通过 cargo cargo run --example 运行

自定义模板

使用您自己的模板自定义警报消息

    const CUSTOM_TEMPLATE: &str = r#"==> [CUSTOM_TEMPLATE]:: 🙆‍♂️ Newer {{ app_name }} version available: {{ new_version }} (currently running: {{ current_version }}) {% if download_link %}| Link: {{ download_link }} {% endif %}"#;
    ... 
    version_context.printstd_with_template(CUSTOM_TEMPLATE);

谢谢

感谢所有 贡献者 - 您使这一切成为可能,谢谢!

版权

版权所有(c)2022 @kaplanelad。有关详细信息,请参阅 LICENSE

依赖项

~17–28MB
~444K SLoC