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)]
|
#[derive(Parser)]
|
||||||
pub enum SubCommand {
|
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(
|
#[clap(
|
||||||
visible_alias = "run",
|
visible_alias = "run",
|
||||||
about = "Synchronize the repositories to the configured values"
|
about = "Synchronize the repositories to the configured values"
|
||||||
@@ -28,8 +42,6 @@ pub enum SubCommand {
|
|||||||
Find(Find),
|
Find(Find),
|
||||||
#[clap(about = "Show status of configured repositories")]
|
#[clap(about = "Show status of configured repositories")]
|
||||||
Status(OptionalConfig),
|
Status(OptionalConfig),
|
||||||
#[clap(visible_alias = "wt", about = "Manage worktrees")]
|
|
||||||
Worktree(Worktree),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
|||||||
@@ -797,7 +797,8 @@ pub fn run() {
|
|||||||
let opts = cmd::parse();
|
let opts = cmd::parse();
|
||||||
|
|
||||||
match opts.subcmd {
|
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) {
|
let config = match config::read_config(&sync.config) {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -807,7 +808,7 @@ pub fn run() {
|
|||||||
};
|
};
|
||||||
sync_trees(config);
|
sync_trees(config);
|
||||||
}
|
}
|
||||||
cmd::SubCommand::Status(args) => match &args.config {
|
cmd::ReposAction::Status(args) => match &args.config {
|
||||||
Some(config_path) => {
|
Some(config_path) => {
|
||||||
let config = match config::read_config(config_path) {
|
let config = match config::read_config(config_path) {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
@@ -831,7 +832,7 @@ pub fn run() {
|
|||||||
show_single_repo_status(&dir, has_worktree);
|
show_single_repo_status(&dir, has_worktree);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cmd::SubCommand::Find(find) => {
|
cmd::ReposAction::Find(find) => {
|
||||||
let path = Path::new(&find.path);
|
let path = Path::new(&find.path);
|
||||||
if !path.exists() {
|
if !path.exists() {
|
||||||
print_error(&format!("Path \"{}\" does not exist", path.display()));
|
print_error(&format!("Path \"{}\" does not exist", path.display()));
|
||||||
@@ -857,6 +858,7 @@ pub fn run() {
|
|||||||
print!("{}", toml);
|
print!("{}", toml);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
cmd::SubCommand::Worktree(args) => {
|
cmd::SubCommand::Worktree(args) => {
|
||||||
let dir = match std::env::current_dir() {
|
let dir = match std::env::current_dir() {
|
||||||
Ok(d) => d,
|
Ok(d) => d,
|
||||||
|
|||||||
Reference in New Issue
Block a user