Move repo-tree functionality into own subcommand
This commit is contained in:
16
src/cmd.rs
16
src/cmd.rs
@@ -19,6 +19,20 @@ pub struct Opts {
|
||||
|
||||
#[derive(Parser)]
|
||||
pub enum SubCommand {
|
||||
#[clap(about = "Manage repositories")]
|
||||
Repos(Repos),
|
||||
#[clap(visible_alias = "wt", about = "Manage worktrees")]
|
||||
Worktree(Worktree),
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
pub struct Repos {
|
||||
#[clap(subcommand, name = "action")]
|
||||
pub action: ReposAction,
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
pub enum ReposAction {
|
||||
#[clap(
|
||||
visible_alias = "run",
|
||||
about = "Synchronize the repositories to the configured values"
|
||||
@@ -28,8 +42,6 @@ pub enum SubCommand {
|
||||
Find(Find),
|
||||
#[clap(about = "Show status of configured repositories")]
|
||||
Status(OptionalConfig),
|
||||
#[clap(visible_alias = "wt", about = "Manage worktrees")]
|
||||
Worktree(Worktree),
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
|
||||
@@ -797,7 +797,8 @@ pub fn run() {
|
||||
let opts = cmd::parse();
|
||||
|
||||
match opts.subcmd {
|
||||
cmd::SubCommand::Sync(sync) => {
|
||||
cmd::SubCommand::Repos(repos) => match repos.action {
|
||||
cmd::ReposAction::Sync(sync) => {
|
||||
let config = match config::read_config(&sync.config) {
|
||||
Ok(c) => c,
|
||||
Err(e) => {
|
||||
@@ -807,7 +808,7 @@ pub fn run() {
|
||||
};
|
||||
sync_trees(config);
|
||||
}
|
||||
cmd::SubCommand::Status(args) => match &args.config {
|
||||
cmd::ReposAction::Status(args) => match &args.config {
|
||||
Some(config_path) => {
|
||||
let config = match config::read_config(config_path) {
|
||||
Ok(c) => c,
|
||||
@@ -831,7 +832,7 @@ pub fn run() {
|
||||
show_single_repo_status(&dir, has_worktree);
|
||||
}
|
||||
},
|
||||
cmd::SubCommand::Find(find) => {
|
||||
cmd::ReposAction::Find(find) => {
|
||||
let path = Path::new(&find.path);
|
||||
if !path.exists() {
|
||||
print_error(&format!("Path \"{}\" does not exist", path.display()));
|
||||
@@ -857,6 +858,7 @@ pub fn run() {
|
||||
print!("{}", toml);
|
||||
}
|
||||
}
|
||||
},
|
||||
cmd::SubCommand::Worktree(args) => {
|
||||
let dir = match std::env::current_dir() {
|
||||
Ok(d) => d,
|
||||
|
||||
Reference in New Issue
Block a user