-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
115 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use clap::CommandFactory; | ||
use fs_err as fs; | ||
use miette::Context; | ||
use miette::IntoDiagnostic; | ||
|
||
use crate::cli; | ||
use crate::cli::Opts; | ||
use crate::git::Git; | ||
|
||
pub struct App { | ||
git: Git, | ||
config: Opts, | ||
} | ||
|
||
impl App { | ||
pub fn new(config: Opts) -> Self { | ||
Self { | ||
config, | ||
git: Git::new(), | ||
} | ||
} | ||
|
||
pub fn run(self) -> miette::Result<()> { | ||
match &self.config.command { | ||
cli::Command::Completions { shell } => { | ||
let mut clap_command = cli::Opts::command(); | ||
clap_complete::generate( | ||
*shell, | ||
&mut clap_command, | ||
"git-prole", | ||
&mut std::io::stdout(), | ||
); | ||
} | ||
#[cfg(feature = "clap_mangen")] | ||
cli::Command::Manpages { out_dir } => { | ||
let clap_command = cli::Opts::command(); | ||
clap_mangen::generate_to(clap_command, out_dir) | ||
.into_diagnostic() | ||
.wrap_err("Failed to generate man pages")?; | ||
} | ||
cli::Command::Convert {} => self.convert()?, | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn convert(&self) -> miette::Result<()> { | ||
let working_dir = self.git.working_dir()?; | ||
let tempdir = tempfile::tempdir().into_diagnostic()?; | ||
|
||
// Figuring out which worktrees to create is non-trivial: | ||
// - We might have any number of remotes. Which one to use? | ||
// - We might already have the default branch checked out. | ||
// - We might _not_ have the default branch checked out. | ||
// - We might have unstaged/uncommitted work. | ||
// - We might not be on _any_ branch. | ||
|
||
// TODO: Ask the user before we start messing around with their repo layout! | ||
fs::rename(&working_dir, &tempdir).into_diagnostic()?; | ||
fs::create_dir_all(&working_dir).into_diagnostic()?; | ||
|
||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,15 @@ | ||
mod cli; | ||
mod commit_hash; | ||
mod git; | ||
mod install_tracing; | ||
|
||
use clap::CommandFactory; | ||
use clap::Parser; | ||
use cli::Opts; | ||
use install_tracing::install_tracing; | ||
|
||
#[allow(unused_imports)] | ||
use miette::Context; | ||
#[allow(unused_imports)] | ||
use miette::IntoDiagnostic; | ||
mod app; | ||
mod cli; | ||
mod commit_hash; | ||
mod git; | ||
mod install_tracing; | ||
|
||
fn main() -> miette::Result<()> { | ||
let opts = Opts::parse(); | ||
install_tracing(&opts.log)?; | ||
|
||
match opts.command { | ||
cli::Command::Completions { shell } => { | ||
let mut clap_command = cli::Opts::command(); | ||
clap_complete::generate( | ||
shell, | ||
&mut clap_command, | ||
"git-prole", | ||
&mut std::io::stdout(), | ||
); | ||
} | ||
#[cfg(feature = "clap_mangen")] | ||
cli::Command::Manpages { out_dir } => { | ||
let clap_command = cli::Opts::command(); | ||
clap_mangen::generate_to(clap_command, out_dir) | ||
.into_diagnostic() | ||
.wrap_err("Failed to generate man pages")?; | ||
} | ||
cli::Command::Add {} => todo!(), | ||
} | ||
|
||
Ok(()) | ||
app::App::new(opts).run() | ||
} |