diff options
| author | diogo464 <[email protected]> | 2022-02-15 19:00:00 +0000 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2022-02-15 19:00:00 +0000 |
| commit | 2b04d646aec90e0fe28e84356b13758b8a956e8a (patch) | |
| tree | e7a742dc12a2eb39e26be71b9c08455aee6b3ac2 | |
| parent | d5abd94c24a6d4542bbdddc8a8d43a7de6f4eed5 (diff) | |
improved argument parsing
| -rw-r--r-- | src/main.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index 8c8e9dc..a56238e 100644 --- a/src/main.rs +++ b/src/main.rs | |||
| @@ -116,6 +116,7 @@ struct LinkArgs { | |||
| 116 | #[clap(long)] | 116 | #[clap(long)] |
| 117 | directory: bool, | 117 | directory: bool, |
| 118 | 118 | ||
| 119 | #[clap(min_values = 1)] | ||
| 119 | origins: Vec<PathBuf>, | 120 | origins: Vec<PathBuf>, |
| 120 | 121 | ||
| 121 | destination: PathBuf, | 122 | destination: PathBuf, |
| @@ -198,18 +199,15 @@ fn command_uninstall(global_flags: Flags, args: UninstallArgs) -> anyhow::Result | |||
| 198 | /// Moves files/directories and updates links. | 199 | /// Moves files/directories and updates links. |
| 199 | #[derive(Parser, Debug)] | 200 | #[derive(Parser, Debug)] |
| 200 | struct MvArgs { | 201 | struct MvArgs { |
| 201 | paths: Vec<PathBuf>, | 202 | #[clap(min_values = 1)] |
| 203 | origins: Vec<PathBuf>, | ||
| 204 | |||
| 205 | destination: PathBuf, | ||
| 202 | } | 206 | } |
| 203 | 207 | ||
| 204 | fn command_mv(global_flags: Flags, args: MvArgs) -> anyhow::Result<()> { | 208 | fn command_mv(global_flags: Flags, args: MvArgs) -> anyhow::Result<()> { |
| 205 | let mut dotup = utils::read_dotup(&global_flags)?; | 209 | let mut dotup = utils::read_dotup(&global_flags)?; |
| 206 | let mut paths = args.paths; | 210 | dotup.mv(args.origins.into_iter(), args.destination); |
| 207 | if paths.len() < 2 { | ||
| 208 | return Err(anyhow::anyhow!("mv requires atleast 2 arguments")); | ||
| 209 | } | ||
| 210 | let to = paths.pop().unwrap(); | ||
| 211 | let from = paths; | ||
| 212 | dotup.mv(from.iter(), &to); | ||
| 213 | utils::write_dotup(&dotup)?; | 211 | utils::write_dotup(&dotup)?; |
| 214 | Ok(()) | 212 | Ok(()) |
| 215 | } | 213 | } |
