-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make scarb new and init command interactive (#1472)
Closes #1207 Closes [#1982](foundry-rs/starknet-foundry#1982) Make scarb new and init command interactive
- Loading branch information
Showing
13 changed files
with
123 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,45 @@ | ||
use std::io::{self, IsTerminal}; | ||
|
||
use crate::args::TestRunner; | ||
use anyhow::{ensure, Result}; | ||
use dialoguer::theme::ColorfulTheme; | ||
use dialoguer::Select; | ||
use indoc::indoc; | ||
use which::which; | ||
|
||
pub fn get_or_ask_for_test_runner(test_runner: Option<TestRunner>) -> Result<TestRunner> { | ||
Ok(test_runner) | ||
.transpose() | ||
.unwrap_or_else(ask_for_test_runner) | ||
} | ||
|
||
fn ask_for_test_runner() -> Result<TestRunner> { | ||
ensure!( | ||
io::stdout().is_terminal(), | ||
indoc! {r" | ||
you are not running in terminal | ||
help: please provide the --test-runner flag | ||
"} | ||
); | ||
|
||
let options = if which("snforge").is_ok() { | ||
vec!["Starknet Foundry (default)", "Cairo Test"] | ||
} else { | ||
vec![ | ||
"Cairo Test (default)", | ||
"Starknet Foundry (recommended, requires snforge installed: https://github.com/foundry-rs/starknet-foundry)", | ||
] | ||
}; | ||
|
||
let selection = Select::with_theme(&ColorfulTheme::default()) | ||
.with_prompt("Which test runner do you want to set up?") | ||
.items(&options) | ||
.default(0) | ||
.interact()?; | ||
|
||
if options[selection].starts_with("Cairo Test") { | ||
Ok(TestRunner::CairoTest) | ||
} else { | ||
Ok(TestRunner::StarknetFoundry) | ||
} | ||
} |
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