提交 c1201541 authored 作者: Serhij S's avatar Serhij S

x.env section

上级 aa2364d6
[package] [package]
name = "roboplc-cli" name = "roboplc-cli"
version = "0.5.0" version = "0.5.1"
edition = "2021" edition = "2021"
authors = ["Serhij S. <div@altertech.com>"] authors = ["Serhij S. <div@altertech.com>"]
license = "Apache-2.0" license = "Apache-2.0"
......
...@@ -10,6 +10,8 @@ pub struct Config { ...@@ -10,6 +10,8 @@ pub struct Config {
pub remote: Remote, pub remote: Remote,
#[serde(default)] #[serde(default)]
pub build: Build, pub build: Build,
#[serde(default)]
pub x: X,
#[serde(default, rename = "build-custom")] #[serde(default, rename = "build-custom")]
pub build_custom: BuildCustom, pub build_custom: BuildCustom,
} }
...@@ -36,6 +38,12 @@ pub struct Build { ...@@ -36,6 +38,12 @@ pub struct Build {
pub cargo_args: Option<String>, pub cargo_args: Option<String>,
} }
#[derive(Deserialize, Serialize, Default, Debug)]
pub struct X {
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub env: BTreeMap<String, String>,
}
#[derive(Deserialize, Serialize, Default, Debug)] #[derive(Deserialize, Serialize, Default, Debug)]
pub struct BuildCustom { pub struct BuildCustom {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
......
use std::{fs, time::Duration}; use std::{collections::btree_map, fs, time::Duration};
use arguments::{Args, SubCommand}; use arguments::{Args, FlashExec, SubCommand};
use clap::Parser; use clap::Parser;
use common::{find_robo_toml, Mode}; use common::{find_robo_toml, Mode};
use once_cell::sync::OnceCell; use once_cell::sync::OnceCell;
...@@ -59,6 +59,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { ...@@ -59,6 +59,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
let mut maybe_timeout = args.timeout; let mut maybe_timeout = args.timeout;
let mut build_config = None; let mut build_config = None;
let mut x_config = None;
let mut build_custom = None; let mut build_custom = None;
if let SubCommand::New(_) = args.subcmd { if let SubCommand::New(_) = args.subcmd {
// do not parse robo.toml for `new` command // do not parse robo.toml for `new` command
...@@ -76,6 +77,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { ...@@ -76,6 +77,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
build_config = Some(robo_toml.build); build_config = Some(robo_toml.build);
build_custom = Some(robo_toml.build_custom); build_custom = Some(robo_toml.build_custom);
x_config = Some(robo_toml.x);
} }
maybe_url = maybe_url.map(|v| { maybe_url = maybe_url.map(|v| {
let mut u = v.trim_end_matches('/').to_owned(); let mut u = v.trim_end_matches('/').to_owned();
...@@ -133,11 +135,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { ...@@ -133,11 +135,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
flashing::rollback(&url, &key, agent, opts)?; flashing::rollback(&url, &key, agent, opts)?;
} }
SubCommand::Exec(opts) => { SubCommand::Exec(opts) => {
let mut opts: FlashExec = opts.into();
if let Some(x_conf) = x_config {
for (k, v) in x_conf.env {
if let btree_map::Entry::Vacant(e) = opts.program_env.entry(k) {
e.insert(v);
}
}
}
flashing::flash( flashing::flash(
&url, &url,
&key, &key,
agent, agent,
opts.into(), opts,
build_config.unwrap_or_default(), build_config.unwrap_or_default(),
build_custom.unwrap_or_default(), build_custom.unwrap_or_default(),
true, true,
......
...@@ -52,6 +52,7 @@ pub fn create( ...@@ -52,6 +52,7 @@ pub fn create(
}, },
build: <_>::default(), build: <_>::default(),
build_custom: <_>::default(), build_custom: <_>::default(),
x: <_>::default(),
}; };
if let Some(docker_arch) = opts.docker { if let Some(docker_arch) = opts.docker {
robo_toml.build.target = Some(docker_arch.target().to_owned()); robo_toml.build.target = Some(docker_arch.target().to_owned());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论