Skip to content

The table-no-truncate output format emits YAML documents for list subcommands #1580

Description

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Summary

While documenting the new table-no-truncate value for the --output-format option of the dsc extension list and dsc function list subcommands I discovered that DSC doesn't emit a table at all - instead, it emits a series of YAML documents with the --- separator between each item.

I suspect this is caused by the last if statement in the following lines:

DSC/dsc/src/subcommand.rs

Lines 684 to 697 in 0b07d11

fn list_functions(functions: &FunctionDispatcher, function_name: Option<&String>, output_format: Option<&ListOutputFormat>) {
let mut write_table = false;
let mut table = Table::new(&[
t!("subcommand.tableHeader_functionCategory").to_string().as_ref(),
t!("subcommand.tableHeader_functionName").to_string().as_ref(),
t!("subcommand.tableHeader_minArgs").to_string().as_ref(),
t!("subcommand.tableHeader_maxArgs").to_string().as_ref(),
t!("subcommand.tableHeader_argTypes").to_string().as_ref(),
t!("subcommand.tableHeader_description").to_string().as_ref(),
]);
if output_format.is_none() && io::stdout().is_terminal() {
// write as table if format is not specified and interactive
write_table = true;
}

DSC/dsc/src/subcommand.rs

Lines 785 to 797 in 0b07d11

let mut write_table = false;
let mut table = Table::new(&[
t!("subcommand.tableHeader_type").to_string().as_ref(),
t!("subcommand.tableHeader_kind").to_string().as_ref(),
t!("subcommand.tableHeader_version").to_string().as_ref(),
t!("subcommand.tableHeader_capabilities").to_string().as_ref(),
t!("subcommand.tableHeader_adapter").to_string().as_ref(),
t!("subcommand.tableHeader_description").to_string().as_ref(),
]);
if format == Some(&ListOutputFormat::TableNoTruncate) || (format.is_none() && io::stdout().is_terminal()) {
// write as table if format is not specified and interactive
write_table = true;
}

For both list_extensions() and list_functions() the code only sets write_table to true when the user doesn't specify --output-format and stdout isn't being redirected or captured.

To fix this error, I think the code would need to be something like:

let write_table = if matches!(format, Some(ListOutputFormat::TableNoTruncate)) {
    // write as table if user specified the table format
    true
} else {
    // write as table if format is not specified and interactive
    format.is_none() && io::stdout().is_terminal()
};
let mut table = Table::new(&[
    t!("subcommand.tableHeader_type").to_string().as_ref(),
    t!("subcommand.tableHeader_version").to_string().as_ref(),
    t!("subcommand.tableHeader_capabilities").to_string().as_ref(),
    t!("subcommand.tableHeader_description").to_string().as_ref(),
]);

And we can drop the if statement from the current code.

Steps to reproduce

  1. Invoke the following commands:

    dsc extension list --output-format table-no-truncate
    dsc function list --output-format table-no-truncate

Expected behavior

dsc extension list --output-format table-no-truncate

Type                             Version  Capabilities  Description                                              
-----------------------------------------------------------------------------------------------------------------
Microsoft.PowerShell/Discover    0.1.0    d--           Discovers DSC resources packaged in PowerShell 7 modules.
Microsoft.Windows.Appx/Discover  0.1.0    d--           Discovers DSC resources packaged as Appx packages.

Actual behavior

dsc extension list --output-format table-no-truncate

type: Microsoft.PowerShell/Discover
version: 0.1.0
capabilities:
- discover
import: null
path: C:\code\dsc\dsc-pr-review\bin\debug\powershell.dsc.extension.json
deprecation_message: null
description: Discovers DSC resources packaged in PowerShell 7 modules.
directory: C:\code\dsc\dsc-pr-review\bin\debug
author: null
manifest:
  $schema: https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json
  type: Microsoft.PowerShell/Discover
  version: 0.1.0
  condition: '[not(equals(tryWhich(''pwsh''), null()))]'
  description: Discovers DSC resources packaged in PowerShell 7 modules.
  discover:
    executable: pwsh
    args:
    - -NoLogo
    - -NonInteractive
    - -ExecutionPolicy
    - Bypass
    - -NoProfile
    - -Command
    - ./powershell.discover.ps1
  import: null
  importParameters: null
  secret: null

---
type: Microsoft.Windows.Appx/Discover
version: 0.1.0
capabilities:
- discover
import: null
path: C:\code\dsc\dsc-pr-review\bin\debug\appx.dsc.extension.json
deprecation_message: null
description: Discovers DSC resources packaged as Appx packages.
directory: C:\code\dsc\dsc-pr-review\bin\debug
author: null
manifest:
  $schema: https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json
  type: Microsoft.Windows.Appx/Discover
  version: 0.1.0
  description: Discovers DSC resources packaged as Appx packages.
  discover:
    executable: powershell
    args:
    - -NoLogo
    - -NonInteractive
    - -ExecutionPolicy
    - Bypass
    - -NoProfile
    - -Command
    - ./appx-discover.ps1
  import: null
  importParameters: null
  secret: null

Error details

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.2
PSEdition                      Core
GitCommitId                    7.6.2
OS                             Microsoft Windows 10.0.26200
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

3.2.0

Visuals

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-BugSomething isn't working

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions