This commit is contained in:
parent
fcd3d6ffca
commit
ac07105bf7
6 changed files with 87 additions and 29 deletions
20
src/pkg.rs
20
src/pkg.rs
|
@ -4,6 +4,26 @@ pub struct Repository {
|
|||
pub name: String,
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
pub fn list() -> Vec<String> {
|
||||
let mut repos = vec![];
|
||||
|
||||
for entry in std::fs::read_dir("./data").unwrap() {
|
||||
let path = entry.unwrap().path();
|
||||
let file_name = path.file_name().unwrap().to_str().unwrap().to_string();
|
||||
repos.push(file_name);
|
||||
}
|
||||
|
||||
repos
|
||||
}
|
||||
|
||||
pub fn create(name: &str) -> Repository {
|
||||
let path = PathBuf::from("./data").join(name);
|
||||
std::fs::create_dir_all(path).unwrap();
|
||||
Repository::new(name).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Repository {
|
||||
pub fn new(name: &str) -> Option<Self> {
|
||||
if PathBuf::from("./data").join(name).exists() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue