update cli
This commit is contained in:
parent
6daa913c68
commit
dc9a5ddad2
486
Cargo.lock
generated
486
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
2
external/cursive
vendored
2
external/cursive
vendored
@ -1 +1 @@
|
||||
Subproject commit 74c9d6977af86b2a57d4415c71eacda26f28c6b4
|
||||
Subproject commit f29f750aade5a669d90ac9ea3a96e8299c4c66c0
|
2
external/cursive-flexi-logger-view
vendored
2
external/cursive-flexi-logger-view
vendored
@ -1 +1 @@
|
||||
Subproject commit 1e1542b1bb45ba590e604cb9904ef08e5e6bd55d
|
||||
Subproject commit a1ff362346bd93955d9126893e4f6afb21f00881
|
2
external/cursive_buffered_backend
vendored
2
external/cursive_buffered_backend
vendored
@ -1 +1 @@
|
||||
Subproject commit 5a093be753db1251c2451e7e0e55d548af4abe1d
|
||||
Subproject commit c4a7301b865d5af525fad30e76c2c5d121189943
|
@ -23,23 +23,23 @@ cursive_buffered_backend = { path = "../external/cursive_buffered_backend" }
|
||||
# cursive-tabs = "0.5.0"
|
||||
clap = "^3"
|
||||
directories = "^4"
|
||||
log = "^0.4"
|
||||
futures = "^0.3"
|
||||
serde = "^1.0.122"
|
||||
serde_derive = "^1.0.122"
|
||||
parking_lot = "^0.11"
|
||||
log = "^0"
|
||||
futures = "^0"
|
||||
serde = "^1"
|
||||
serde_derive = "^1"
|
||||
parking_lot = "^0"
|
||||
cfg-if = "^1"
|
||||
capnp = "^0.14"
|
||||
capnp-rpc = "^0.14"
|
||||
config = { version = "0.10.1", features = ["yaml"] }
|
||||
bugsalot = "^0.2"
|
||||
flexi_logger = "0.17"
|
||||
thiserror = "^1.0"
|
||||
crossbeam-channel = "0.5"
|
||||
capnp = "^0"
|
||||
capnp-rpc = "^0"
|
||||
config = { version = "^0", features = ["yaml"] }
|
||||
bugsalot = "^0"
|
||||
flexi_logger = "^0"
|
||||
thiserror = "^1"
|
||||
crossbeam-channel = "^0"
|
||||
veilid-core = { path = "../veilid-core" }
|
||||
|
||||
[dev-dependencies]
|
||||
serial_test = "^0.4"
|
||||
serial_test = "^0"
|
||||
|
||||
[build-dependencies]
|
||||
capnpc = "^0.14"
|
||||
capnpc = "^0"
|
||||
|
@ -8,6 +8,7 @@ use clap::{Arg, ColorChoice, Command};
|
||||
use flexi_logger::*;
|
||||
use std::ffi::OsStr;
|
||||
use std::net::ToSocketAddrs;
|
||||
use std::path::Path;
|
||||
|
||||
mod client_api_connection;
|
||||
mod command_processor;
|
||||
@ -49,9 +50,9 @@ fn parse_command_line(default_config_path: &OsStr) -> Result<clap::ArgMatches, S
|
||||
Arg::new("config-file")
|
||||
.short('c')
|
||||
.takes_value(true)
|
||||
.allow_invalid_utf8(true)
|
||||
.value_name("FILE")
|
||||
.default_value_os(default_config_path)
|
||||
.allow_invalid_utf8(true)
|
||||
.help("Specify a configuration file to use"),
|
||||
)
|
||||
.get_matches();
|
||||
@ -70,11 +71,18 @@ async fn main() -> Result<(), String> {
|
||||
}
|
||||
|
||||
// Attempt to load configuration
|
||||
let mut settings = settings::Settings::new(
|
||||
matches.occurrences_of("config-file") == 0,
|
||||
matches.value_of_os("config-file").unwrap(),
|
||||
)
|
||||
.map_err(map_to_string)?;
|
||||
let settings_path = if let Some(config_file) = matches.value_of_os("config-file") {
|
||||
if Path::new(config_file).exists() {
|
||||
Some(config_file)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let mut settings = settings::Settings::new(settings_path)
|
||||
.map_err(|e| format!("configuration is invalid: {}", e))?;
|
||||
|
||||
// Set config from command line
|
||||
if matches.occurrences_of("debug") != 0 {
|
||||
@ -108,17 +116,17 @@ async fn main() -> Result<(), String> {
|
||||
std::fs::create_dir_all(settings.logging.file.directory.clone())
|
||||
.map_err(map_to_string)?;
|
||||
logger
|
||||
.log_target(LogTarget::FileAndWriter(flv))
|
||||
.suppress_timestamp()
|
||||
// .format(flexi_logger::colored_default_format)
|
||||
.log_to_file_and_writer(
|
||||
FileSpec::default()
|
||||
.directory(settings.logging.file.directory.clone())
|
||||
.suppress_timestamp(),
|
||||
flv,
|
||||
)
|
||||
.start()
|
||||
.expect("failed to initialize logger!");
|
||||
} else {
|
||||
logger
|
||||
.log_target(LogTarget::Writer(flv))
|
||||
.suppress_timestamp()
|
||||
.format(flexi_logger::colored_default_format)
|
||||
.log_to_writer(flv)
|
||||
.start()
|
||||
.expect("failed to initialize logger!");
|
||||
}
|
||||
@ -126,9 +134,11 @@ async fn main() -> Result<(), String> {
|
||||
std::fs::create_dir_all(settings.logging.file.directory.clone())
|
||||
.map_err(map_to_string)?;
|
||||
logger
|
||||
.log_target(LogTarget::File)
|
||||
.suppress_timestamp()
|
||||
.log_to_file(
|
||||
FileSpec::default()
|
||||
.directory(settings.logging.file.directory.clone())
|
||||
.suppress_timestamp(),
|
||||
)
|
||||
.start()
|
||||
.expect("failed to initialize logger!");
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use std::ffi::OsStr;
|
||||
use std::net::{SocketAddr, ToSocketAddrs};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub fn load_default_config(cfg: &mut config::Config) -> Result<(), config::ConfigError> {
|
||||
pub fn load_default_config() -> Result<config::Config, config::ConfigError> {
|
||||
let default_config = r###"---
|
||||
address: "localhost:5959"
|
||||
autoconnect: true
|
||||
@ -16,7 +16,7 @@ logging:
|
||||
enabled: false
|
||||
file:
|
||||
enabled: true
|
||||
directory: ""
|
||||
directory: "%LOGGING_FILE_DIRECTORY%"
|
||||
append: true
|
||||
interface:
|
||||
node_log:
|
||||
@ -44,21 +44,29 @@ interface:
|
||||
info : "#5cd3c6"
|
||||
warn : "#fedc50"
|
||||
error : "#ff4a15"
|
||||
"###;
|
||||
cfg.merge(config::File::from_str(
|
||||
default_config,
|
||||
"###
|
||||
.replace(
|
||||
"%LOGGING_FILE_DIRECTORY%",
|
||||
&Settings::get_default_log_directory().to_string_lossy(),
|
||||
);
|
||||
|
||||
config::Config::builder()
|
||||
.add_source(config::File::from_str(
|
||||
&default_config,
|
||||
config::FileFormat::Yaml,
|
||||
))
|
||||
.map(drop)
|
||||
.build()
|
||||
}
|
||||
|
||||
pub fn load_config(
|
||||
cfg: &mut config::Config,
|
||||
cfg: config::Config,
|
||||
config_file: &Path,
|
||||
) -> Result<(), config::ConfigError> {
|
||||
) -> Result<config::Config, config::ConfigError> {
|
||||
if let Some(config_file_str) = config_file.to_str() {
|
||||
cfg.merge(config::File::new(config_file_str, config::FileFormat::Yaml))
|
||||
.map(drop)
|
||||
config::Config::builder()
|
||||
.add_source(cfg)
|
||||
.add_source(config::File::new(config_file_str, config::FileFormat::Yaml))
|
||||
.build()
|
||||
} else {
|
||||
Err(config::ConfigError::Message(
|
||||
"config file path is not valid UTF-8".to_owned(),
|
||||
@ -226,38 +234,26 @@ impl Settings {
|
||||
default_log_directory
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
config_file_is_default: bool,
|
||||
config_file: &OsStr,
|
||||
) -> Result<Self, config::ConfigError> {
|
||||
// Create a config
|
||||
let mut cfg = config::Config::default();
|
||||
|
||||
pub fn new(config_file: Option<&OsStr>) -> Result<Self, config::ConfigError> {
|
||||
// Load the default config
|
||||
load_default_config(&mut cfg)?;
|
||||
|
||||
// Use default log directory for logs
|
||||
cfg.set(
|
||||
"logging.file.directory",
|
||||
Settings::get_default_log_directory().to_str(),
|
||||
)?;
|
||||
let mut cfg = load_default_config()?;
|
||||
|
||||
// Merge in the config file if we have one
|
||||
if let Some(config_file) = config_file {
|
||||
let config_file_path = Path::new(config_file);
|
||||
if !config_file_is_default || config_file_path.exists() {
|
||||
// If the user specifies a config file on the command line then it must exist
|
||||
load_config(&mut cfg, config_file_path)?;
|
||||
cfg = load_config(cfg, config_file_path)?;
|
||||
}
|
||||
cfg.try_into()
|
||||
|
||||
// Generate config
|
||||
cfg.try_deserialize()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_config() {
|
||||
let mut cfg = config::Config::default();
|
||||
|
||||
load_default_config(&mut cfg).unwrap();
|
||||
let settings = cfg.try_into::<Settings>().unwrap();
|
||||
let cfg = load_default_config().unwrap();
|
||||
let settings = cfg.try_deserialize::<Settings>().unwrap();
|
||||
|
||||
println!("default settings: {:?}", settings);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ use log::*;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
use veilid_core::*;
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
@ -87,6 +88,12 @@ pub struct UI {
|
||||
inner: Handle<UIInner>,
|
||||
}
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum DumbError {
|
||||
// #[error("{0}")]
|
||||
// Message(String),
|
||||
}
|
||||
|
||||
impl UI {
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private functions
|
||||
@ -642,10 +649,10 @@ impl UI {
|
||||
cursive_flexi_logger_view::resize(node_log_scrollback);
|
||||
|
||||
// Instantiate the cursive runnable
|
||||
/*
|
||||
|
||||
// reduces flicker, but it costs cpu
|
||||
let mut runnable = CursiveRunnable::new(
|
||||
|| -> Result<Box<dyn cursive_buffered_backend::Backend>, UIError> {
|
||||
let runnable = CursiveRunnable::new(
|
||||
|| -> Result<Box<dyn cursive_buffered_backend::Backend>, Box<DumbError>> {
|
||||
let crossterm_backend = cursive::backends::crossterm::Backend::init().unwrap();
|
||||
let buffered_backend =
|
||||
cursive_buffered_backend::BufferedBackend::new(crossterm_backend);
|
||||
@ -653,8 +660,8 @@ impl UI {
|
||||
Ok(Box::new(buffered_backend))
|
||||
},
|
||||
);
|
||||
*/
|
||||
let runnable = cursive::default();
|
||||
//let runnable = cursive::default();
|
||||
|
||||
// Make the callback mechanism easily reachable
|
||||
let cb_sink = runnable.cb_sink().clone();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user