1 /* 2 * Copyright (C) 2024 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.cli.common 18 19 import com.android.tools.metalava.reporter.Baseline 20 import com.github.ajalt.clikt.parameters.groups.OptionGroup 21 import com.github.ajalt.clikt.parameters.options.flag 22 import com.github.ajalt.clikt.parameters.options.option 23 24 const val ARG_DELETE_EMPTY_BASELINES = "--delete-empty-baselines" 25 const val ARG_PASS_BASELINE_UPDATES = "--pass-baseline-updates" 26 27 /** The name of the group, can be used in help text to refer to the options in this group. */ 28 const val BASELINE_OPTIONS_GROUP = "Baseline Files" 29 30 class CommonBaselineOptions( 31 sourceOptions: SourceOptions = SourceOptions(), 32 issueReportingOptions: IssueReportingOptions = IssueReportingOptions(), 33 ) : 34 OptionGroup( 35 name = BASELINE_OPTIONS_GROUP, 36 help = 37 """ 38 Options that provide general control over baseline files. 39 """ 40 .trimIndent() 41 ) { 42 private val deleteEmptyBaselines by 43 option( 44 ARG_DELETE_EMPTY_BASELINES, 45 help = 46 """ 47 If true, if after updating a baseline file is empty then it will be deleted. 48 """ 49 .trimIndent() 50 ) 51 .flag() 52 53 internal val baselineConfig by <lambda>null54 lazy(LazyThreadSafetyMode.NONE) { 55 Baseline.Config( 56 issueConfiguration = issueReportingOptions.issueConfiguration, 57 deleteEmptyBaselines = deleteEmptyBaselines, 58 sourcePath = sourceOptions.sourcePath, 59 ) 60 } 61 62 /** If updating baselines, don't fail the build */ 63 internal val passBaselineUpdates by 64 option( 65 ARG_PASS_BASELINE_UPDATES, 66 help = 67 """ 68 Normally, encountering errors will fail the build, even when updating 69 baselines. This flag will record issues in baseline files but otherwise 70 ignore them so that all the baselines in the source tree can be updated in 71 one go. 72 """ 73 .trimIndent() 74 ) 75 .flag() 76 } 77