Skip to content

Commit

Permalink
Search extensions directory for fluvio extensions rather than PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
simlay committed Nov 24, 2020
1 parent 2639684 commit 07021e4
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 19 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -u
set -o pipefail

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

# Ensure that this architecture is supported and matches the
Expand Down Expand Up @@ -507,6 +508,7 @@ main() {
# After verification, install the file and make it executable
say "⬇️ Downloaded Fluvio, installing..."
ensure mkdir -p "${FLUVIO_BIN}"
ensure mkdir -p "${FLUVIO_EXTENSIONS}"
local _install_file="${FLUVIO_BIN}/fluvio"
ensure mv "${_temp_file}" "${_install_file}"
ensure chmod +x "${_install_file}"
Expand Down
1 change: 1 addition & 0 deletions src/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ color-eyre = "0.5.5"
which = "4.0.2"
sha2 = "0.9.1"
hex = "0.4.2"
home = "0.5.3"

# Fluvio dependencies

Expand Down
18 changes: 15 additions & 3 deletions src/cli/src/install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@ use crate::CliError;
pub mod update;
pub mod plugins;

fn fluvio_bin_dir() -> Result<PathBuf, CliError> {
pub(crate) fn fluvio_extensions_dir() -> Result<PathBuf, CliError> {
if let Ok(dir) = std::env::var("FLUVIO_DIR") {
// Assume this is like `~/.fluvio
let path = PathBuf::from(dir).join("extensions");
if path.exists() {
return Ok(path);
}
}

let home =
dirs::home_dir().ok_or_else(|| IoError::new(ErrorKind::NotFound, "Homedir not found"))?;
Ok(home.join(".fluvio/bin/"))
home::home_dir().ok_or_else(|| IoError::new(ErrorKind::NotFound, "Homedir not found"))?;
let path = home.join(".fluvio/extensions/");
if path.exists() {
return Ok(path);
}
Err(IoError::new(ErrorKind::NotFound, "Fluvio extensions directory not found").into())
}

/// Fetches the latest version of the package with the given ID
Expand Down
8 changes: 2 additions & 6 deletions src/cli/src/install/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use fluvio_index::{PackageId, HttpAgent, MaybeVersion};

use crate::CliError;
use crate::install::{
fetch_latest_version, fetch_package_file, fluvio_bin_dir, install_bin, install_println,
fetch_latest_version, fetch_package_file, fluvio_extensions_dir, install_bin, install_println,
};
use crate::install::update::{
check_update_required, prompt_required_update, check_update_available, prompt_available_update,
Expand Down Expand Up @@ -79,12 +79,8 @@ impl InstallOpt {
install_println("🔑 Downloaded and verified package file");

// Install the package to the ~/.fluvio/bin/ dir
let fluvio_dir = fluvio_bin_dir()?;
let fluvio_dir = fluvio_extensions_dir()?;
install_bin(&fluvio_dir, id.name.as_str(), &package_file)?;
install_println(format!(
"✅ Successfully installed ~/.fluvio/bin/{}",
&id.name
));

Ok("".to_string())
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli/src/install/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use semver::Version;
use fluvio_index::{PackageId, HttpAgent, MaybeVersion};
use crate::CliError;
use crate::install::{
fetch_latest_version, fetch_package_file, install_bin, fluvio_bin_dir, install_println,
fetch_latest_version, fetch_package_file, install_bin, fluvio_extensions_dir, install_println,
};

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

// Install the package to the ~/.fluvio/bin/ dir
let fluvio_dir = fluvio_bin_dir()?;
let fluvio_dir = fluvio_extensions_dir()?;
install_bin(&fluvio_dir, "fluvio", &package_file)?;
install_println(format!(
"✅ Successfully installed ~/.fluvio/bin/{}",
Expand Down
30 changes: 22 additions & 8 deletions src/cli/src/root_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,24 +286,38 @@ impl CompletionCmd {
}

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

// The external subcommand's name is given as the first argument, take it.
let cmd = args.remove(0);

// Check for a matching external command in the environment

let external_subcommand = format!("fluvio-{}", cmd);
let subcommand_path = match CanonicalPath::new(&external_subcommand) {
Ok(path) => path,
Err(WhichError::CannotFindBinaryPath) => {
let mut subcommand_path: Option<PathBuf> = None;

let fluvio_dir = crate::install::fluvio_extensions_dir()?;

if let Ok(entries) = fs::read_dir(&fluvio_dir) {
for entry in entries {
if let Ok(entry) = entry {
if entry.path().ends_with(&external_subcommand) {
subcommand_path = Some(entry.path());
break;
}
}
}
}
let subcommand_path = match subcommand_path {
Some(path) => path,
None => {
println!(
"Unable to find plugin '{}'. Make sure it is executable and in your PATH.",
&external_subcommand
"Unable to find plugin '{}'. Make sure it is installed in {:?}.",
&external_subcommand, fluvio_dir,
);
std::process::exit(1);
}
other => other?,
};

// Print the fully-qualified command to debug
Expand Down

0 comments on commit 07021e4

Please sign in to comment.