Skip to content

refactor: fold duplicated command-layer helpers into one copy each - #261

Merged
tas50 merged 1 commit into
mainfrom
refactor/remove-duplicate-helpers
Sep 24, 2026
Merged

tas50 merged 1 commit into
mainfrom
refactor/remove-duplicate-helpers

Conversation

@tas50

@tas50 tas50 commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Cleanup from an audit of the command layer. No behavior change. It removes 292 net lines.

  • listNames: eleven fetch<Noun>Names functions (list, collect keys, sort) differed only in the service they called. They're now one generic listNames(ctx, c.Nodes.List), built on slices.Sorted(maps.Keys(...)).
  • Profile selection: the --profile → $CINC_PROFILE → $CHEF_PROFILE precedence was written out five times (common.go, create.go twice, explore.go, and privately in cli/config). config.EnvProfile is exported and explicitProfile(cmd) sits on top of it.
  • Shadowed helpers: create.go had byte-identical private copies of components.PromptWithDefault and config.ExpandHome.
  • Editor: openClientJSONEditor was openObjectJSONEditor[cinc.APIClient] spelled out by hand. The fused doc comment above the editor vars is fixed too.
  • Dead code: eight RunList == nil guards before Nodes.Update/Roles.Update. Node.MarshalJSON/Role.MarshalJSON already send run_list as [].
  • Small ones: cmpString becomes strings.Compare. The config check's hand-rolled ErrorResponse.StatusCode == 403 becomes errors.Is(err, cinc.ErrForbidden). The bagCreateOrPropagate pass-through is inlined.

Test plan

  • go test ./apps/... ./cli/config/ ./cli/components/
  • go vet, gofmt clean

@tas50
tas50 enabled auto-merge (squash) September 24, 2026 05:18
- Eleven fetch<Noun>Names functions, identical but for the service they
  listed, become one generic listNames(ctx, c.Nodes.List).
- The --profile / $CINC_PROFILE / $CHEF_PROFILE lookup was written out
  five times; config.EnvProfile (exported) and explicitProfile(cmd) are
  now the only copies.
- create.go carried private copies of components.PromptWithDefault and
  config.ExpandHome; use the shared ones.
- openClientJSONEditor was openObjectJSONEditor[cinc.APIClient] spelled
  out by hand.
- Drop the RunList == nil guards before Nodes/Roles.Update:
  Node.MarshalJSON and Role.MarshalJSON already send [].
- Replace cmpString with strings.Compare, the config check's manual
  StatusCode == 403 test with errors.Is(err, cinc.ErrForbidden), and the
  bagCreateOrPropagate pass-through with the call it wrapped.

Signed-off-by: Tim Smith <tsmith84@proton.me>
@tas50
tas50 force-pushed the refactor/remove-duplicate-helpers branch from 5aa0981 to 25ad5a1 Compare September 24, 2026 05:29
@tas50
tas50 merged commit 37c6aa2 into main Sep 24, 2026
6 checks passed
@tas50
tas50 deleted the refactor/remove-duplicate-helpers branch September 24, 2026 05:33
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.

1 participant