feat: Add flags for prompt values to upgrade command by kkemple ยท Pull Request #87 ยท slackapi/slack-cli

Conversation

@kkemple

Summary of changes

  • Added a new boolean flag --auto-approve to the upgrade command
  • Added a new method InstallUpdatesWithoutPrompt to the UpdateNotification type for handling auto-approved updates
  • Modified the dependencies' PrintUpdateNotification methods to check for the flag and bypass confirmation
  • Updated command examples and help text to document the new flag

This PR enables:

  • Automated CLI upgrade workflows in CI/CD pipelines
  • Programmatic upgrades through the MCP server tools API
  • Simplified upgrades for users who always want the latest version
  • Better integration with scripts and other automation tools

The flag follows established patterns in the codebase for command options, with appropriate documentation and test coverage to ensure reliability.


Tests Added

  • Updated TestUpgradeCommand to verify behavior with and without the flag
  • Added a test case specifically for the auto-approve flag path
  • Ensured all existing tests continue to pass

Docs Updated

  • Added the flag to the command documentation in docs/reference/commands/slack_upgrade.md
  • Added an example demonstrating usage of the flag
  • Updated the options section to include the new flag with its description

Reasoning for implementation

The upgrade command needed a way to be run non-interactively, especially for automation and scripting use cases. The --auto-approve flag provides this functionality by skipping the confirmation prompt when installing updates.

While we could have modified the existing confirmation flow directly, creating a dedicated method provides better separation of concerns:

  1. Keeps the standard interactive flow clean and focused
  2. Makes the auto-approve path more explicit and maintainable
  3. Reduces the risk of regression in either flow when changes are made

Requirements

@codecov

@kkemple

Last commit improves error handling in the automatic updates flow by:

  • Fixing linting error in cmd/upgrade/upgrade.go by properly checking the error returned from updateNotification.InstallUpdatesWithoutPrompt() when the --auto-approve flag is used.
  • Adding comprehensive test coverage for error scenarios:
    • New TestUpgradeCommandWithAutoApproveError test in cmd/upgrade/upgrade_test.go
      to verify error propagation when auto-approve is enabled
    • New Test_Update_InstallUpdatesWithoutPrompt test in internal/update/update_test.go
      to test different error scenarios in the update notification process
  • Improved test structure to correctly model the early-return behavior of the InstallUpdatesWithoutPrompt method, ensuring mock expectations are properly set when errors occur.

These changes ensure that if an error occurs during automatic updates, it will
be properly propagated back to the user rather than silently ignored, improving
reliability and user experience.

mwbrooks

Choose a reason for hiding this comment

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

Great idea @kkemple and thanks for putting together a PR ๐Ÿ‘๐Ÿป

We already have some conventions for disabling prompts and seeding a default answer. There are also some good conventions in the CLI community. So, I think I'd lean toward adopting those rather than introducing a new flag.

@zimeg Do you think this is a good place for the --no-prompt flag? We could also use the common convention of --yes | -y to default all prompts to "yes".

@zimeg

@mwbrooks Great suggestions and I also think this is a good idea to have for imperative automations ๐Ÿ‘พ

Do you think this is a good place for the --no-prompt flag?

With our current default prompt being "no" for the upgrade command, I don't think this would be ideal. AFAICT this flag should instead error with the suggested flag alternative instead of make the default choice?

To me --yes is solid and --auto-approve makes sense too! I'd avoid --force since we're not overriding warnings here.

One concern I have with both options is that we sometimes have multiple prompts when upgrading, one for the CLI version and one for the SDK. Without being so verbose, matching one flag to one prompt might be the most sure, though developers using --yes might understand the effects of automating updates.

Could these boolean flags for the prompt make sense?

$ slack upgrade --cli
$ slack upgrade --sdk

@zimeg

Matching specific confirmation prompts might be an interesting pattern to use with something like this as well:

$ slack upgrade --confirm=cli --confirm=sdk

@mwbrooks

Great point @zimeg that --no-prompt always chooses the default, while --yes or --no would answer ALL prompts with a yes or no.

One concern I have with both options is that we sometimes have multiple prompts when upgrading, one for the CLI version and one for the SDK.

You also bring up a good point that the upgrade command can have 2 prompts: CLI and SDK.

I did some research and common approaches are:

  • Skip all prompts using defaults: --no-prompt, --no-interactivity, --quiet
  • Answer all prompts with a value: --yes or --no
  • Answer each prompt with a specific value: --foo bar

So, I think we can come back to something that we discussed a good year ago: each prompt should have a flag.

In that case, something like this makes sense:

  • Upgrade CLI: --cli=<bool>
  • Upgrade SDK: --sdk=<bool>

@kkemple kkemple changed the title feat: Add --auto-approve flag to upgrade command feat: Add flags for prompt values to upgrade command

May 13, 2025

@kkemple

Replace --auto-approve flag with component-specific flags

This change allows users to selectively upgrade components rather than using a single auto-approve flag.

Implementation Review

  • โœ… Flag Definition: Implemented with clear, descriptive flag names and helpful descriptions
  • โœ… Component Logic: The InstallUpdatesWithComponentFlags method correctly selects which components to update based on flags
  • โœ… Documentation: All examples, help text, and reference docs have been updated to reflect the new flags
  • โœ… Tests: Comprehensive tests cover all combinations and edge cases
  • โœ… Code Cleanup: Removed the unused InstallUpdatesWithoutPrompt method and its tests since it was only created in this

@kkemple

Once we're code complete here and everything looks good, I'll work on the e2e test!

zimeg

Choose a reason for hiding this comment

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

๐Ÿ‘๏ธโ€๐Ÿ—จ๏ธ Quick note on some confusion I'm finding in outputs when testing this. I hope to review the code changes soon, but want to make sure this is updating as expected first!

Choose a reason for hiding this comment

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

๐Ÿ“ Before this merges I think we will want to make a separate PR for these rules.

It might also be worth considering our review process for these, but I'm favoring quick review with welcomed follow up. Saving more rambles for the other PR though ๐Ÿซก

}, "\n"),
Example: style.ExampleCommandsf([]style.ExampleCommand{
{Command: "upgrade", Meaning: "Check for any available updates"},
{Command: "upgrade --cli", Meaning: "Check for CLI updates and automatically upgrade without confirmation"},

Choose a reason for hiding this comment

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

๐Ÿค” For some reason this flag is causing me to update twice which doesn't seem to be happening in earlier versions. This might be due to my setups, but please let me know if this is unexpected!

$ lack update --cli

๐ŸŒฑ A new version of the Slack CLI is available:
   v3.1.0-26-g24ec54b โ†’ 3.1.0

   You can read the release notes at:
   https://docs.slack.dev/changelog

   To manually update, visit the download page:
   https://tools.slack.dev/slack-cli

โœ“ Installing update automatically...
   Starting the auto-update...
   Downloading version 3.1.0...
   Found current install path: /Users/eden.zimbelman/programming/tools/slack-cli/bin/slack
   Extracting the download: /Users/eden.zimbelman/.slack/bin/3.1.0
   Backing up current install: /Users/eden.zimbelman/.slack/bin/backups/v3.1.0-26-g24ec54b
   Updating to version 3.1.0: /Users/eden.zimbelman/programming/tools/slack-cli/bin/slack
   Successfully updated to version 3.1.0
   Verifying the update...

๐ŸŒฑ A new version of the Slack CLI is available:
   v3.1.0-26-g24ec54b โ†’ 3.1.0

   You can read the release notes at:
   https://docs.slack.dev/changelog

   To manually update, visit the download page:
   https://tools.slack.dev/slack-cli

   Starting the auto-update...
   Downloading version 3.1.0...
   Found current install path: /Users/eden.zimbelman/programming/tools/slack-cli/bin/slack
   Extracting the download: /Users/eden.zimbelman/.slack/bin/3.1.0
   Backing up current install: /Users/eden.zimbelman/.slack/bin/backups/v3.1.0-26-g24ec54b
   Updating to version 3.1.0: /Users/eden.zimbelman/programming/tools/slack-cli/bin/slack
   Successfully updated to version 3.1.0
   Verifying the update...
$ lack version
Using lack v3.1.0

Choose a reason for hiding this comment

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

back on this today! will have to try it out locally and see what's going on!

lukegalbraithrussell

--cli automatically approve and install CLI updates without prompting
-h, --help help for upgrade
--sdk automatically approve and install SDK updates without prompting
```

Choose a reason for hiding this comment

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

these docs are auto-generated, updating in source will update this page

@zimeg zimeg mentioned this pull request

Mar 16, 2026

2 tasks

Labels

enhancement

M-T: A feature request for new functionality