cli-bool-flag-pattern

Add boolean flags to the update-config CLI command and persist changes in JSON.

9|1|Updated Jul 21, 2025
One-click install
npx skills add https://github.com/usepowershell/PoshMcp --skill cli-bool-flag-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cli-bool-flag-pattern
Source: https://github.com/usepowershell/PoshMcp/tree/main/.squad/skills/cli-bool-flag-pattern
Command: npx skills add https://github.com/usepowershell/PoshMcp --skill cli-bool-flag-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Adding and maintaining boolean flags in the update-config CLI handler can lead to inconsistent parsing, brittle JSON mutations, double-counted or missed settingsChanged increments, and missing unit tests that allow regressions.

Core Features & Use Cases

  • Consistent Parsing: Use TryParseRequiredBoolean to extract and validate boolean CLI arguments and centrally manage settingsChanged increments.
  • Safe JSON Mutation: Use GetOrCreateObject to navigate or create nested JSON sections and assign flag values to the appropriate path (examples include powerShellConfiguration.Performance, Authentication, and Function).
  • Testable Changes: Require unit tests that supply flags, invoke the update-config flow, and assert the resulting JSON structure and values to ensure correctness.
  • Use Case: Add an --enable-caching flag that updates config.powerShellConfiguration.Performance.enableCaching and increments SettingsChanged.

Quick Start

Run the update-config command with the desired --enable-caching flag and then inspect the configuration JSON to confirm the performance section contains enableCaching set to the expected boolean value.

Frequently Asked Questions about cli-bool-flag-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add boolean CLI flags to update a JSON configuration file?

To add boolean CLI flags to a JSON configuration file, use TryParseRequiredBoolean to validate arguments, apply GetOrCreateObject for safe nested JSON mutations, and increment a settings-changed counter for each applied flag.

What is the best way to parse boolean command line arguments in PowerShell CLI?

The best way to parse boolean command line arguments in PowerShell CLI is using TryParseRequiredBoolean to centrally extract and validate inputs, preventing brittle parsing and double-counted configuration changes.

How do I safely update nested JSON sections from CLI input?

Safely update nested JSON sections from CLI input by using GetOrCreateObject to navigate or create the required JSON path and assign boolean flag values to the appropriate configuration section.

How do I unit test CLI boolean flag parsing and JSON structure changes?

Unit test CLI boolean flag parsing by supplying flags to invoke the update-config flow, then assert the resulting JSON structure and values to ensure correct settingsChanged increments and prevent regressions.

Does this CLI flag pattern require existing JSON configuration sections to exist?

No, the pattern does not require existing JSON configuration sections. It uses GetOrCreateObject to dynamically locate or create nested JSON sections during the update-config CLI command execution.