1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use crate::{
registry::Registry,
result::{Error, Result},
};
use etc::{Etc, FileSystem, Write};
use std::{path::PathBuf, process::Command};
pub fn exec(edit: bool, git: String) -> Result<()> {
let mut registry = Registry::new()?;
let mut should_rewrite = false;
let cur_registry = PathBuf::from(®istry.dir);
let home = cur_registry
.parent()
.expect("Could not find the home of sup");
if edit {
Command::new("vi")
.arg(home.to_string_lossy().to_string())
.status()?;
return Ok(());
}
if !git.is_empty() && git.ne(®istry.config.node.registry) {
if !git.ends_with(".git") {
return Err(Error::Sup(format!("Wrong git url: {}", git)));
}
should_rewrite = true;
registry.config.node.registry = git;
}
if should_rewrite {
Etc::from(&home)
.open("config.toml")?
.write(toml::to_string(®istry.config)?)?;
return Ok(());
}
println!("{:#?}", registry.config);
Ok(())
}