|
| 1 | +// Copyright Kani Contributors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 OR MIT |
| 3 | +//! Define arguments that should be common to all subcommands in Kani. |
| 4 | +use crate::args::ValidateArgs; |
| 5 | +use clap::{error::Error, error::ErrorKind, ValueEnum}; |
| 6 | + |
| 7 | +/// Common Kani arguments that we expect to be included in most subcommands. |
| 8 | +#[derive(Debug, clap::Args)] |
| 9 | +pub struct CommonArgs { |
| 10 | + /// Produce full debug information |
| 11 | + #[arg(long)] |
| 12 | + pub debug: bool, |
| 13 | + /// Produces no output, just an exit code and requested artifacts; overrides --verbose |
| 14 | + #[arg(long, short, conflicts_with_all(["debug", "verbose"]))] |
| 15 | + pub quiet: bool, |
| 16 | + /// Output processing stages and commands, along with minor debug information |
| 17 | + #[arg(long, short, default_value_if("debug", "true", Some("true")))] |
| 18 | + pub verbose: bool, |
| 19 | + /// Enable usage of unstable options |
| 20 | + #[arg(long, hide_short_help = true)] |
| 21 | + pub enable_unstable: bool, |
| 22 | + |
| 23 | + /// We no longer support dry-run. Use `--verbose` to see the commands being printed during |
| 24 | + /// Kani execution. |
| 25 | + #[arg(long, hide = true)] |
| 26 | + pub dry_run: bool, |
| 27 | + |
| 28 | + /// Enable an unstable feature. |
| 29 | + #[arg(short = 'Z', num_args(1), value_name = "UNSTABLE_FEATURE")] |
| 30 | + pub unstable_features: Vec<UnstableFeatures>, |
| 31 | +} |
| 32 | + |
| 33 | +#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum, strum_macros::Display)] |
| 34 | +#[strum(serialize_all = "kebab-case")] |
| 35 | +pub enum UnstableFeatures { |
| 36 | + /// Allow replacing certain items with stubs (mocks). |
| 37 | + /// See [RFC-0002](https://model-checking.github.io/kani/rfc/rfcs/0002-function-stubbing.html) |
| 38 | + Stubbing, |
| 39 | + /// Generate a C-like file equivalent to input program used for debugging purpose. |
| 40 | + GenC, |
| 41 | + /// Allow Kani to link against C code. |
| 42 | + CFfi, |
| 43 | + /// Enable concrete playback flow. |
| 44 | + ConcretePlayback, |
| 45 | +} |
| 46 | + |
| 47 | +impl ValidateArgs for CommonArgs { |
| 48 | + fn validate(&self) -> Result<(), Error> { |
| 49 | + if self.dry_run { |
| 50 | + return Err(Error::raw( |
| 51 | + ErrorKind::ValueValidation, |
| 52 | + "The `--dry-run` option is obsolete. Use --verbose instead.", |
| 53 | + )); |
| 54 | + } |
| 55 | + Ok(()) |
| 56 | + } |
| 57 | +} |
0 commit comments