Skip to content

Create more *_into functions#2501

Merged
CLHatch merged 1 commit into
mainfrom
namrefs
May 22, 2026
Merged

Create more *_into functions#2501
CLHatch merged 1 commit into
mainfrom
namrefs

Conversation

@CLHatch

@CLHatch CLHatch commented May 22, 2026

Copy link
Copy Markdown
Contributor

Pull request

Purpose
Describe the problem or feature in addition to a link to the issues.

Approach
How does this change address the problem?

Open Questions and Pre-Merge TODOs
Check all boxes as they are completed

  • Use github checklists. When solved, check the box and explain the answer.

Learning
Describe the research stage
Links to blog posts, patterns, libraries or addons used to solve this problem

Requirements
Check all boxes as they are completed

Summary by Sourcery

Refactor configuration, environment, and helper scripts to introduce *_into variants that write results to variables and update existing callers to use them for improved composability and performance.

Enhancements:

  • Add *_into variants for INI/TOML accessors, config_get, theme_name, varname_to_appname, and var_default_value to populate output variables instead of printing directly.
  • Refactor higher-level scripts (config/env management, menus, theming, and app variable utilities) to rely on the new *_into helpers instead of command substitution, simplifying value flow and reuse.

Tests:

  • Add basic test hooks for new *_into helper functions, mirroring existing behavior while noting limited CI coverage.

@CLHatch CLHatch requested a review from a team as a code owner May 22, 2026 09:22
@sourcery-ai

sourcery-ai Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

This PR introduces a set of into helper functions for configuration, environment, and theme handling, refactors existing callers to use these out-parameter helpers instead of subshell command substitutions, and splits var_default_value/varname_to_appname/config logic into reusable *_into implementations while preserving existing behavior.

Flow diagram for config_get_into and backend selection

flowchart TD
    Caller["Caller (e.g. env_sanitize, config_show)"] --> CG["config_get"]
    CG --> CGI["config_get_into(section_key, config_file)"]

    CGI -->|"file_extension == toml"| CTGI["config_toml_get_into(section_key, config_file)"]
    CGI -->|"file_extension == ini"| CIGI["config_ini_get_into(section_key, config_file)"]

    CTGI --> GTVI["get_toml_val_into(file, section.key)"]
    CTGI --> GTVSI["get_toml_val_string_into(...) / get_toml_val_bool_into(...)"]

    CIGI --> GIVI["get_ini_val_into(file, key)"]
    CIGI --> GIVSI["get_ini_val_string_into(...) / get_ini_val_bool_into(...)"]

    GTVI --> OutVal["OutVar (config value)"]
    GTVSI --> OutVal
    GIVI --> OutVal
    GIVSI --> OutVal
Loading

Flow diagram for var_default_value_into and callers

flowchart TD
    CallerMenu["Caller (env_sanitize, menu_value_prompt, etc.)"] --> VDV["var_default_value"]
    VDV --> VDVIntoCall["var_default_value_into(out_var, VarName)"]

    VDVIntoCall --> VTAI["varname_to_appname_into(APPNAME, VarName)"]
    VDVIntoCall -->|"APP var"| AppCase["APP case"]
    VDVIntoCall -->|"APPENV var"| AppEnvCase["APPENV case"]
    VDVIntoCall -->|"no APPNAME"| GlobalCase["GLOBAL case"]

    AppCase --> AIFApp["app_instance_file_into(DefaultAppVarFile, APPNAME, .env)"]
    AIFApp --> EnvExists["env_var_exists(CleanVarName, DefaultAppVarFile)"]
    EnvExists -->|"exists"| EGLIApp["env_get_literal_into(out_var, CleanVarName, DefaultAppVarFile)"]
    EnvExists -->|"missing"| AppFallback["compute hardcoded defaults for APP vars"]

    AppEnvCase --> AIFEnv["app_instance_file_into(DefaultAppVarFile, APPNAME, .env.app.*)"]
    AIFEnv --> EnvExistsEnv["env_var_exists(CleanVarName, DefaultAppVarFile)"]
    EnvExistsEnv -->|"exists"| EGLEnv["env_get_literal_into(out_var, CleanVarName, DefaultAppVarFile)"]
    EnvExistsEnv -->|"missing"| AppEnvFallback["default to ''"]

    GlobalCase --> GlobalSwitch["GLOBAL var switch"]
    GlobalSwitch -->|"COMPOSE/CONFIG paths"| UseLiterals["use LITERAL_COMPOSE_FOLDER / LITERAL_CONFIG_FOLDER"]
    GlobalSwitch -->|"PGID/PUID"| UseDetected["use DETECTED_PGID / DETECTED_PUID"]
    GlobalSwitch -->|"fallback"| ComposeDefault["env_get_literal_into from COMPOSE_ENV_DEFAULT_FILE or ''"]

    EGLIApp --> OutVal["OutVar (default value)"]
    AppFallback --> OutVal
    EGLEnv --> OutVal
    AppEnvFallback --> OutVal
    UseLiterals --> OutVal
    UseDetected --> OutVal
    ComposeDefault --> OutVal
Loading

File-Level Changes

Change Details Files
Introduce *_into variants for reading and interpreting INI/TOML configuration values and theme names, and switch higher-level config helpers to use them.
  • Add get_ini_val_into, get_ini_val_string_into, get_ini_val_bool_into that populate a referenced variable instead of echoing results
  • Add get_toml_val_into, get_toml_val_string_into, get_toml_val_bool_into following the same into pattern
  • Create config_ini_get_into, config_toml_get_into, and config_get_into as out-var based wrappers around existing config resolution logic
  • Implement theme_name_into that resolves ui.theme using config_get_into
  • Refactor config_get, config_ini_get, config_toml_get, theme_name, and multiple menu_* scripts to call the new *_into functions and then echo the captured value when needed
includes/misc_functions.sh
scripts/config_ini_get_into.sh
scripts/config_toml_get_into.sh
scripts/config_get_into.sh
scripts/theme_name_into.sh
scripts/config_ini_get.sh
scripts/config_toml_get.sh
scripts/config_get.sh
scripts/theme_name.sh
scripts/config_theme.sh
scripts/menu_options_display.sh
scripts/menu_options_package_manager.sh
scripts/menu_options_theme.sh
includes/cmdline.sh
scripts/menu_dialog_example.sh
scripts/theme_author.sh
scripts/theme_description.sh
Split var_default_value and varname_to_appname into *_into implementations and refactor all consumers to use the new out-parameter style.
  • Move core var_default_value logic into new var_default_value_into using a nameref out parameter and preserve existing APP/APPENV/GLOBAL resolution semantics
  • Change var_default_value to a thin wrapper that calls var_default_value_into and echoes the result for backwards compatibility
  • Introduce varname_to_appname_into with BASH regex and colon handling, and update varname_to_appname to delegate to it
  • Update scripts that previously parsed app names or default values via command substitution to use varname_to_appname_into and var_default_value_into instead, reducing subshells and repeated parsing
scripts/var_default_value_into.sh
scripts/var_default_value.sh
scripts/varname_to_appname_into.sh
scripts/varname_to_appname.sh
scripts/menu_value_prompt.sh
scripts/menu_add_var.sh
scripts/menu_config_vars.sh
scripts/env_sanitize.sh
scripts/varname_is_valid.sh
scripts/env_backup.sh
scripts/appvars_create.sh
scripts/appvars_lines.sh
scripts/appvars_list.sh
scripts/appvars_purge.sh
scripts/config_create.sh
scripts/config_show.sh
scripts/env_delete.sh
scripts/env_get_line_regex.sh
scripts/env_set.sh
scripts/env_set_literal.sh
scripts/env_var_exists.sh
scripts/env_migrate.sh
scripts/env_update.sh
scripts/menu_heading.sh
scripts/needs_appvars_create.sh
scripts/needs_yml_merge.sh
scripts/var_helpline.sh
Standardize app env file path resolution via app_env_file_into and propagate *_into usage to env/timestamp helpers and config flows.
  • Replace uses of app_env_file that relied on command substitution with app_env_file_into wherever an env file path is needed
  • Adjust scripts that compare, back up, or delete per-app env files to use local variables populated via *_into helpers
  • Update needs_env_update/unset_needs_env_update and needs_yml_merge/unset_needs_yml_merge to capture app env file paths and enabled lines without subshells
scripts/menu_add_var.sh
scripts/menu_config_vars.sh
scripts/unset_needs_env_update.sh
scripts/env_migrate.sh
scripts/env_update.sh
scripts/menu_heading.sh
scripts/needs_appvars_create.sh
scripts/needs_yml_merge.sh
scripts/unset_needs_yml_merge.sh
scripts/app_is_referenced.sh
scripts/appvars_create.sh
scripts/appvars_lines.sh
scripts/appvars_list.sh
scripts/appvars_purge.sh
scripts/env_delete.sh
scripts/env_get_line_regex.sh
scripts/env_set.sh
scripts/env_set_literal.sh
scripts/env_var_exists.sh
Refine env update / sanitize flows to rely on new *_into helpers for config and default discovery while preserving behavior.
  • Adjust env_sanitize to retrieve LITERAL_CONFIG_FOLDER and LITERAL_COMPOSE_FOLDER using config_get_into with fallbacks
  • Update env_sanitize default resolution for missing or invalid env vars to use var_default_value_into instead of var_default_value
  • Change env_backup to get DOCKER_CONFIG_FOLDER and DOCKER_VOLUME_CONFIG defaults via var_default_value_into
  • Update unset_needs_env_update and needs_env_update to use env_get_line_into with intermediate locals instead of anonymous variables
scripts/env_sanitize.sh
scripts/env_backup.sh
scripts/unset_needs_env_update.sh
scripts/needs_env_update.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions Bot added the core Automatic label label May 22, 2026
@CLHatch CLHatch merged commit 6794039 into main May 22, 2026
15 checks passed
@CLHatch CLHatch deleted the namrefs branch May 22, 2026 09:22

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The new *_get_into helpers (e.g., config_ini_get_into, config_toml_get_into, config_get_into) compute the file extension using ${var_##*.}, which is invalid parameter expansion and will not yield the intended extension; this should be corrected to ${var##*.}.
  • theme_name_into always returns successfully and defaults to an empty string on failure (|| true), which changes the behavior compared to the previous theme_name implementation; consider propagating non‑zero status or explicitly handling the "no theme configured" case so callers can distinguish between a missing theme and a valid empty value.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new *_get_into helpers (e.g., config_ini_get_into, config_toml_get_into, config_get_into) compute the file extension using `${var_##*.}`, which is invalid parameter expansion and will not yield the intended extension; this should be corrected to `${var##*.}`.
- theme_name_into always returns successfully and defaults to an empty string on failure (`|| true`), which changes the behavior compared to the previous theme_name implementation; consider propagating non‑zero status or explicitly handling the "no theme configured" case so callers can distinguish between a missing theme and a valid empty value.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

core Automatic label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant