| 121 | }, |
| 122 | } |
| 123 | pub fn handle_command() { |
| 124 | let cli = Cli::parse(); |
| 125 | match cli.command { |
| 126 | Command::Init => { |
| 127 | cmd::init().expect("初始化失败"); |
| 128 | } |
| 129 | Command::Add { files, all, update } => { |
| 130 | cmd::add(files, all, update); |
| 131 | } |
| 132 | Command::Rm { files, cached, recursive } => { |
| 133 | cmd::rm(files, cached, recursive).expect("删除失败"); |
| 134 | } |
| 135 | Command::Commit { message, allow_empty } => { |
| 136 | cmd::commit(message, allow_empty); |
| 137 | } |
| 138 | Command::Status => { |
| 139 | cmd::status(); |
| 140 | } |
| 141 | Command::Log { all, number } => { |
| 142 | cmd::log(all, number); |
| 143 | } |
| 144 | Command::Branch { list, delete, new_branch, commit_hash, show_current } => { |
| 145 | cmd::branch(new_branch, commit_hash, list, delete, show_current); |
| 146 | } |
| 147 | Command::Switch { branch, create, detach } => { |
| 148 | cmd::switch(branch, create, detach); |
| 149 | } |
| 150 | Command::Restore { path, source, mut worktree, staged } => { |
| 151 | // 未指定stage和worktree时,默认操作worktree |
| 152 | // 指定 --staged 将仅还原index |
| 153 | if !staged { |
| 154 | worktree = true; |
| 155 | } |
| 156 | // 未指定source 且 --staged,默认操作HEAD,否则从index中恢复(就近原则) |
| 157 | /* |
| 158 | If `--source` not specified, the contents are restored from `HEAD` if `--staged` is given, |
| 159 | otherwise from the [index]. |
| 160 | */ |
| 161 | cmd::restore(path, source, worktree, staged); |
| 162 | } |
| 163 | Command::Merge { branch } => { |
| 164 | cmd::merge(branch); |
| 165 | } |
| 166 | } |
| 167 | } |