Skip to content
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

fix: unable to set verbosity via number #2993

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
98 changes: 98 additions & 0 deletions cli/integration_tests/basic_monorepo/verbosity.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
Setup
$ . ${TESTDIR}/../setup.sh
$ . ${TESTDIR}/setup.sh $(pwd)

Verbosity level 1
$ ${TURBO} build -v --filter=util --force
[-0-9:.TWZ+]+ \[INFO] turbo: skipping turbod since we appear to be in a non-interactive context (re)
\xe2\x80\xa2 Packages in scope: util (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
util:build: cache bypass, force executing 238262ce1218fd3a
util:build:
util:build: > build
util:build: > echo 'building'
util:build:
util:build: building

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Time:\s*[\.0-9]+m?s (re)

$ ${TURBO} build --verbosity=1 --filter=util --force
[-0-9:.TWZ+]+ \[INFO] turbo: skipping turbod since we appear to be in a non-interactive context (re)
\xe2\x80\xa2 Packages in scope: util (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
util:build: cache bypass, force executing 238262ce1218fd3a
util:build:
util:build: > build
util:build: > echo 'building'
util:build:
util:build: building

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Time:\s*[\.0-9]+m?s (re)


Verbosity level 2
$ ${TURBO} build -vv --filter=util --force
[-0-9:.TWZ+]+ \[INFO] turbo: skipping turbod since we appear to be in a non-interactive context (re)
[-0-9:.TWZ+]+ \[DEBUG] turbo: global hash env vars: vars=\["VERCEL_ANALYTICS_ID"] (re)
[-0-9:.TWZ+]+ \[DEBUG] turbo: global hash: value=c1fb8f74a026cdb8 (re)
[-0-9:.TWZ+]+ |[DEBUG] turbo: local cache folder: path="" (re)
\xe2\x80\xa2 Packages in scope: util (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
[-0-9:.TWZ+]+ \[DEBUG] turbo.: start (re)
[-0-9:.TWZ+]+ \[DEBUG] turbo: task hash env vars for util:build: vars=\[] (re)
[-0-9:.TWZ+]+ \[DEBUG] turbo: task hash: value=238262ce1218fd3a (re)
util:build: cache bypass, force executing 238262ce1218fd3a
util:build:
util:build: > build
util:build: > echo 'building'
util:build:
util:build: building
[-0-9:.TWZ+]+ \[DEBUG] turbo.: caching output: outputs="{\[packages/util/.turbo/turbo-build.log] \[]}" (re)
[-0-9:.TWZ+]+ \[DEBUG] turbo.: done: status=complete duration=[\.0-9]+m?s (re)

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Time:\s*[\.0-9]+m?s (re)

$ ${TURBO} build --verbosity=2 --filter=util --force
[-0-9:.TWZ+]+ \[INFO] turbo: skipping turbod since we appear to be in a non-interactive context (re)
[-0-9:.TWZ+]+ \[DEBUG] turbo: global hash env vars: vars=\["VERCEL_ANALYTICS_ID"] (re)
[-0-9:.TWZ+]+ \[DEBUG] turbo: global hash: value=c1fb8f74a026cdb8 (re)
[-0-9:.TWZ+]+ \[DEBUG] turbo: local cache folder: path="" (re)
\xe2\x80\xa2 Packages in scope: util (esc)
\xe2\x80\xa2 Running build in 1 packages (esc)
\xe2\x80\xa2 Remote caching disabled (esc)
[-0-9:.TWZ+]+ \[DEBUG] turbo.: start (re)
[-0-9:.TWZ+]+ \[DEBUG] turbo: task hash env vars for util:build: vars=\[] (re)
[-0-9:.TWZ+]+ \[DEBUG] turbo: task hash: value=238262ce1218fd3a (re)
util:build: cache bypass, force executing 238262ce1218fd3a
util:build:
util:build: > build
util:build: > echo 'building'
util:build:
util:build: building
[-0-9:.TWZ+]+ \[DEBUG] turbo.: caching output: outputs="{\[packages/util/.turbo/turbo-build.log] \[]}" (re)
[-0-9:.TWZ+]+ \[DEBUG] turbo.: done: status=complete duration=[\.0-9]+m?s (re)

Tasks: 1 successful, 1 total
Cached: 0 cached, 1 total
Time:\s*[\.0-9]+m?s (re)




Make sure users can only use one verbosity flag
$ ${TURBO} build -v --verbosity=1
error: The argument '-v...' cannot be used with '--verbosity <COUNT>'

Usage: turbo [OPTIONS] [COMMAND]

For more information try '--help'
[1]
2 changes: 1 addition & 1 deletion cli/integration_tests/no_args.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Make sure exit code is 2 when no args are passed
--team <TEAM> Set the team slug for API calls
--token <TOKEN> Set the auth token for API calls
--trace <TRACE> Specify a file to save a pprof trace
-v... verbosity
--verbosity <COUNT> Verbosity level
-h, --help Print help information

Run Arguments:
Expand Down
12 changes: 6 additions & 6 deletions cli/integration_tests/turbo_help.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Test help flag
--team <TEAM> Set the team slug for API calls
--token <TOKEN> Set the auth token for API calls
--trace <TRACE> Specify a file to save a pprof trace
-v... verbosity
--verbosity <COUNT> Verbosity level
-h, --help Print help information

Run Arguments:
Expand Down Expand Up @@ -95,7 +95,7 @@ Test help flag
--team <TEAM> Set the team slug for API calls
--token <TOKEN> Set the auth token for API calls
--trace <TRACE> Specify a file to save a pprof trace
-v... verbosity
--verbosity <COUNT> Verbosity level
-h, --help Print help information

Run Arguments:
Expand Down Expand Up @@ -143,7 +143,7 @@ Test help flag for link command
--team <TEAM> Set the team slug for API calls
--token <TOKEN> Set the auth token for API calls
--trace <TRACE> Specify a file to save a pprof trace
-v... verbosity
--verbosity <COUNT> Verbosity level
-h, --help Print help information

Run Arguments:
Expand All @@ -170,7 +170,7 @@ Test help flag for unlink command
--team <TEAM> Set the team slug for API calls
--token <TOKEN> Set the auth token for API calls
--trace <TRACE> Specify a file to save a pprof trace
-v... verbosity
--verbosity <COUNT> Verbosity level
-h, --help Print help information

Run Arguments:
Expand Down Expand Up @@ -198,7 +198,7 @@ Test help flag for login command
--team <TEAM> Set the team slug for API calls
--token <TOKEN> Set the auth token for API calls
--trace <TRACE> Specify a file to save a pprof trace
-v... verbosity
--verbosity <COUNT> Verbosity level
-h, --help Print help information

Run Arguments:
Expand All @@ -225,7 +225,7 @@ Test help flag for logout command
--team <TEAM> Set the team slug for API calls
--token <TOKEN> Set the auth token for API calls
--trace <TRACE> Specify a file to save a pprof trace
-v... verbosity
--verbosity <COUNT> Verbosity level
-h, --help Print help information

Run Arguments:
Expand Down
63 changes: 57 additions & 6 deletions crates/turborepo-lib/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,8 @@ pub struct Args {
#[clap(long, global = true, value_parser)]
pub trace: Option<String>,
/// verbosity
#[clap(
short = 'v',
action = clap::ArgAction::Count,
global = true)]
pub verbosity: u8,
#[clap(flatten)]
pub verbosity: Verbosity,
#[clap(long = "__test-run", global = true, hide = true)]
pub test_run: bool,
#[clap(flatten, next_help_heading = "Run Arguments")]
Expand All @@ -96,6 +93,34 @@ pub struct Args {
pub command: Option<Command>,
}

#[derive(Debug, Parser, Serialize, Clone, Copy, PartialEq, Eq, Default)]
#[serde(into = "u8")]
pub struct Verbosity {
#[clap(
long = "verbosity",
global = true,
conflicts_with = "v",
value_name = "COUNT"
)]
/// Verbosity level
pub verbosity: Option<u8>,
#[clap(
short = 'v',
action = clap::ArgAction::Count,
global = true,
hide = true,
conflicts_with = "verbosity"
)]
pub v: u8,
}

impl Into<u8> for Verbosity {
chris-olszewski marked this conversation as resolved.
Show resolved Hide resolved
fn into(self) -> u8 {
let Self { verbosity, v } = self;
verbosity.unwrap_or(v)
}
}

#[derive(Subcommand, Clone, Debug, Serialize, PartialEq)]
#[serde(tag = "command")]
pub enum DaemonCommand {
Expand Down Expand Up @@ -406,7 +431,7 @@ mod test {
}
}

use crate::cli::{Args, Command, DryRunMode, OutputLogsMode, RunArgs};
use crate::cli::{Args, Command, DryRunMode, OutputLogsMode, RunArgs, Verbosity};

#[test]
fn test_parse_run() {
Expand Down Expand Up @@ -1051,4 +1076,30 @@ mod test {
}
);
}

#[test]
fn test_verbosity_serialization() -> Result<(), serde_json::Error> {
assert_eq!(
serde_json::to_string(&Verbosity {
verbosity: None,
v: 0
})?,
"0"
);
assert_eq!(
serde_json::to_string(&Verbosity {
verbosity: Some(3),
v: 0
})?,
"3"
);
assert_eq!(
serde_json::to_string(&Verbosity {
verbosity: None,
v: 3
})?,
"3"
);
Ok(())
}
}