forked from vieter-v/vieter
				
			CLI tool can now work with new repo UUIDs
							parent
							
								
									f44ce1c17f
								
							
						
					
					
						commit
						7eb0aa76e1
					
				| 
						 | 
				
			
			@ -42,28 +42,34 @@ pub fn cmd() cli.Command {
 | 
			
		|||
			},
 | 
			
		||||
			cli.Command{
 | 
			
		||||
				name: 'remove'
 | 
			
		||||
				required_args: 2
 | 
			
		||||
				usage: 'url branch'
 | 
			
		||||
				description: 'Remove a repository.'
 | 
			
		||||
				required_args: 1
 | 
			
		||||
				usage: 'id'
 | 
			
		||||
				description: 'Remove a repository that matches the given ID prefix.'
 | 
			
		||||
				execute: fn (cmd cli.Command) ? {
 | 
			
		||||
					config_file := cmd.flags.get_string('config-file') ?
 | 
			
		||||
					conf := env.load<Config>(config_file) ?
 | 
			
		||||
 | 
			
		||||
					remove(conf, cmd.args[0], cmd.args[1]) ?
 | 
			
		||||
					remove(conf, cmd.args[0]) ?
 | 
			
		||||
				}
 | 
			
		||||
			},
 | 
			
		||||
		]
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn list(conf Config) ? {
 | 
			
		||||
fn get_repos(conf Config) ?map[string]git.GitRepo {
 | 
			
		||||
	mut req := http.new_request(http.Method.get, '$conf.address/api/repos', '') ?
 | 
			
		||||
	req.add_custom_header('X-API-Key', conf.api_key) ?
 | 
			
		||||
 | 
			
		||||
	res := req.do() ?
 | 
			
		||||
	data := json.decode(response.Response<map[string]git.GitRepo>, res.text) ?
 | 
			
		||||
 | 
			
		||||
	for id, details in data.data {
 | 
			
		||||
	return data.data
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn list(conf Config) ? {
 | 
			
		||||
	repos := get_repos(conf) ?
 | 
			
		||||
 | 
			
		||||
	for id, details in repos {
 | 
			
		||||
		println("${id[..8]}\t$details.url\t$details.branch\t$details.arch")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -78,8 +84,28 @@ fn add(conf Config, url string, branch string, arch []string) ? {
 | 
			
		|||
	println(res.text)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn remove(conf Config, url string, branch string) ? {
 | 
			
		||||
	mut req := http.new_request(http.Method.delete, '$conf.address/api/repos?url=$url&branch=$branch',
 | 
			
		||||
fn remove(conf Config, id_prefix string) ? {
 | 
			
		||||
	repos := get_repos(conf) ?
 | 
			
		||||
 | 
			
		||||
	mut to_remove := []string{}
 | 
			
		||||
 | 
			
		||||
	for id, _ in repos {
 | 
			
		||||
		if id.starts_with(id_prefix) {
 | 
			
		||||
			to_remove << id
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if to_remove.len == 0 {
 | 
			
		||||
		eprintln("No repo found for given prefix.")
 | 
			
		||||
		exit(1)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if to_remove.len > 1 {
 | 
			
		||||
		eprintln("Multiple repos found for given prefix.")
 | 
			
		||||
		exit(1)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	mut req := http.new_request(http.Method.delete, '$conf.address/api/repos/${to_remove[0]}',
 | 
			
		||||
		'') ?
 | 
			
		||||
	req.add_custom_header('X-API-Key', conf.api_key) ?
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,7 +3,7 @@ api_key = "test"
 | 
			
		|||
download_dir = "data/downloads"
 | 
			
		||||
repo_dir = "data/repo"
 | 
			
		||||
pkg_dir = "data/pkgs"
 | 
			
		||||
# log_level = "DEBUG"
 | 
			
		||||
log_level = "DEBUG"
 | 
			
		||||
repos_file = "data/repos.json"
 | 
			
		||||
 | 
			
		||||
address = "http://localhost:8000"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue