提交 78a56aaa authored 作者: Serhij S's avatar Serhij S

auto add http prefix to urls

上级 45c2e58f
...@@ -1030,7 +1030,7 @@ dependencies = [ ...@@ -1030,7 +1030,7 @@ dependencies = [
[[package]] [[package]]
name = "roboplc-cli" name = "roboplc-cli"
version = "0.1.7" version = "0.1.8"
dependencies = [ dependencies = [
"clap", "clap",
"colored", "colored",
......
[package] [package]
name = "roboplc-cli" name = "roboplc-cli"
version = "0.1.7" version = "0.1.8"
edition = "2021" edition = "2021"
authors = ["Serhij S. <div@altertech.com>"] authors = ["Serhij S. <div@altertech.com>"]
license = "Apache-2.0" license = "Apache-2.0"
......
...@@ -363,7 +363,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { ...@@ -363,7 +363,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
let timeout = timeout.unwrap_or(DEFAULT_TIMEOUT); let timeout = timeout.unwrap_or(DEFAULT_TIMEOUT);
let url_s = url.ok_or("URL not specified")?; let url_s = url.ok_or("URL not specified")?;
let url = url_s.trim_end_matches('/'); let mut url = url_s.trim_end_matches('/').to_owned();
if !url.starts_with("http://") && !url.starts_with("https://") {
url = format!("http://{}", url);
}
let key = key.ok_or("Key not specified")?; let key = key.ok_or("Key not specified")?;
let agent: Agent = ureq::AgentBuilder::new() let agent: Agent = ureq::AgentBuilder::new()
.timeout_read(Duration::from_secs(timeout)) .timeout_read(Duration::from_secs(timeout))
...@@ -371,19 +374,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { ...@@ -371,19 +374,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.build(); .build();
match args.subcmd { match args.subcmd {
SubCommand::Stat => { SubCommand::Stat => {
stat_command(url, &key, agent)?; stat_command(&url, &key, agent)?;
} }
SubCommand::Config => { SubCommand::Config => {
set_mode_command(url, &key, agent, Mode::Config)?; set_mode_command(&url, &key, agent, Mode::Config)?;
} }
SubCommand::Run => { SubCommand::Run => {
set_mode_command(url, &key, agent, Mode::Run)?; set_mode_command(&url, &key, agent, Mode::Run)?;
} }
SubCommand::Flash(opts) => { SubCommand::Flash(opts) => {
flash(url, &key, agent, opts, robo_toml)?; flash(&url, &key, agent, opts, robo_toml)?;
} }
SubCommand::Purge => { SubCommand::Purge => {
purge_command(url, &key, agent)?; purge_command(&url, &key, agent)?;
} }
} }
Ok(()) Ok(())
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论