diff --git a/src/cli.rs b/src/cli.rs index 3dd3422..5209c8f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -54,6 +54,9 @@ pub enum SubCommand { directories: Vec, }, + /// 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 diff --git a/src/commands/info.rs b/src/commands/info.rs new file mode 100644 index 0000000..99d2e56 --- /dev/null +++ b/src/commands/info.rs @@ -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(()) +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index c3e3703..5bed599 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,6 +1,7 @@ mod add; mod check; mod ignore; +mod info; mod remove; mod unwatch; mod update; @@ -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::*; diff --git a/src/main.rs b/src/main.rs index eecfb1a..6172b0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, diff --git a/src/state.rs b/src/state.rs index dd7968a..7d59fdb 100644 --- a/src/state.rs +++ b/src/state.rs @@ -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)?;