A tool to help managing forked repos with their own history
1use anyhow::Result;
2use clap::{Parser, Subcommand};
3
4mod commands;
5mod config;
6mod git;
7mod patch;
8
9#[derive(Parser)]
10#[command(name = "forkme")]
11#[command(about = "A tool for managing forks using a patch-based approach")]
12#[command(version)]
13struct Cli {
14 #[command(subcommand)]
15 command: Commands,
16}
17
18#[derive(Subcommand)]
19enum Commands {
20 /// Initialize a forkme-managed project
21 Init {
22 /// URL of the upstream repository
23 #[arg(long)]
24 url: Option<String>,
25
26 /// Branch to track from upstream (default to main)
27 #[arg(long, default_value = "main")]
28 branch: String,
29
30 /// Limit the git cloning depth (optional)
31 #[arg(long)]
32 depth: Option<usize>,
33 },
34
35 /// Apply patches to the source directory
36 Apply,
37
38 /// Sync changes from source back to patches
39 Sync {
40 /// Ignore files that have uncommitted changes in the working tree
41 #[arg(long)]
42 ignore_uncommitted: bool,
43 },
44
45 /// Show the current status of the forkme project
46 Status,
47
48 /// Show statistics about patches
49 Stats,
50
51 /// Update: fetch upstream and rebase forkme branch
52 Update,
53}
54
55fn main() -> Result<()> {
56 let cli = Cli::parse();
57
58 match cli.command {
59 Commands::Init { url, branch, depth } => commands::init::run(url, &branch, depth)?,
60 Commands::Apply => commands::apply::run()?,
61 Commands::Sync { ignore_uncommitted } => commands::sync::run(ignore_uncommitted)?,
62 Commands::Status => commands::status::run()?,
63 Commands::Stats => commands::stats::run()?,
64 Commands::Update => commands::update::run()?,
65 }
66
67 Ok(())
68}