GithubActions icon indicating copy to clipboard operation
GithubActions copied to clipboard

feat: Allow configuring PowerShell preference variables

Open z-Fng opened this issue 1 month ago • 1 comments

Description

This PR makes the following changes:

Motivation and Context

  • Most Verbose outputs are unnecessary at the moment. Setting VerbosePreference to Continue can suppress these outputs. Closes #66
  • Allow configuring PowerShell preference variables, which lays the groundwork for future code refactoring (such as log level management). Relates to #33

Test Cases

  • https://github.com/z-Fng/Scoop-Extras/actions/runs/19240280236/job/55000983538

Summary by CodeRabbit

  • Documentation

    • Added a PowerShell preference variables section with defaults and a link to Microsoft docs.
  • Behavioral Change

    • Removed explicit global preference settings that previously forced continue behavior, changing default error/verbosity handling.
  • Refactor

    • Centralized startup initialization for preference variables with support for optional environment overrides and startup logging of applied settings.

z-Fng avatar Nov 10 '25 17:11 z-Fng

Walkthrough

Removes hardcoded global PowerShell preference assignments from action.ps1, introduces Initialize-PreferenceVariable in src/Variables.psm1 to set preference globals (with optional Env:<Name> overrides, ErrorActionPreference ignored), and documents the preference variables in README.md.

Changes

Cohort / File(s) Summary
Documentation
README.md
Adds "PowerShell Preference Variables" subsection under available environment variables with a link to Microsoft docs and a table listing DebugPreference, InformationPreference, VerbosePreference, WarningPreference (type: String) and their default values.
Preference Removal
action.ps1
Removes global assignments \$Global:ErrorActionPreference = 'Continue' and \$Global:VerbosePreference = 'Continue' and the preceding comment; no other logic changes.
Preference Initialization
src/Variables.psm1
Adds Initialize-PreferenceVariable that defines an ordered map of default preferences, ensures ErrorActionPreference is set first and ignored from environment overrides, applies Env:<Name> overrides for other prefs, logs assignments via Write-Host, sets each preference in the Global: scope, and invokes the function immediately.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant User
    participant ActionPS as action.ps1
    participant Vars as src/Variables.psm1
    Note over ActionPS,Vars `#DDEEFF`: Startup flow after this PR
    User->>ActionPS: trigger action
    ActionPS->>Vars: import / dot-source Variables module
    Vars->>Vars: Initialize-PreferenceVariable()
    rect rgb(220,238,255)
      Note right of Vars: Build ordered defaults\nSet ErrorActionPreference first (ignored from env)
    end
    alt Env override present (per-variable, except ignored)
        Vars->>Vars: read Env:<Name> -> apply override
    else No env override
        Vars->>Vars: apply defaults
    end
    Vars->>ActionPS: preferences set in Global: scope
    ActionPS->>User: continue execution (no hardcoded global prefs)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Areas to review:
    • src/Variables.psm1: correct handling of ErrorActionPreference ordering and IgnoreEnv behavior, Env:<Name> precedence, logging verbosity, and use of Global: scope.
    • action.ps1: ensure removal of globals doesn't unintentionally alter downstream error/verbose behavior.
    • README.md: verify table values and Microsoft docs link.

Poem

🐇 I nudged the prefs with careful paws,
Env whispers chosen without a pause.
Defaults set, the noise grows thin,
Globals freed, the logs can grin.
A hop, a wink — tidy outputs win.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main feature being added—allowing configuration of PowerShell preference variables—and is directly related to the primary objectives of the pull request.
Linked Issues check ✅ Passed The PR fulfills the primary requirement from issue #66 by adding configuration capability for PowerShell preference variables to reduce verbose output via VerbosePreference.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing configurable PowerShell preference variables: README documentation, removal of hardcoded preferences, and new initialization function.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 10 '25 17:11 coderabbitai[bot]