-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reviewed By: AndreasBackx Differential Revision: D64753922 fbshipit-source-id: da331d0b06fdae1943ee4f219fd06c90a443c655
- Loading branch information
1 parent
8c344bc
commit 6fc5c61
Showing
8 changed files
with
121 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,23 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
extern crate scrut; | ||
|
||
mod commands; | ||
mod fb_main_common; | ||
mod utils; | ||
|
||
use anyhow::Result; | ||
use cli::ExitCode; | ||
use fb_main_common::main_impl; | ||
use fb_main_common::Args; | ||
use fbinit::FacebookInit; | ||
|
||
#[cli::main("scrut", error_logging)] | ||
pub fn main(fb: FacebookInit, args: Args) -> Result<ExitCode> { | ||
main_impl(fb, args) | ||
} |
This file contains 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,58 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
use anyhow::anyhow; | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use cli::ExitCode; | ||
use fbinit::FacebookInit; | ||
use scrut::parsers::markdown::MarkdownParserError; | ||
use tracing::error; | ||
|
||
use crate::commands::root::Commands; | ||
use crate::commands::root::GlobalParameters; | ||
use crate::commands::test::ValidationFailedError; | ||
|
||
#[derive(Debug, Parser)] | ||
#[clap( | ||
about = "A testing toolkit to scrutinize CLI applications", | ||
author = "clifoundation" | ||
)] | ||
pub struct Args { | ||
#[clap(subcommand)] | ||
commands: Commands, | ||
|
||
#[clap(flatten)] | ||
global: GlobalParameters, | ||
} | ||
|
||
/// Implemented here because it's only used in `fb-main*.rs`, and so | ||
/// there's little point in exposing it to the OSS version. | ||
pub fn is_user_error(err: &anyhow::Error) -> bool { | ||
if let Some(MarkdownParserError::MissingLanguageSpecifier { .. }) = | ||
err.downcast_ref::<MarkdownParserError>() | ||
{ | ||
return true; | ||
} | ||
false | ||
} | ||
|
||
pub fn main_impl(_fb: FacebookInit, args: Args) -> Result<ExitCode> { | ||
if let Err(err) = args.commands.run() { | ||
if err.downcast_ref::<ValidationFailedError>().is_some() { | ||
return Ok(ExitCode::from(50)); | ||
} | ||
if is_user_error(&err) { | ||
error!("{:?}", err); | ||
Ok(ExitCode::from(1)) | ||
} else { | ||
Err(anyhow!(err)) | ||
} | ||
} else { | ||
Ok(ExitCode::SUCCESS) | ||
} | ||
} |
This file contains 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,23 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
extern crate scrut; | ||
|
||
mod commands; | ||
mod fb_main_common; | ||
mod utils; | ||
|
||
use anyhow::Result; | ||
use cli::ExitCode; | ||
use fb_main_common::main_impl; | ||
use fb_main_common::Args; | ||
use fbinit::FacebookInit; | ||
|
||
#[cli::main("scrut", usage_logging = false)] | ||
pub fn main(fb: FacebookInit, args: Args) -> Result<ExitCode> { | ||
main_impl(fb, args) | ||
} |
This file contains 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 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