| 105 | |
| 106 | #[tokio::main] |
| 107 | async fn main() -> Result<()> { |
| 108 | let cli = Cli::parse(); |
| 109 | config::load(Path::new(&cli.config))?; |
| 110 | |
| 111 | let conf = config::get(); |
| 112 | let filter = filter::Targets::new().with_targets(vec![ |
| 113 | ("chirpstack", Level::from_str(&conf.logging.level).unwrap()), |
| 114 | ("backend", Level::from_str(&conf.logging.level).unwrap()), |
| 115 | ("lrwn", Level::from_str(&conf.logging.level).unwrap()), |
| 116 | ]); |
| 117 | if conf.logging.json { |
| 118 | tracing_subscriber::registry() |
| 119 | .with( |
| 120 | tracing_subscriber::fmt::layer() |
| 121 | .json() |
| 122 | .flatten_event(conf.logging.flatten_json), |
| 123 | ) |
| 124 | .with(filter) |
| 125 | .init(); |
| 126 | } else { |
| 127 | tracing_subscriber::registry() |
| 128 | .with(tracing_subscriber::fmt::layer()) |
| 129 | .with(filter) |
| 130 | .init(); |
| 131 | } |
| 132 | |
| 133 | match &cli.command { |
| 134 | Some(Commands::Configfile {}) => cmd::configfile::run(), |
| 135 | Some(Commands::PrintDs { dev_eui }) => { |
| 136 | let dev_eui = EUI64::from_str(dev_eui).unwrap(); |
| 137 | cmd::print_ds::run(&dev_eui).await.unwrap(); |
| 138 | } |
| 139 | Some(Commands::ImportDeviceProfiles { dir }) => { |
| 140 | cmd::import_device_profiles::run(Path::new(&dir)) |
| 141 | .await |
| 142 | .unwrap() |
| 143 | } |
| 144 | Some(Commands::CreateApiKey { name }) => cmd::create_api_key::run(name).await?, |
| 145 | Some(Commands::SetPassword { |
| 146 | email, |
| 147 | password_file, |
| 148 | stdin, |
| 149 | }) => cmd::set_password::run(email, password_file, *stdin).await?, |
| 150 | Some(Commands::MigrateDeviceSessionsToPostgres {}) => cmd::migrate_ds_to_pg::run().await?, |
| 151 | Some(Commands::MigrateDeviceProfileTemplates {}) => { |
| 152 | cmd::migrate_device_profile_templates::run().await? |
| 153 | } |
| 154 | Some(Commands::MigrateDeviceGatewayRxInfo {}) => { |
| 155 | cmd::migrate_device_gateway_rx_info::run().await? |
| 156 | } |
| 157 | None => cmd::root::run().await?, |
| 158 | } |
| 159 | |
| 160 | Ok(()) |
| 161 | } |