Skip to content

Commit 13ec1d6

Browse files
authored
Search extensions directory for fluvio extensions rather than PATH (#508)
1 parent 2639684 commit 13ec1d6

File tree

7 files changed

+54
-19
lines changed

7 files changed

+54
-19
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set -u
66
set -o pipefail
77

88
readonly FLUVIO_BIN="${HOME}/.fluvio/bin"
9+
readonly FLUVIO_EXTENSIONS="${HOME}/.fluvio/extensions"
910
readonly FLUVIO_LATEST_URL="https://packages.fluvio.io/v1/latest"
1011

1112
# Ensure that this architecture is supported and matches the
@@ -507,6 +508,7 @@ main() {
507508
# After verification, install the file and make it executable
508509
say "⬇️ Downloaded Fluvio, installing..."
509510
ensure mkdir -p "${FLUVIO_BIN}"
511+
ensure mkdir -p "${FLUVIO_EXTENSIONS}"
510512
local _install_file="${FLUVIO_BIN}/fluvio"
511513
ensure mv "${_temp_file}" "${_install_file}"
512514
ensure chmod +x "${_install_file}"

src/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ color-eyre = "0.5.5"
3838
which = "4.0.2"
3939
sha2 = "0.9.1"
4040
hex = "0.4.2"
41+
home = "0.5.3"
4142

4243
# Fluvio dependencies
4344

src/cli/src/install/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,22 @@ use crate::CliError;
99
pub mod update;
1010
pub mod plugins;
1111

12-
fn fluvio_bin_dir() -> Result<PathBuf, CliError> {
12+
pub(crate) fn fluvio_extensions_dir() -> Result<PathBuf, CliError> {
13+
if let Ok(dir) = std::env::var("FLUVIO_DIR") {
14+
// Assume this is like `~/.fluvio
15+
let path = PathBuf::from(dir).join("extensions");
16+
if path.exists() {
17+
return Ok(path);
18+
}
19+
}
20+
1321
let home =
14-
dirs::home_dir().ok_or_else(|| IoError::new(ErrorKind::NotFound, "Homedir not found"))?;
15-
Ok(home.join(".fluvio/bin/"))
22+
home::home_dir().ok_or_else(|| IoError::new(ErrorKind::NotFound, "Homedir not found"))?;
23+
let path = home.join(".fluvio/extensions/");
24+
if path.exists() {
25+
return Ok(path);
26+
}
27+
Err(IoError::new(ErrorKind::NotFound, "Fluvio extensions directory not found").into())
1628
}
1729

1830
/// Fetches the latest version of the package with the given ID

src/cli/src/install/plugins.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use fluvio_index::{PackageId, HttpAgent, MaybeVersion};
33

44
use crate::CliError;
55
use crate::install::{
6-
fetch_latest_version, fetch_package_file, fluvio_bin_dir, install_bin, install_println,
6+
fetch_latest_version, fetch_package_file, fluvio_extensions_dir, install_bin, install_println,
77
};
88
use crate::install::update::{
99
check_update_required, prompt_required_update, check_update_available, prompt_available_update,
@@ -79,12 +79,8 @@ impl InstallOpt {
7979
install_println("🔑 Downloaded and verified package file");
8080

8181
// Install the package to the ~/.fluvio/bin/ dir
82-
let fluvio_dir = fluvio_bin_dir()?;
82+
let fluvio_dir = fluvio_extensions_dir()?;
8383
install_bin(&fluvio_dir, id.name.as_str(), &package_file)?;
84-
install_println(format!(
85-
"✅ Successfully installed ~/.fluvio/bin/{}",
86-
&id.name
87-
));
8884

8985
Ok("".to_string())
9086
}

src/cli/src/install/update.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use semver::Version;
55
use fluvio_index::{PackageId, HttpAgent, MaybeVersion};
66
use crate::CliError;
77
use crate::install::{
8-
fetch_latest_version, fetch_package_file, install_bin, fluvio_bin_dir, install_println,
8+
fetch_latest_version, fetch_package_file, install_bin, fluvio_extensions_dir, install_println,
99
};
1010

1111
const FLUVIO_PACKAGE_ID: &str = "fluvio/fluvio";
@@ -48,7 +48,7 @@ async fn update_self(agent: &HttpAgent) -> Result<String, CliError> {
4848
install_println("🔑 Downloaded and verified package file");
4949

5050
// Install the package to the ~/.fluvio/bin/ dir
51-
let fluvio_dir = fluvio_bin_dir()?;
51+
let fluvio_dir = fluvio_extensions_dir()?;
5252
install_bin(&fluvio_dir, "fluvio", &package_file)?;
5353
install_println(format!(
5454
"✅ Successfully installed ~/.fluvio/bin/{}",

src/cli/src/root_cli.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -286,24 +286,38 @@ impl CompletionCmd {
286286
}
287287

288288
fn process_external_subcommand(mut args: Vec<String>) -> Result<()> {
289+
use std::fs;
289290
use std::process::Command;
290-
use which::{CanonicalPath, Error as WhichError};
291+
use std::path::PathBuf;
291292

292293
// The external subcommand's name is given as the first argument, take it.
293294
let cmd = args.remove(0);
294-
295295
// Check for a matching external command in the environment
296+
296297
let external_subcommand = format!("fluvio-{}", cmd);
297-
let subcommand_path = match CanonicalPath::new(&external_subcommand) {
298-
Ok(path) => path,
299-
Err(WhichError::CannotFindBinaryPath) => {
298+
let mut subcommand_path: Option<PathBuf> = None;
299+
300+
let fluvio_dir = crate::install::fluvio_extensions_dir()?;
301+
302+
if let Ok(entries) = fs::read_dir(&fluvio_dir) {
303+
for entry in entries {
304+
if let Ok(entry) = entry {
305+
if entry.path().ends_with(&external_subcommand) {
306+
subcommand_path = Some(entry.path());
307+
break;
308+
}
309+
}
310+
}
311+
}
312+
let subcommand_path = match subcommand_path {
313+
Some(path) => path,
314+
None => {
300315
println!(
301-
"Unable to find plugin '{}'. Make sure it is executable and in your PATH.",
302-
&external_subcommand
316+
"Unable to find plugin '{}'. Make sure it is installed in {:?}.",
317+
&external_subcommand, fluvio_dir,
303318
);
304319
std::process::exit(1);
305320
}
306-
other => other?,
307321
};
308322

309323
// Print the fully-qualified command to debug

0 commit comments

Comments
 (0)