Skip to content

Replace root upgrade flag with self upgrade command#333

Merged
kindermax merged 1 commit intomasterfrom
codex/make-upgrade-selfcommand-308
Apr 3, 2026
Merged

Replace root upgrade flag with self upgrade command#333
kindermax merged 1 commit intomasterfrom
codex/make-upgrade-selfcommand-308

Conversation

@kindermax
Copy link
Copy Markdown
Collaborator

@kindermax kindermax commented Apr 3, 2026

Summary

  • Add lets self upgrade as the supported self-update entrypoint
  • Remove the top-level --upgrade flag and return a clear migration error for legacy usage
  • Update help text, config-version guidance, tests, and docs to reference the new command

Testing

  • lets fmt
  • go test ./...
  • lets test-bats help.bats
  • lets test-bats help_long.bats
  • lets test-bats command_group.bats
  • lets test-bats command_group_long.bats
  • lets test-bats config_version.bats

Summary by Sourcery

Replace the deprecated top-level self-upgrade flag with a dedicated lets self upgrade subcommand and update CLI behavior, messaging, and docs accordingly.

New Features:

  • Add a lets self upgrade subcommand to perform binary self-upgrades via the existing upgrade infrastructure.

Bug Fixes:

  • Ensure update checks are not triggered for self and its subcommands, including self upgrade, to avoid redundant notifications during maintenance operations.

Enhancements:

  • Remove the legacy --upgrade root flag, making the CLI reject it with a clear migration error pointing to lets self upgrade.
  • Refine root flag parsing, help output, and command classification helpers to treat self as a structured command group.
  • Improve self-upgrade error propagation by surfacing upgrade failures directly from the self upgrade command.

Documentation:

  • Update installation, CLI, architecture, and changelog documentation to describe lets self upgrade as the supported self-update mechanism and remove references to --upgrade.

Tests:

  • Extend unit and Bats tests to cover the self upgrade command, legacy --upgrade flag rejection, updated help output, config-version guidance, and update-check skipping for self commands.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Apr 3, 2026

Reviewer's Guide

Replaces the deprecated top-level --upgrade flag with a new lets self upgrade subcommand, refactors update-check logic to be command-aware, and updates tests and docs to reflect the new upgrade entrypoint and behavior.

Sequence diagram for lets self upgrade command execution

sequenceDiagram
    actor User
    participant Shell
    participant Main as CliMain
    participant Cobra as CobraRoot
    participant Self as SelfCommand
    participant UpgradeCmd as UpgradeCommand
    participant Factory as upgraderFactory
    participant Upgrader as UpgradeUpgrader

    User->>Shell: run lets self upgrade
    Shell->>Main: invoke Main(version, buildDate)
    Main->>Cobra: execute root command
    Cobra->>Self: dispatch self subcommand
    Self->>UpgradeCmd: dispatch upgrade subcommand

    activate UpgradeCmd
    UpgradeCmd->>Factory: createUpgrader()
    Factory-->>UpgradeCmd: Upgrader or error
    alt factory error
        UpgradeCmd-->>User: print can not self-upgrade binary
    else factory ok
        UpgradeCmd->>Upgrader: Upgrade(context)
        alt upgrade error
            Upgrader-->>UpgradeCmd: error
            UpgradeCmd-->>User: print can not self-upgrade binary
        else upgrade success
            Upgrader-->>UpgradeCmd: nil
            UpgradeCmd-->>User: print success and exit 0
        end
    end
    deactivate UpgradeCmd
Loading

Class diagram for new self upgrade command structure

classDiagram
    class CobraCommand {
        +string Use
        +string Short
        +RunE(cmd CobraCommand, args []string) error
    }

    class upgraderFactory {
        <<function type>>
        +New() (Upgrader, error)
    }

    class UpgradeUpgrader {
        <<interface>>
        +Upgrade(ctx Context) error
    }

    class UpgradePackage {
        +NewBinaryUpgrader(registry GithubRegistry, version string) Upgrader
    }

    class GithubRegistry {
        +NewGithubRegistry() GithubRegistry
    }

    class CmdPackage {
        +initUpgradeCommand(version string) CobraCommand
        +initUpgradeCommandWith(createUpgrader upgraderFactory) CobraCommand
        +initSelfCmd(rootCmd CobraCommand, version string, openURL funcUrl) void
    }

    class CliPackage {
        +Main(version string, buildDate string) int
        +maybeStartUpdateCheck(command CobraCommand, appSettings Settings) UpdateCheckResult
        +shouldCheckForUpdate(command CobraCommand, interactive bool, appSettings Settings) bool
        +allowsMissingConfig(current CobraCommand) bool
        +isSelfCommand(current CobraCommand) bool
        +parseRootFlags(args string[]) Flags
    }

    class Flags {
        +bool help
        +bool version
        +bool all
        +bool init
    }

    class Settings {
        +bool UpgradeNotify
    }

    class Context
    class UpdateCheckResult
    class funcUrl {
        <<function type>>
        +Call(url string) error
    }

    CmdPackage --> CobraCommand : configures
    CmdPackage ..> upgraderFactory : uses
    CmdPackage ..> UpgradePackage : uses
    CmdPackage ..> GithubRegistry : uses
    upgraderFactory --> UpgradeUpgrader : returns
    UpgradePackage ..> UpgradeUpgrader : creates
    UpgradePackage ..> GithubRegistry : uses

    CliPackage ..> CobraCommand : uses
    CliPackage ..> Settings : uses
    CliPackage ..> Flags : uses
    CliPackage ..> Context : uses
    CliPackage ..> UpdateCheckResult : uses
    CliPackage ..> CmdPackage : calls self subcommands through cobra

    CmdPackage ..> funcUrl : uses in initSelfCmd
Loading

File-Level Changes

Change Details Files
Introduce lets self upgrade subcommand and wire it into the self command tree.
  • Add initUpgradeCommand and initUpgradeCommandWith to construct an upgrade Cobra command that runs the binary upgrader and returns wrapped errors
  • Register the new upgrade subcommand under lets self within InitSelfCmd
  • Add unit tests to verify successful execution and error propagation of the self upgrade subcommand using a mock upgrader
internal/cmd/upgrade.go
internal/cmd/self.go
internal/cmd/root_test.go
Remove the root-level --upgrade flag and replace it with a migration error.
  • Drop upgrade from root flags definition and parsing struct
  • Change parseRootFlags to treat --upgrade as invalid and return a clear error pointing to lets self upgrade
  • Delete the old --upgrade execution path from cli.Main
  • Add tests to assert the legacy flag is rejected with the expected error message
internal/cmd/root.go
internal/cli/cli.go
internal/cli/cli_test.go
Refine update-check logic to operate on Cobra commands and skip self commands explicitly.
  • Change shouldCheckForUpdate to accept a *cobra.Command instead of a command name string and return false for completion, help, and any self subcommands under the lets root
  • Extract isSelfCommand helper and reuse it from both allowsMissingConfig and shouldCheckForUpdate
  • Update maybeStartUpdateCheck and associated tests to pass commands rather than strings, and add coverage for skipping self, self doc, and self upgrade
internal/cli/cli.go
internal/cli/cli_test.go
Update documentation, help output, and tests to reference lets self upgrade instead of --upgrade.
  • Update installation, architecture, CLI docs, and changelog to describe lets self upgrade as the upgrade mechanism and remove --upgrade from documented flags
  • Adjust config-version validation error message to instruct users to run lets self upgrade
  • Update bats tests that assert help/flags output and config-version messages to match the new wording and removed --upgrade flag
docs/docs/installation.mdx
docs/docs/architecture.md
docs/docs/cli.md
docs/docs/changelog.md
internal/config/validate.go
tests/config_version.bats
tests/help.bats
tests/help_long.bats
tests/command_group.bats
tests/command_group_long.bats

Possibly linked issues

  • #: PR removes --upgrade, adds lets self upgrade command, and updates docs/tests as requested in the issue.

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

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


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.

@kindermax kindermax merged commit 473e724 into master Apr 3, 2026
5 checks passed
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