-
Notifications
You must be signed in to change notification settings - Fork 147
List Subcommand (Implementation) #3523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
f54c0f3
standalone list command
67ed073
more concise pretty output
4ace776
json output
b903473
use standalone project instead
b412d06
clippy
bc802a1
refactor
bfd2684
cargo list
8e4efc0
use CrateItems instead; refactor into kani-middle
2e79fbc
add std flag
b1c5a9e
output updates
ced1dab
update RFC with implementation
c98b0b0
nits
b57e47d
add tests
6a659d0
add modifies rationale to rfc
d88a4aa
Merge branch 'main' into list-subcommand
87328bc
copyrights
0e14cd1
Merge branch 'list-subcommand' of github.com:carolynzech/kani into li…
e41c2b6
kani-compiler is list-agnostic
5d0edb8
check explicitly that fn resolves
e5de12c
change tests to json; sort output
7a52503
clippy
552f339
Merge branch 'main' into list-subcommand
7383445
clippy
55c9937
revert unnecessary changes
a85ec2c
update rfc
76365a3
Merge branch 'main' into list-subcommand
b5f48a1
update RFC status
a2a5082
Merge branch 'main' into list-subcommand
0854cb3
update Cargo.lock
7faeb2a
remove cli-table dependency; print manually
15dd78a
add Markdown explanation to RFc
3f583d3
remove contracts count; reduce rfc detail
9daa8ba
use StableDefId
cfc1db3
Doc comments formatting
3380cb8
PR feedback
e3455c0
Apply RFC suggestions from code review
2ad1360
Apply suggestions from code review
1cc50a0
remove contracts count mention from RFC
c2474e3
rfc nit
5d536c1
Merge branch 'main' into list-subcommand
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| // Copyright Kani Contributors | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| //! Implements the subcommand handling of the list subcommand | ||
|
|
||
| use std::path::PathBuf; | ||
|
|
||
| use crate::args::ValidateArgs; | ||
| use clap::{Error, Parser, ValueEnum, error::ErrorKind}; | ||
| use kani_metadata::UnstableFeature; | ||
|
|
||
| use super::VerificationArgs; | ||
|
|
||
| /// List information relevant to verification | ||
| #[derive(Debug, Parser)] | ||
| pub struct CargoListArgs { | ||
| #[command(flatten)] | ||
| pub verify_opts: VerificationArgs, | ||
|
|
||
| /// Output format | ||
| #[clap(long, default_value = "pretty")] | ||
| pub format: Format, | ||
| } | ||
|
|
||
| /// List information relevant to verification | ||
| #[derive(Debug, Parser)] | ||
| pub struct StandaloneListArgs { | ||
| /// Rust file to verify | ||
| #[arg(required = true)] | ||
| pub input: PathBuf, | ||
|
|
||
| #[arg(long, hide = true)] | ||
| pub crate_name: Option<String>, | ||
|
|
||
| #[command(flatten)] | ||
| pub verify_opts: VerificationArgs, | ||
|
|
||
| /// Output format | ||
| #[clap(long, default_value = "pretty")] | ||
| pub format: Format, | ||
|
|
||
| /// Pass this flag to run the `list` command on the standard library. | ||
| /// Ensure that the provided `path` is the `library` folder. | ||
| #[arg(long)] | ||
| pub std: bool, | ||
| } | ||
|
|
||
| /// Message formats available for the subcommand. | ||
| #[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum, strum_macros::Display)] | ||
| #[strum(serialize_all = "kebab-case")] | ||
| pub enum Format { | ||
| /// Print diagnostic messages in a user friendly format. | ||
| Pretty, | ||
| /// Print diagnostic messages in JSON format. | ||
| Json, | ||
| } | ||
|
|
||
| impl ValidateArgs for CargoListArgs { | ||
| fn validate(&self) -> Result<(), Error> { | ||
| self.verify_opts.validate()?; | ||
| if !self.verify_opts.common_args.unstable_features.contains(UnstableFeature::List) { | ||
| return Err(Error::raw( | ||
| ErrorKind::MissingRequiredArgument, | ||
| "The `list` subcommand is unstable and requires -Z list", | ||
| )); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl ValidateArgs for StandaloneListArgs { | ||
| fn validate(&self) -> Result<(), Error> { | ||
| self.verify_opts.validate()?; | ||
| if !self.verify_opts.common_args.unstable_features.contains(UnstableFeature::List) { | ||
| return Err(Error::raw( | ||
| ErrorKind::MissingRequiredArgument, | ||
| "The `list` subcommand is unstable and requires -Z list", | ||
| )); | ||
| } | ||
|
|
||
| if self.std { | ||
| if !self.input.exists() { | ||
| Err(Error::raw( | ||
| ErrorKind::InvalidValue, | ||
| format!( | ||
| "Invalid argument: `<input>` argument `{}` does not exist", | ||
| self.input.display() | ||
| ), | ||
| )) | ||
| } else if !self.input.is_dir() { | ||
| Err(Error::raw( | ||
| ErrorKind::InvalidValue, | ||
| format!( | ||
| "Invalid argument: `<input>` argument `{}` is not a directory", | ||
| self.input.display() | ||
| ), | ||
| )) | ||
| } else { | ||
| let full_path = self.input.canonicalize()?; | ||
| let dir = full_path.file_stem().unwrap(); | ||
| if dir != "library" { | ||
| Err(Error::raw( | ||
| ErrorKind::InvalidValue, | ||
| format!( | ||
| "Invalid argument: Expected `<input>` to point to the `library` folder \ | ||
| containing the standard library crates.\n\ | ||
| Found `{}` folder instead", | ||
| dir.to_string_lossy() | ||
| ), | ||
| )) | ||
| } else { | ||
| Ok(()) | ||
| } | ||
| } | ||
| } else if self.input.is_file() { | ||
| Ok(()) | ||
| } else { | ||
| Err(Error::raw( | ||
| ErrorKind::InvalidValue, | ||
| format!( | ||
| "Invalid argument: Input invalid. `{}` is not a regular file.", | ||
| self.input.display() | ||
| ), | ||
| )) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.