1 /* 2 * Copyright (C) 2025 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 package com.android.tools.metalava 18 19 import com.android.tools.metalava.cli.common.MetalavaCliException 20 import com.android.tools.metalava.cli.common.existingFile 21 import com.android.tools.metalava.config.Config 22 import com.android.tools.metalava.config.ConfigParser 23 import com.github.ajalt.clikt.parameters.groups.OptionGroup 24 import com.github.ajalt.clikt.parameters.options.multiple 25 import com.github.ajalt.clikt.parameters.options.option 26 27 const val ARG_CONFIG_FILE = "--config-file" 28 29 /** The name of the group, can be used in help text to refer to the options in this group. */ 30 const val CONFIG_FILE_OPTIONS_GROUP = "Config Files" 31 32 class ConfigFileOptions : 33 OptionGroup( 34 name = CONFIG_FILE_OPTIONS_GROUP, 35 help = 36 """ 37 Options that control the configuration files. 38 """ 39 .trimIndent(), 40 ) { 41 42 private val configFiles by 43 option( 44 ARG_CONFIG_FILE, 45 help = 46 """ 47 A configuration file that can be consumed by Metalava. This can be specified 48 multiple times in which case later config files will override/merge with 49 earlier ones. 50 """, 51 metavar = "<file>", 52 ) 53 .existingFile() 54 .multiple(required = false) 55 56 /** The [Config] loaded from [configFiles]. */ 57 val config by <lambda>null58 lazy(LazyThreadSafetyMode.NONE) { 59 try { 60 ConfigParser.parse(configFiles) 61 } catch (e: Exception) { 62 throw MetalavaCliException(e.message!!, cause = e) 63 } 64 } 65 } 66