Skip to content

Commit

Permalink
Merge pull request #7 from ErichDonGubler/files-args
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Jul 11, 2023
2 parents 0c472d8 + 2625559 commit 2cb23d0
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO: move to `src/bin.rs`
use std::process::Command;
use std::{ffi::OsString, process::Command};

use clap::Parser;
use ezcmd::EasyCommand;
Expand All @@ -24,15 +24,21 @@ enum Subcommand {
base: Option<String>,
#[clap(flatten)]
config: PresetConfig,
#[clap(flatten)]
files: FileSelection,
},
/// Display local branches and, optionally, their upstreams.
Locals {
#[clap(flatten)]
config: PresetConfig,
#[clap(flatten)]
files: FileSelection,
},
Select {
/// Additional branches to include.
branches: Vec<String>,
#[clap(flatten)]
files: FileSelection,
},
}

Expand All @@ -49,6 +55,13 @@ struct PresetConfig {
select_last_tag: bool,
}

#[derive(Debug, Parser)]
struct FileSelection {
/// Files by which to filter history.
#[clap(raw(true))]
files: Vec<OsString>,
}

fn main() {
run(|| {
let Args { format, subcommand } = Args::parse();
Expand All @@ -59,6 +72,7 @@ fn main() {
select_pushes: false,
select_last_tag: false,
},
files: FileSelection { files: vec![] },
});
let current_branch = || {
stdout_lines(EasyCommand::new_with("git", |cmd| {
Expand Down Expand Up @@ -115,8 +129,12 @@ fn main() {

Ok(branches)
};
let branches = match subcommand {
Subcommand::Stack { base, config } => {
let (branches, files) = match subcommand {
Subcommand::Stack {
base,
config,
files: FileSelection { files },
} => {
let specified_base = base
.map(Ok)
.or_else(|| git_config("glimpse.base").transpose())
Expand All @@ -127,7 +145,7 @@ fn main() {
default
});

if let Some(current_branch) = current_branch()? {
let branches = if let Some(current_branch) = current_branch()? {
let mut config = config;
if current_branch == base {
config.select_upstreams = true;
Expand All @@ -142,12 +160,23 @@ fn main() {
let mut branches = branches(&config, &|cmd| cmd.arg(base))?;
branches.push("HEAD".to_owned());
branches
}
};
(branches, files)
}
Subcommand::Locals { config } => branches(&config, &|cmd| cmd)?,
Subcommand::Select { branches } => branches,
Subcommand::Locals {
config,
files: FileSelection { files },
} => (branches(&config, &|cmd| cmd)?, files),
Subcommand::Select {
branches,
files: FileSelection { files },
} => (branches, files),
};
log::debug!("showing graph for branches {branches:?}");
show_graph(format, branches.iter().map(|s| s.as_str()))
show_graph(
format,
branches.iter().map(|s| s.as_str()),
files.iter().map(|f| f.as_os_str()),
)
})
}

0 comments on commit 2cb23d0

Please sign in to comment.