MCPcopy Create free account
hub / github.com/PowerShell/DSC / main

Function main

archive/registry/src/main.rs:30–157  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28
29#[allow(clippy::too_many_lines)]
30fn main() {
31 #[cfg(debug_assertions)]
32 check_debug();
33
34 let args = Arguments::parse();
35 let input: Option<String> = if is_tty(Stream::Stdin) {
36 None
37 } else {
38 let mut buffer: Vec<u8> = Vec::new();
39 io::stdin().read_to_end(&mut buffer).unwrap();
40 let input = match String::from_utf8(buffer) {
41 Ok(input) => input,
42 Err(e) => {
43 eprintln!("Invalid UTF-8 sequence: {e}");
44 exit(EXIT_INVALID_INPUT);
45 }
46 };
47 Some(input)
48 };
49
50 let mut config: Registry = Registry::default();
51 // check if input is valid for subcommand
52 match args.subcommand {
53 args::SubCommand::Config { subcommand: _ } => {
54 if let Some(input) = input {
55 config = match serde_json::from_str(&input) {
56 Ok(config) => config,
57 Err(err) => {
58 eprintln!("Error JSON does not match schema: {err}");
59 exit(EXIT_INVALID_INPUT);
60 }
61 };
62 } else {
63 eprintln!("Error: Input JSON via STDIN is required for config subcommand.");
64 exit(EXIT_INVALID_PARAMETER);
65 }
66 }
67 _ => {
68 if input.is_some() && !input.as_ref().unwrap().is_empty() {
69 eprintln!("Error: Input JSON via STDIN is only valid for config subcommand: '{}'", input.unwrap());
70 exit(EXIT_INVALID_INPUT);
71 }
72 }
73 }
74
75 match args.subcommand {
76 args::SubCommand::Query { key_path, value_name, recurse } => {
77 eprintln!("Get key_path: {key_path}, value_name: {value_name:?}, recurse: {recurse}");
78 },
79 args::SubCommand::Set { key_path, value } => {
80 eprintln!("Set key_path: {key_path}, value: {value}");
81 },
82 args::SubCommand::Test => {
83 eprintln!("Test");
84 },
85 args::SubCommand::Remove { key_path, value_name, recurse } => {
86 eprintln!("Remove key_path: {key_path}, value_name: {value_name:?}, recurse: {recurse}");
87 },

Callers

nothing calls this directly

Calls 12

check_debugFunction · 0.70
validate_configFunction · 0.70
config_getFunction · 0.70
config_setFunction · 0.70
config_testFunction · 0.70
parseFunction · 0.50
newFunction · 0.50
defaultFunction · 0.50
from_strFunction · 0.50
to_stringFunction · 0.50
is_emptyMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected