Skip to content

Commit 0c7440b

Browse files
authored
Merge pull request #1595 from michaeltlombardi/gh-1580/main/table-no-truncate
(GH-1580) Fix table output for no-truncate option
2 parents 9043315 + 540ef07 commit 0c7440b

2 files changed

Lines changed: 36 additions & 10 deletions

File tree

dsc/src/subcommand.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -615,18 +615,27 @@ pub fn resource(subcommand: &ResourceSubCommand, progress_format: ProgressFormat
615615
}
616616
}
617617

618+
/// Indicates whether to emit a table based on the output format and whether stdout is a terminal.
619+
fn should_write_table(format: Option<&ListOutputFormat>) -> bool {
620+
if matches!(format, Some(ListOutputFormat::TableNoTruncate)) {
621+
// write as table if user specified the table format
622+
true
623+
} else {
624+
// write as table if format is not specified and interactive
625+
format.is_none() && io::stdout().is_terminal()
626+
}
627+
}
628+
618629
fn list_extensions(dsc: &mut DscManager, extension_name: &TypeNameFilter, format: Option<&ListOutputFormat>, progress_format: ProgressFormat) {
619-
let mut write_table = false;
630+
let write_table = should_write_table(format);
631+
620632
let mut table = Table::new(&[
621633
t!("subcommand.tableHeader_type").to_string().as_ref(),
622634
t!("subcommand.tableHeader_version").to_string().as_ref(),
623635
t!("subcommand.tableHeader_capabilities").to_string().as_ref(),
624636
t!("subcommand.tableHeader_description").to_string().as_ref(),
625637
]);
626-
if format.is_none() && io::stdout().is_terminal() {
627-
// write as table if format is not specified and interactive
628-
write_table = true;
629-
}
638+
630639
let mut include_separator = false;
631640

632641
for manifest_resource in dsc.list_available(&DiscoveryKind::Extension, extension_name, None, progress_format) {
@@ -682,7 +691,7 @@ fn list_extensions(dsc: &mut DscManager, extension_name: &TypeNameFilter, format
682691
}
683692

684693
fn list_functions(functions: &FunctionDispatcher, function_name: Option<&String>, output_format: Option<&ListOutputFormat>) {
685-
let mut write_table = false;
694+
let write_table = should_write_table(output_format);
686695
let mut table = Table::new(&[
687696
t!("subcommand.tableHeader_functionCategory").to_string().as_ref(),
688697
t!("subcommand.tableHeader_functionName").to_string().as_ref(),
@@ -691,10 +700,7 @@ fn list_functions(functions: &FunctionDispatcher, function_name: Option<&String>
691700
t!("subcommand.tableHeader_argTypes").to_string().as_ref(),
692701
t!("subcommand.tableHeader_description").to_string().as_ref(),
693702
]);
694-
if output_format.is_none() && io::stdout().is_terminal() {
695-
// write as table if format is not specified and interactive
696-
write_table = true;
697-
}
703+
698704
let mut include_separator = false;
699705
let returned_types= [
700706
(FunctionArgKind::Array, "a"),

dsc/tests/dsc_function_list.tests.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
33

4+
BeforeDiscovery {
5+
try {
6+
$windowWidth = [Console]::WindowWidth
7+
} catch {
8+
$consoleUnavailable = $true
9+
}
10+
}
11+
412
Describe 'Tests for function list subcommand' {
513
It 'Should list all available functions' {
614
$out = dsc function list | ConvertFrom-Json
@@ -22,4 +30,16 @@ Describe 'Tests for function list subcommand' {
2230
$out.returnTypes | Should -Be @('String')
2331
$out.description | Should -Not -BeNullOrEmpty
2432
}
33+
34+
It 'Table can be not truncated' -Skip:($consoleUnavailable) {
35+
$output = dsc function list --output-format table-no-truncate
36+
$LASTEXITCODE | Should -Be 0
37+
$foundWideLine = $false
38+
foreach ($line in $output) {
39+
if ($line.Length -gt $windowWidth) {
40+
$foundWideLine = $true
41+
}
42+
}
43+
$foundWideLine | Should -BeTrue
44+
}
2545
}

0 commit comments

Comments
 (0)