xref: /aosp_15_r20/system/usb_info_tools/typec_connector_class_helper/src/main.rs (revision c6808bf1d92d62e809b5d71fe00befd40d32d6f9)
1 // Copyright 2024 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //! main
16 
17 mod typec_class_utils;
18 mod usb_pd_utils;
19 
20 #[cfg(test)]
21 mod typec_class_utils_tests;
22 
23 use anyhow::{anyhow, Result};
24 use std::{env, io::stdout, path::Path};
25 use typec_class_utils::{
26     parse_dirs_and_execute, print_port_info, OutputWriter, PORT_REGEX, TYPEC_SYSFS_PATH,
27 };
28 
main() -> Result<()>29 fn main() -> Result<()> {
30     logger::init(
31         logger::Config::default()
32             .with_tag_on_device("usb_info")
33             .with_max_level(log::LevelFilter::Info),
34     );
35 
36     let args: Vec<String> = env::args().collect();
37     if args.len() > 1 {
38         return Err(anyhow!("typec_connector_class_helper does not accept any arguments."));
39     }
40 
41     let mut out_writer = OutputWriter::new(stdout(), 0);
42     parse_dirs_and_execute(
43         Path::new(TYPEC_SYSFS_PATH),
44         &mut out_writer,
45         PORT_REGEX,
46         print_port_info,
47     )
48 }
49