()
| 25 | |
| 26 | #[allow(clippy::too_many_lines)] |
| 27 | fn main() { |
| 28 | #[cfg(debug_assertions)] |
| 29 | check_debug(); |
| 30 | |
| 31 | enable_tracing(); |
| 32 | |
| 33 | let args = Arguments::parse(); |
| 34 | match args.subcommand { |
| 35 | args::SubCommand::Query { key_path, value_name, recurse } => { |
| 36 | debug!("Get key_path: {key_path}, value_name: {value_name:?}, recurse: {recurse}"); |
| 37 | }, |
| 38 | args::SubCommand::Set { key_path, value } => { |
| 39 | debug!("Set key_path: {key_path}, value: {value}"); |
| 40 | }, |
| 41 | args::SubCommand::Remove { key_path, value_name, recurse } => { |
| 42 | debug!("Remove key_path: {key_path}, value_name: {value_name:?}, recurse: {recurse}"); |
| 43 | }, |
| 44 | args::SubCommand::Find { key_path, find, recurse, keys_only, values_only } => { |
| 45 | debug!("Find key_path: {key_path}, find: {find}, recurse: {recurse:?}, keys_only: {keys_only:?}, values_only: {values_only:?}"); |
| 46 | }, |
| 47 | args::SubCommand::Config { subcommand } => { |
| 48 | match subcommand { |
| 49 | args::ConfigSubCommand::Get{input} => { |
| 50 | debug!("Get input: {input}"); |
| 51 | let reg_helper = match RegistryHelper::new_from_json(&input) { |
| 52 | Ok(reg_helper) => reg_helper, |
| 53 | Err(err) => { |
| 54 | error!("{err}"); |
| 55 | exit(EXIT_INVALID_INPUT); |
| 56 | } |
| 57 | }; |
| 58 | match reg_helper.get() { |
| 59 | Ok(reg_config) => { |
| 60 | let json = serde_json::to_string(®_config).unwrap(); |
| 61 | println!("{json}"); |
| 62 | }, |
| 63 | Err(err) => { |
| 64 | error!("{err}"); |
| 65 | exit(EXIT_REGISTRY_ERROR); |
| 66 | } |
| 67 | } |
| 68 | }, |
| 69 | args::ConfigSubCommand::Set{input, what_if} => { |
| 70 | debug!("Set input: {input}, what_if: {what_if}"); |
| 71 | let mut reg_helper = match RegistryHelper::new_from_json(&input) { |
| 72 | Ok(reg_helper) => reg_helper, |
| 73 | Err(err) => { |
| 74 | error!("{err}"); |
| 75 | exit(EXIT_INVALID_INPUT); |
| 76 | } |
| 77 | }; |
| 78 | if what_if { reg_helper.enable_what_if(); } |
| 79 | |
| 80 | // In what-if, if the desired state is _exist: false, route to delete |
| 81 | if what_if |
| 82 | && let Ok(desired) = serde_json::from_str::<Registry>(&input) |
| 83 | && matches!(desired.exist, Some(false)) { |
| 84 | match reg_helper.remove() { |
nothing calls this directly
no test coverage detected