Skip to content

Commit

Permalink
add: Show info about current geil state
Browse files Browse the repository at this point in the history
  • Loading branch information
Nukesor committed Oct 17, 2024
1 parent 970cee4 commit 427aa8b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ pub enum SubCommand {
directories: Vec<PathBuf>,
},

/// Print information about the current configuration of geil.
Info,

/// This is the main command of `geil`. This will:
/// - Fetch all branches from a remote
/// - Check stash sizes
Expand Down
38 changes: 38 additions & 0 deletions src/commands/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use anyhow::Result;

use crate::state::State;

pub fn print_info(state: &mut State) -> Result<()> {
if !state.watched.is_empty() {
println!("Watched folders:");
for watched in &state.watched {
println!(" - {watched:?}");
}
println!();
}

if !state.ignored.is_empty() {
println!("Ignored folders:");
for ignored in &state.ignored {
println!(" - {ignored:?}");
}
println!();
}

if !state.keys.is_empty() {
println!("Known keys:");
for key in &state.keys {
println!(" - {} ({:?})", key.name, key.path);
}
println!();
}

if !state.keys.is_empty() {
println!("Known repositories:\n");
for repo in &state.repositories {
println!(" - {:?}", repo.path);
}
}

Ok(())
}
2 changes: 2 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod add;
mod check;
mod ignore;
mod info;
mod remove;
mod unwatch;
mod update;
Expand All @@ -9,6 +10,7 @@ mod watch;
pub use add::*;
pub use check::*;
pub use ignore::*;
pub use info::*;
pub use remove::*;
pub use unwatch::*;
pub use update::*;
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fn main() -> Result<()> {
SubCommand::Watch { directories } => commands::watch(&mut state, &directories),
SubCommand::Unwatch { directories } => commands::unwatch(&mut state, &directories),
SubCommand::Ignore { directories } => commands::ignore(&mut state, &directories),
SubCommand::Info => commands::print_info(&mut state),
SubCommand::Update {
all,
not_parallel,
Expand Down
3 changes: 2 additions & 1 deletion src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ impl State {

impl State {
/// Save a state to the disk.
pub fn save(&self) -> Result<()> {
pub fn save(&mut self) -> Result<()> {
self.repositories.sort_by(|a, b| a.path.cmp(&b.path));
let path = default_cache_path()?;
let file = File::create(path)?;

Expand Down

0 comments on commit 427aa8b

Please sign in to comment.