Skip to content

Commit

Permalink
feat: Add command goose update to update goose CLI version (#1308)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Hancock <[email protected]>
  • Loading branch information
inmzhang and alexhancock authored Feb 26, 2025
1 parent fd3ebee commit 26348a6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/goose-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod agent_version;
pub mod configure;
pub mod info;
pub mod mcp;
pub mod update;
34 changes: 34 additions & 0 deletions crates/goose-cli/src/commands/update.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::process::Command;

use anyhow::Result;

const DOWNLOAD_SCRIPT_URL: &str =
"https://github.com/block/goose/releases/download/stable/download_cli.sh";

pub fn update(canary: bool, reconfigure: bool) -> Result<()> {
// Get the download script from github
let curl_output = Command::new("curl")
.arg("-fsSL")
.arg(DOWNLOAD_SCRIPT_URL)
.output()?;

if !curl_output.status.success() {
anyhow::bail!(
"Failed to download update script: {}",
std::str::from_utf8(&curl_output.stderr)?
);
}

let shell_str = std::str::from_utf8(&curl_output.stdout)?;

let update = Command::new("bash")
.arg("-c")
.arg(shell_str)
.env("CANARY", canary.to_string())
.env("CONFIGURE", reconfigure.to_string())
.spawn()?;

update.wait_with_output()?;

Ok(())
}
24 changes: 24 additions & 0 deletions crates/goose-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ enum Command {

/// List available agent versions
Agents(AgentCommand),

/// Update the Goose CLI version
#[command(about = "Update the goose CLI version")]
Update {
/// Update to canary version
#[arg(
short,
long,
help = "Update to canary version",
long_help = "Update to the latest canary version of the goose CLI, otherwise updates to the latest stable version."
)]
canary: bool,

/// Enforce to re-configure Goose during update
#[arg(short, long, help = "Enforce to re-configure goose during update")]
reconfigure: bool,
},
}

#[derive(clap::ValueEnum, Clone, Debug)]
Expand Down Expand Up @@ -234,6 +251,13 @@ async fn main() -> Result<()> {
cmd.run()?;
return Ok(());
}
Some(Command::Update {
canary,
reconfigure,
}) => {
goose_cli::commands::update::update(canary, reconfigure)?;
return Ok(());
}
None => {
Cli::command().print_help()?;
println!();
Expand Down
11 changes: 8 additions & 3 deletions documentation/docs/guides/updating-goose.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
sidebar_position: 2
---

# Updating Goose

import Tabs from '@theme/Tabs';
Expand All @@ -12,10 +13,15 @@ import Link from "@docusaurus/Link";
To update Goose to the latest stable version, reinstall using the instructions below
:::


<Tabs groupId="interface">
<TabItem value="cli" label="Goose CLI" default>
You can update Goose by running the [installation](/docs/getting-started/installation) script again:
You can update Goose by simply running:

```sh
goose update
```

Or you can run the [installation](/docs/getting-started/installation) script again:

```sh
curl -fsSL https://github.com/block/goose/releases/download/stable/download_cli.sh | CONFIGURE=false bash
Expand Down Expand Up @@ -49,4 +55,3 @@ To update Goose to the latest stable version, reinstall using the instructions b
</Tabs>

All configuration settings will remain the same, with Goose updated to the latest version.

0 comments on commit 26348a6

Please sign in to comment.