提交 795c7c26 authored 作者: Serhij S's avatar Serhij S

rflow serve fixes, tests

上级 5e6638eb
...@@ -52,7 +52,7 @@ pub enum SubCommand { ...@@ -52,7 +52,7 @@ pub enum SubCommand {
pub struct NewCommand { pub struct NewCommand {
#[clap(help = "Project name")] #[clap(help = "Project name")]
pub name: String, pub name: String,
#[clap(long, help = "RoboPLC crate features")] #[clap(short = 'F', long, help = "RoboPLC crate features")]
pub features: Vec<String>, pub features: Vec<String>,
#[clap(last(true), help = "extra cargo arguments")] #[clap(last(true), help = "extra cargo arguments")]
pub extras: Vec<String>, pub extras: Vec<String>,
......
...@@ -34,8 +34,8 @@ pub fn create( ...@@ -34,8 +34,8 @@ pub fn create(
robo_features.push(feature); robo_features.push(feature);
} }
} }
add_dependency("roboplc", &robo_features)?; add_dependency("roboplc", &robo_features, env::var("ROBOPLC_PATH").ok())?;
add_dependency("tracing", &["log"])?; add_dependency("tracing", &["log"], None)?;
let robo_toml = Config { let robo_toml = Config {
remote: config::Remote { remote: config::Remote {
key: maybe_key, key: maybe_key,
...@@ -51,10 +51,17 @@ pub fn create( ...@@ -51,10 +51,17 @@ pub fn create(
Ok(()) Ok(())
} }
fn add_dependency(name: &str, features: &[&str]) -> Result<(), Box<dyn std::error::Error>> { fn add_dependency(
name: &str,
features: &[&str],
path: Option<String>,
) -> Result<(), Box<dyn std::error::Error>> {
println!("Adding dependency: {}", name.green().bold()); println!("Adding dependency: {}", name.green().bold());
let mut cmd = std::process::Command::new("cargo"); let mut cmd = std::process::Command::new("cargo");
cmd.arg("-q").arg("add").arg(name); cmd.arg("-q").arg("add").arg(name);
if let Some(path) = path {
cmd.arg("--path").arg(path);
}
for feature in features { for feature in features {
cmd.arg("--features").arg(feature); cmd.arg("--features").arg(feature);
} }
...@@ -67,7 +74,7 @@ fn add_dependency(name: &str, features: &[&str]) -> Result<(), Box<dyn std::erro ...@@ -67,7 +74,7 @@ fn add_dependency(name: &str, features: &[&str]) -> Result<(), Box<dyn std::erro
#[allow(clippy::let_and_return)] #[allow(clippy::let_and_return)]
fn prepare_main(tpl: &str, features: &[&str]) -> String { fn prepare_main(tpl: &str, features: &[&str]) -> String {
/// METRICS // METRICS
let mut out = if features.contains(&"metrics") { let mut out = if features.contains(&"metrics") {
tpl.replace( tpl.replace(
" // METRICS", " // METRICS",
...@@ -78,7 +85,7 @@ fn prepare_main(tpl: &str, features: &[&str]) -> String { ...@@ -78,7 +85,7 @@ fn prepare_main(tpl: &str, features: &[&str]) -> String {
} else { } else {
tpl.replace(" // METRICS\n", "") tpl.replace(" // METRICS\n", "")
}; };
/// RVIDEO // RVIDEO
out = if features.contains(&"rvideo") { out = if features.contains(&"rvideo") {
out.replace( out.replace(
"// RVIDEO-SERVE", "// RVIDEO-SERVE",
...@@ -109,7 +116,7 @@ impl Worker<Message, Variables> for RvideoSrv { ...@@ -109,7 +116,7 @@ impl Worker<Message, Variables> for RvideoSrv {
#[worker_opts(cpu = 0, priority = 50, scheduling = "fifo", blocking = true)] #[worker_opts(cpu = 0, priority = 50, scheduling = "fifo", blocking = true)]
struct RflowSrv {} struct RflowSrv {}
impl Worker<Message, Variables> for RvideoSrv { impl Worker<Message, Variables> for RflowSrv {
fn run(&mut self, _context: &Context<Message, Variables>) -> WResult { fn run(&mut self, _context: &Context<Message, Variables>) -> WResult {
roboplc::serve_rflow().map_err(Into::into) roboplc::serve_rflow().map_err(Into::into)
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论