cli: Treat first argument as name of release channel to use for the cli (#10856)

With this commit, it is now possible to invoke cli with a release
channel of bundle as an argument. E.g: `zed stable some_arguments` will
find CLI binary of Stable channel installed on your machine and invoke
it with `some_arguments` (so the first argument is essentially omitted).

Fixes #10851

Release Notes:

- CLI now accepts an optional name of release channel as it's first
argument. For example, `zed stable` will always use your Stable
installation's CLI. Trailing args are passed along.
This commit is contained in:
Piotr Osiewicz 2024-04-22 18:01:06 +02:00 committed by GitHub
parent 189cece03e
commit a111b959d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 64 additions and 8 deletions

View file

@ -2,7 +2,7 @@
#![deny(missing_docs)]
use std::env;
use std::{env, str::FromStr};
use gpui::{AppContext, Global, SemanticVersion};
use once_cell::sync::Lazy;
@ -18,11 +18,8 @@ static RELEASE_CHANNEL_NAME: Lazy<String> = if cfg!(debug_assertions) {
#[doc(hidden)]
pub static RELEASE_CHANNEL: Lazy<ReleaseChannel> =
Lazy::new(|| match RELEASE_CHANNEL_NAME.as_str() {
"dev" => ReleaseChannel::Dev,
"nightly" => ReleaseChannel::Nightly,
"preview" => ReleaseChannel::Preview,
"stable" => ReleaseChannel::Stable,
Lazy::new(|| match ReleaseChannel::from_str(&RELEASE_CHANNEL_NAME) {
Ok(channel) => channel,
_ => panic!("invalid release channel {}", *RELEASE_CHANNEL_NAME),
});
@ -149,3 +146,21 @@ impl ReleaseChannel {
}
}
}
/// Error indicating that release channel string does not match any known release channel names.
#[derive(Copy, Clone, Debug, Hash, PartialEq)]
pub struct InvalidReleaseChannel;
impl FromStr for ReleaseChannel {
type Err = InvalidReleaseChannel;
fn from_str(channel: &str) -> Result<Self, Self::Err> {
Ok(match channel {
"dev" => ReleaseChannel::Dev,
"nightly" => ReleaseChannel::Nightly,
"preview" => ReleaseChannel::Preview,
"stable" => ReleaseChannel::Stable,
_ => return Err(InvalidReleaseChannel),
})
}
}