refactor(client): streamline code & improve error propagation
This commit is contained in:
parent
0bd5158608
commit
0727d0fd25
6 changed files with 29 additions and 67 deletions
|
|
@ -183,15 +183,7 @@ fn print_log_list(logs []BuildLog, raw bool) ! {
|
|||
// list prints a list of all build logs.
|
||||
fn list(conf Config, filter BuildLogFilter, raw bool) ! {
|
||||
c := client.new(conf.address, conf.api_key)
|
||||
logs := c.get_build_logs(filter)!.data
|
||||
|
||||
print_log_list(logs, raw)!
|
||||
}
|
||||
|
||||
// list prints a list of all build logs for a given target.
|
||||
fn list_for_target(conf Config, target_id int, raw bool) ! {
|
||||
c := client.new(conf.address, conf.api_key)
|
||||
logs := c.get_build_logs_for_target(target_id)!.data
|
||||
logs := c.get_build_logs(filter)!
|
||||
|
||||
print_log_list(logs, raw)!
|
||||
}
|
||||
|
|
@ -199,7 +191,7 @@ fn list_for_target(conf Config, target_id int, raw bool) ! {
|
|||
// info print the detailed info for a given build log.
|
||||
fn info(conf Config, id int) ! {
|
||||
c := client.new(conf.address, conf.api_key)
|
||||
log := c.get_build_log(id)!.data
|
||||
log := c.get_build_log(id)!
|
||||
|
||||
print(log)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -215,8 +215,7 @@ pub fn cmd() cli.Command {
|
|||
}
|
||||
|
||||
c := client.new(conf.address, conf.api_key)
|
||||
res := c.queue_job(target_id, arch, force)!
|
||||
println(res.message)
|
||||
c.queue_job(target_id, arch, force)!
|
||||
} else {
|
||||
build(conf, target_id, force)!
|
||||
}
|
||||
|
|
@ -245,23 +244,19 @@ fn list(conf Config, filter TargetFilter, raw bool) ! {
|
|||
// add adds a new repository to the server's list.
|
||||
fn add(conf Config, t &NewTarget, raw bool) ! {
|
||||
c := client.new(conf.address, conf.api_key)
|
||||
res := c.add_target(t)!
|
||||
target_id := c.add_target(t)!
|
||||
|
||||
if raw {
|
||||
println(res.data)
|
||||
println(target_id)
|
||||
} else {
|
||||
println('Target added with id $res.data')
|
||||
println('Target added with id $target_id')
|
||||
}
|
||||
}
|
||||
|
||||
// remove removes a repository from the server's list.
|
||||
fn remove(conf Config, id string) ! {
|
||||
id_int := id.int()
|
||||
|
||||
if id_int != 0 {
|
||||
c := client.new(conf.address, conf.api_key)
|
||||
c.remove_target(id_int)!
|
||||
}
|
||||
c := client.new(conf.address, conf.api_key)
|
||||
c.remove_target(id.int())!
|
||||
}
|
||||
|
||||
// patch patches a given repository with the provided params.
|
||||
|
|
@ -274,22 +269,13 @@ fn patch(conf Config, id string, params map[string]string) ! {
|
|||
}
|
||||
}
|
||||
|
||||
id_int := id.int()
|
||||
if id_int != 0 {
|
||||
c := client.new(conf.address, conf.api_key)
|
||||
c.patch_target(id_int, params)!
|
||||
}
|
||||
c := client.new(conf.address, conf.api_key)
|
||||
c.patch_target(id.int(), params)!
|
||||
}
|
||||
|
||||
// info shows detailed information for a given repo.
|
||||
fn info(conf Config, id string) ! {
|
||||
id_int := id.int()
|
||||
|
||||
if id_int == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
c := client.new(conf.address, conf.api_key)
|
||||
repo := c.get_target(id_int)!
|
||||
repo := c.get_target(id.int())!
|
||||
println(repo)
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue