提交 0491168a authored 作者: Serhij S's avatar Serhij S

.robo-global.toml

上级 66a4778c
......@@ -155,6 +155,27 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "dirs"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
dependencies = [
"libc",
"option-ext",
"redox_users",
"windows-sys 0.48.0",
]
[[package]]
name = "errno"
version = "0.3.8"
......@@ -162,7 +183,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
dependencies = [
"libc",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
......@@ -261,7 +282,7 @@ checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b"
dependencies = [
"hermit-abi",
"libc",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
......@@ -282,6 +303,16 @@ version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "libredox"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
dependencies = [
"bitflags 2.5.0",
"libc",
]
[[package]]
name = "linux-raw-sys"
version = "0.4.13"
......@@ -402,6 +433,12 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
name = "percent-encoding"
version = "2.3.1"
......@@ -468,6 +505,17 @@ dependencies = [
"getrandom",
]
[[package]]
name = "redox_users"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891"
dependencies = [
"getrandom",
"libredox",
"thiserror",
]
[[package]]
name = "ring"
version = "0.17.8"
......@@ -480,16 +528,17 @@ dependencies = [
"libc",
"spin",
"untrusted",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
name = "roboplc-cli"
version = "0.1.18"
version = "0.1.19"
dependencies = [
"ansi_term",
"clap",
"colored",
"dirs",
"serde",
"serde_json",
"shlex",
......@@ -515,7 +564,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
......@@ -584,7 +633,7 @@ version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534"
dependencies = [
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
......@@ -685,7 +734,7 @@ dependencies = [
"cfg-if",
"fastrand",
"rustix",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
......@@ -697,6 +746,26 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "thiserror"
version = "1.0.59"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.59"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tinyvec"
version = "1.6.0"
......@@ -869,13 +938,37 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
"windows-targets 0.52.5",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5",
"windows_i686_msvc 0.48.5",
"windows_x86_64_gnu 0.48.5",
"windows_x86_64_gnullvm 0.48.5",
"windows_x86_64_msvc 0.48.5",
]
[[package]]
......@@ -884,28 +977,46 @@ version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_aarch64_gnullvm 0.52.5",
"windows_aarch64_msvc 0.52.5",
"windows_i686_gnu 0.52.5",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
"windows_i686_msvc 0.52.5",
"windows_x86_64_gnu 0.52.5",
"windows_x86_64_gnullvm 0.52.5",
"windows_x86_64_msvc 0.52.5",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_gnu"
version = "0.52.5"
......@@ -918,24 +1029,48 @@ version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_i686_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.5"
......
[package]
name = "roboplc-cli"
version = "0.1.18"
version = "0.1.19"
edition = "2021"
authors = ["Serhij S. <div@altertech.com>"]
license = "Apache-2.0"
......@@ -16,6 +16,7 @@ path = "src/main.rs"
[dependencies]
clap = { version = "=4.1", features = ["derive", "env"] }
colored = "1"
dirs = "5.0.1"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.115"
shlex = "1.3.0"
......
......@@ -9,9 +9,19 @@ use clap::Parser;
pub struct Args {
#[clap(short = 'T', long, help = "Manager API timeout")]
pub timeout: Option<u64>,
#[clap(short = 'U', long, env = "ROBOPLC_URL", help = "Manager URL")]
#[clap(
short = 'U',
long,
env = "ROBOPLC_URL",
help = "Manager URL or a system"
)]
pub url: Option<String>,
#[clap(short = 'k', long, env = "ROBOPLC_KEY", help = "Management key")]
#[clap(
short = 'k',
long,
env = "ROBOPLC_KEY",
help = "Management key, if required"
)]
pub key: Option<String>,
#[clap(subcommand)]
pub subcmd: SubCommand,
......
......@@ -5,6 +5,11 @@ use colored::Colorize;
use serde::{Deserialize, Serialize};
pub const CONFIG_FILE_NAME: &str = "robo.toml";
pub const GLOBAL_CONFIG_FILE_NAME: &str = ".robo-global.toml";
pub fn print_err(msg: &str) {
eprintln!("{}", msg.red());
}
#[derive(Debug, Serialize, Deserialize)]
pub struct State {
......
use std::path::PathBuf;
use std::{collections::BTreeMap, fs, path::PathBuf};
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize)]
use crate::common::{print_err, GLOBAL_CONFIG_FILE_NAME};
#[derive(Deserialize, Serialize, Debug)]
pub struct Config {
#[serde(default)]
pub remote: Remote,
......@@ -10,7 +12,7 @@ pub struct Config {
pub build: Build,
}
#[derive(Deserialize, Serialize, Default)]
#[derive(Deserialize, Serialize, Default, Debug)]
pub struct Remote {
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
......@@ -20,7 +22,7 @@ pub struct Remote {
pub timeout: Option<u64>,
}
#[derive(Deserialize, Serialize, Default)]
#[derive(Deserialize, Serialize, Default, Debug)]
pub struct Build {
#[serde(skip_serializing_if = "Option::is_none")]
pub cargo: Option<PathBuf>,
......@@ -29,3 +31,37 @@ pub struct Build {
#[serde(skip_serializing_if = "Option::is_none")]
pub cargo_args: Option<String>,
}
#[derive(Deserialize, Debug)]
struct GlobalConfig {
remote: BTreeMap<String, Remote>,
}
pub fn get_global_remote(url: &str) -> Option<Remote> {
let Some(home) = dirs::home_dir() else {
print_err("Cannot get home directory");
return None;
};
let path = home.join(GLOBAL_CONFIG_FILE_NAME);
if !path.exists() {
return None;
}
match fs::read_to_string(&path) {
Ok(contents) => match toml::from_str::<GlobalConfig>(&contents) {
Ok(mut config) => {
if let Some(remote) = config.remote.remove(url) {
return Some(remote);
}
None
}
Err(e) => {
print_err(&format!("Cannot parse {}: {}", path.display(), e));
None
}
},
Err(e) => {
print_err(&format!("Cannot read {}: {}", path.display(), e));
None
}
}
}
......@@ -25,6 +25,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();
let mut maybe_url = args.url;
let mut maybe_key = args.key;
if let Some(ref u) = maybe_url {
if !u.starts_with("http://") && !u.starts_with("https://") {
// try to get url from global config
if let Some(remote) = config::get_global_remote(u) {
maybe_url = remote.url;
maybe_key = remote.key;
}
}
}
let mut maybe_timeout = args.timeout;
let mut build_config = None;
if let SubCommand::New(_) = args.subcmd {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论