• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 pub mod cpp;
18 pub mod java;
19 pub mod rust;
20 
21 use aconfig_protos::{is_valid_name_ident, is_valid_package_ident};
22 use anyhow::{ensure, Result};
23 use clap::ValueEnum;
24 
create_device_config_ident(package: &str, flag_name: &str) -> Result<String>25 pub fn create_device_config_ident(package: &str, flag_name: &str) -> Result<String> {
26     ensure!(is_valid_package_ident(package), "bad package");
27     ensure!(is_valid_name_ident(flag_name), "bad flag name");
28     Ok(format!("{}.{}", package, flag_name))
29 }
30 
31 #[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum)]
32 pub enum CodegenMode {
33     Exported,
34     ForceReadOnly,
35     Production,
36     Test,
37 }
38 
39 impl std::fmt::Display for CodegenMode {
fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result40     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
41         match self {
42             CodegenMode::Exported => write!(f, "exported"),
43             CodegenMode::ForceReadOnly => write!(f, "force-read-only"),
44             CodegenMode::Production => write!(f, "production"),
45             CodegenMode::Test => write!(f, "test"),
46         }
47     }
48 }
49 
50 #[cfg(test)]
51 mod tests {
52     use super::*;
53     #[test]
test_create_device_config_ident()54     fn test_create_device_config_ident() {
55         assert_eq!(
56             "com.foo.bar.some_flag",
57             create_device_config_ident("com.foo.bar", "some_flag").unwrap()
58         );
59     }
60 }
61