forked from infinyon/fluvio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces two utility commands for FVM used to check on the active version and listing installed versions. Use `fvm current` to print the active Fluvio Version and use `fvm show` to list installed Fluvio versions. ## Demo https://github.com/infinyon/fluvio/assets/34756077/a2327a63-1d9e-4ceb-86d3-02522de0aa42
- Loading branch information
1 parent
11d4cf0
commit 34fb9ab
Showing
15 changed files
with
292 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
crates/fluvio-version-manager/fixtures/version/0.10.15/fluvio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
echo "Fluvio Test Executable 0.10.15" |
6 changes: 6 additions & 0 deletions
6
crates/fluvio-version-manager/fixtures/version/0.10.15/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"channel": { | ||
"tag": "0.10.15" | ||
}, | ||
"version": "0.10.15" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
echo "Fluvio Test Executable STABLE" |
4 changes: 4 additions & 0 deletions
4
crates/fluvio-version-manager/fixtures/version/stable/manifest.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"channel": "stable", | ||
"version": "0.10.16" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Show Intalled Versions Command | ||
//! | ||
//! The `show` command is responsible of listing all the installed Fluvio Versions | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use colored::Colorize; | ||
|
||
use fluvio_hub_util::fvm::Channel; | ||
|
||
use crate::common::notify::Notify; | ||
use crate::common::settings::Settings; | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct CurrentOpt; | ||
|
||
impl CurrentOpt { | ||
pub async fn process(&self, notify: Notify) -> Result<()> { | ||
let settings = Settings::open()?; | ||
|
||
if let (Some(channel), Some(version)) = (settings.channel, settings.version) { | ||
match channel { | ||
Channel::Latest | Channel::Stable => println!("{} ({})", version, channel), | ||
Channel::Tag(_) => println!("{}", version), | ||
} | ||
} else { | ||
notify.warn("No active version set"); | ||
notify.help(format!( | ||
"You can use {} to set the active version", | ||
"fvm switch".bold() | ||
)); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod current; | ||
pub mod install; | ||
pub mod itself; | ||
pub mod show; | ||
pub mod switch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//! Show Intalled Versions Command | ||
//! | ||
//! The `show` command is responsible of listing all the installed Fluvio Versions | ||
use anyhow::{Result, anyhow}; | ||
use clap::Parser; | ||
use colored::Colorize; | ||
use comfy_table::{Table, Row}; | ||
|
||
use crate::common::manifest::VersionManifest; | ||
use crate::common::notify::Notify; | ||
use crate::common::settings::Settings; | ||
use crate::common::version_directory::VersionDirectory; | ||
use crate::common::workdir::fvm_versions_path; | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct ShowOpt; | ||
|
||
impl ShowOpt { | ||
pub async fn process(&self, notify: Notify) -> Result<()> { | ||
let versions_path = fvm_versions_path()?; | ||
|
||
if !versions_path.exists() { | ||
notify.warn("Cannot list installed versions because there are no versions installed"); | ||
notify.help(format!( | ||
"You can install a Fluvio version using the command {}", | ||
"fvm install".bold() | ||
)); | ||
|
||
return Err(anyhow!("No versions installed")); | ||
} | ||
|
||
let settings = Settings::open()?; | ||
let (manifests, maybe_active) = | ||
VersionDirectory::scan_versions_manifests(versions_path, settings.channel)?; | ||
|
||
if manifests.is_empty() && maybe_active.is_none() { | ||
notify.warn("No installed versions found"); | ||
notify.help(format!( | ||
"You can install a Fluvio version using the command {}", | ||
"fvm install".bold() | ||
)); | ||
|
||
return Ok(()); | ||
} | ||
|
||
Self::render_table(manifests, maybe_active); | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Creates a `Table` and renders it to the terminal. | ||
fn render_table(manifests: Vec<VersionManifest>, maybe_active: Option<VersionManifest>) { | ||
let mut table = Table::new(); | ||
|
||
table.set_header(Row::from([" ", "CHANNEL", "VERSION"])); | ||
|
||
if let Some(active) = maybe_active { | ||
table.add_row(Row::from([ | ||
"✓".to_string(), | ||
active.channel.to_string(), | ||
active.version.to_string(), | ||
])); | ||
} | ||
|
||
let mut sorted_manifests = manifests; | ||
sorted_manifests.sort_by(|a, b| b.channel.cmp(&a.channel)); | ||
|
||
for manifest in sorted_manifests { | ||
table.add_row(Row::from([ | ||
" ".to_string(), | ||
manifest.channel.to_string(), | ||
manifest.version.to_string(), | ||
])); | ||
} | ||
|
||
table.load_preset(comfy_table::presets::NOTHING); | ||
|
||
println!("{}", table); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.