Skip to content

Commit

Permalink
Comment changes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
ksew1 committed Jul 26, 2024
1 parent 234caaf commit 64283a0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
6 changes: 2 additions & 4 deletions scarb/src/bin/scarb/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use scarb::core::Config;
use scarb::ops::{self, VersionControl};

use crate::args::{InitArgs, TestRunner};
use crate::interactive::ask_for_test_runner;
use crate::interactive::get_or_ask_for_test_runner;

#[tracing::instrument(skip_all, level = "info")]
pub fn run(args: InitArgs, config: &Config) -> Result<()> {
Expand All @@ -26,9 +26,7 @@ pub fn run(args: InitArgs, config: &Config) -> Result<()> {
VersionControl::Git
},
snforge: matches!(
Ok(args.test_runner)
.transpose()
.unwrap_or_else(ask_for_test_runner)?,
get_or_ask_for_test_runner(args.test_runner)?,
TestRunner::StarknetFoundry
),
},
Expand Down
6 changes: 2 additions & 4 deletions scarb/src/bin/scarb/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use scarb::core::Config;
use scarb::ops::{self, VersionControl};

use crate::args::{NewArgs, TestRunner};
use crate::interactive::ask_for_test_runner;
use crate::interactive::get_or_ask_for_test_runner;

#[tracing::instrument(skip_all, level = "info")]
pub fn run(args: NewArgs, config: &Config) -> Result<()> {
Expand All @@ -20,9 +20,7 @@ pub fn run(args: NewArgs, config: &Config) -> Result<()> {
VersionControl::Git
},
snforge: matches!(
Ok(args.init.test_runner)
.transpose()
.unwrap_or_else(ask_for_test_runner)?,
get_or_ask_for_test_runner(args.init.test_runner)?,
TestRunner::StarknetFoundry
),
},
Expand Down
14 changes: 12 additions & 2 deletions scarb/src/bin/scarb/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ use crate::args::TestRunner;
use anyhow::{ensure, Result};
use dialoguer::theme::ColorfulTheme;
use dialoguer::Select;
use indoc::indoc;
use which::which;

pub fn ask_for_test_runner() -> Result<TestRunner> {
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(),
"You are not running in terminal. Please provide the --test-runner flag."
indoc! {r"
you are not running in terminal
help: please provide the --test-runner flag
"}
);

let options = if which("snforge").is_ok() {
Expand Down
14 changes: 8 additions & 6 deletions scarb/tests/new_and_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,10 @@ fn new_interactive_not_in_terminal() {
.current_dir(&pt)
.assert()
.failure()
.stdout_eq(indoc! {r#"
error: You are not running in terminal. Please provide the --test-runner flag.
"#});
.stdout_eq(indoc! {r"
error: you are not running in terminal
help: please provide the --test-runner flag
"});
}

#[test]
Expand All @@ -174,9 +175,10 @@ fn init_interactive_not_in_terminal() {
.current_dir(&t)
.assert()
.failure()
.stdout_eq(indoc! {r#"
error: You are not running in terminal. Please provide the --test-runner flag.
"#});
.stdout_eq(indoc! {r"
error: you are not running in terminal
help: please provide the --test-runner flag
"});
}

#[test]
Expand Down

0 comments on commit 64283a0

Please sign in to comment.