forked from vieter-v/vieter
Switched to cli module; merged cli & vieter into single binary
This commit is contained in:
parent
09d0a40aae
commit
5b919ceeae
9 changed files with 167 additions and 65 deletions
40
src/git/git.v
Normal file
40
src/git/git.v
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
module git
|
||||
|
||||
import os
|
||||
import json
|
||||
|
||||
pub struct GitRepo {
|
||||
pub:
|
||||
url string [required]
|
||||
branch string [required]
|
||||
}
|
||||
|
||||
pub fn read_repos(path string) ?[]GitRepo {
|
||||
if !os.exists(path) {
|
||||
mut f := os.create(path) ?
|
||||
|
||||
defer {
|
||||
f.close()
|
||||
}
|
||||
|
||||
f.write_string('[]') ?
|
||||
|
||||
return []
|
||||
}
|
||||
|
||||
content := os.read_file(path) ?
|
||||
res := json.decode([]GitRepo, content) ?
|
||||
return res
|
||||
}
|
||||
|
||||
pub fn write_repos(path string, repos []GitRepo) ? {
|
||||
mut f := os.create(path) ?
|
||||
|
||||
defer {
|
||||
f.close()
|
||||
}
|
||||
|
||||
value := json.encode(repos)
|
||||
f.write_string(value) ?
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue