Skip to content

Conversation

Copy link

Copilot AI commented Nov 10, 2025

🎯 Aim

The runCliCommand function executes commands without ensuring JSON output format, leading to inconsistent and unparseable responses.

πŸ“· Result

N/A - Internal logic change, no UI impact

βœ… What was done

  • Modified runCliCommand in src/util.ts to append --output json when not explicitly specified
  • Preserves user's explicit --output choice (text/csv/md) when present

Implementation:

export async function runCliCommand(command: string): Promise<string> {
    // Ensure --output json is always present
    if (!command.includes('--output')) {
        command = `${command} --output json`;
    }
    
    return new Promise((resolve, reject) => {
        // ... existing code
    });
}

Behavior:

  • m365 status β†’ m365 status --output json
  • m365 status --output text β†’ m365 status --output text (unchanged)

πŸ”— Related issue

Closes: #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>Ensure --output json is always added to CLI commands</issue_title>
<issue_description>Description:

Summary

Currently, the runCliCommand function in src/util.ts executes commands without ensuring that the output format is JSON. This could lead to inconsistent output formats that are harder to parse.

Current Behavior

The runCliCommand function executes commands as-is:

const subprocess = spawn(command, {
    shell: true,
    timeout: 120000,
});

Proposed Enhancement

Modify runCliCommand to automatically append --output json to commands if it's not already present. This would ensure:

  • Consistent JSON output for easier parsing
  • Better error handling and response processing
  • More reliable integration with MCP server responses

Example Implementation

export async function runCliCommand(command: string): Promise<string> {
    // Ensure --output json is always present
    if (!command.includes('--output')) {
        command = `${command} --output json`;
    }
    
    return new Promise((resolve, reject) => {
        const subprocess = spawn(command, {
            shell: true,
            timeout: 120000,
        });
        // ... rest of implementation
    });
}

Benefits

  • Guarantees parseable JSON responses
  • Reduces potential errors from text parsing
    </issue_description>

Comments on the Issue (you are @copilot in this section)


πŸ’‘ You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Ensure '--output json' is added to CLI commands Ensure --output json is always added to CLI commands Nov 10, 2025
Copilot AI requested a review from Adam-it November 10, 2025 17:51
Copilot finished work on behalf of Adam-it November 10, 2025 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure --output json is always added to CLI commands

2 participants