1#![doc(html_root_url = "https://docs.rs/cargo-sync-rdme/0.4.3")]
17#![warn(
18 elided_lifetimes_in_paths,
19 explicit_outlives_requirements,
20 keyword_idents,
21 missing_copy_implementations,
22 missing_debug_implementations,
23 missing_docs,
24 single_use_lifetimes,
25 unreachable_pub,
26 unused
27)]
28
29use std::{env, io};
30
31use clap::Parser;
32use tracing::Level;
33use tracing_subscriber::EnvFilter;
34
35#[macro_use]
36mod macros;
37
38mod cli;
39mod config;
40mod diff;
41mod sync;
42mod traits;
43mod vcs;
44mod with_source;
45
46pub use self::cli::App;
47
48pub type Error = miette::Error;
50
51pub type Result<T> = miette::Result<T>;
53
54pub fn main() -> Result<()> {
56 let args = env::args().enumerate().filter_map(|(idx, arg)| {
59 if idx == 1 && arg == "sync-rdme" {
60 None
61 } else {
62 Some(arg)
63 }
64 });
65 let app = App::parse_from(args);
66 install_logger(app.verbosity.into())?;
67
68 let workspace = app.workspace.metadata()?;
69 for package in app.package.packages(&workspace)? {
70 sync::sync_all(&app, &workspace, package)?;
71 }
72
73 Ok(())
74}
75
76fn install_logger(verbosity: Option<Level>) -> Result<()> {
77 if env::var_os("RUST_LOG").is_none() {
78 match verbosity {
79 Some(Level::ERROR) => env::set_var("RUST_LOG", "error"),
80 Some(Level::WARN) => env::set_var("RUST_LOG", "warn"),
81 Some(Level::INFO) => env::set_var("RUST_LOG", "info"),
82 Some(Level::DEBUG) => env::set_var("RUST_LOG", "debug"),
83 Some(Level::TRACE) => env::set_var("RUST_LOG", "trace"),
84 None => env::set_var("RUST_LOG", "off"),
85 }
86 }
87
88 tracing_subscriber::fmt()
89 .with_env_filter(EnvFilter::from_default_env())
90 .with_writer(io::stderr)
91 .with_target(false)
92 .try_init()
93 .map_err(|e| miette!(e))?;
94
95 Ok(())
96}