summaryrefslogtreecommitdiffstats
path: root/src/args.rs
diff options
context:
space:
mode:
authorStephan Dilly <dilly.stephan@gmail.com>2021-12-05 00:35:45 +0100
committerGitHub <noreply@github.com>2021-12-05 00:35:45 +0100
commit006cdd63738db91e6c3074439bfd561eb0b5eb9c (patch)
treeeece93d978ef7d85a7eee0f023a8346248ae5e71 /src/args.rs
parentecabee02da682dd972048f8e9df8cf09becc8e6a (diff)
support bare repos (#1028)
Diffstat (limited to 'src/args.rs')
-rw-r--r--src/args.rs32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/args.rs b/src/args.rs
index 67b2e294..6d2df0d8 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -1,5 +1,6 @@
use crate::bug_report;
use anyhow::{anyhow, Result};
+use asyncgit::sync::RepoPath;
use clap::{
crate_authors, crate_description, crate_name, crate_version,
App as ClapApp, Arg,
@@ -13,6 +14,7 @@ use std::{
pub struct CliArgs {
pub theme: PathBuf,
+ pub repo_path: RepoPath,
}
pub fn process_cmdline() -> Result<CliArgs> {
@@ -41,10 +43,17 @@ pub fn process_cmdline() -> Result<CliArgs> {
)
.arg(
Arg::with_name("directory")
- .help("Set the working directory")
+ .help("Set the git directory")
.short("d")
.long("directory")
.takes_value(true),
+ )
+ .arg(
+ Arg::with_name("workdir")
+ .help("Set the working directory")
+ .short("w")
+ .long("workdir")
+ .takes_value(true),
);
let arg_matches = app.get_matches();
@@ -55,20 +64,31 @@ pub fn process_cmdline() -> Result<CliArgs> {
if arg_matches.is_present("logging") {
setup_logging()?;
}
- if arg_matches.is_present("directory") {
- let directory =
- arg_matches.value_of("directory").unwrap_or(".");
- env::set_current_dir(directory)?;
- }
+
+ let workdir = arg_matches.value_of("workdir").map(PathBuf::from);
+ let gitdir = arg_matches
+ .value_of("directory")
+ .map_or_else(|| PathBuf::from("."), PathBuf::from);
+
+ #[allow(clippy::option_if_let_else)]
+ let repo_path = if let Some(w) = workdir {
+ RepoPath::Workdir { gitdir, workdir: w }
+ } else {
+ RepoPath::Path(gitdir)
+ };
+
let arg_theme =
arg_matches.value_of("theme").unwrap_or("theme.ron");
+
if get_app_config_path()?.join(arg_theme).is_file() {
Ok(CliArgs {
theme: get_app_config_path()?.join(arg_theme),
+ repo_path,
})
} else {
Ok(CliArgs {
theme: get_app_config_path()?.join("theme.ron"),
+ repo_path,
})
}
}