Compare commits

..

No commits in common. "8a08788935bb9514007f41d17d18cb2d1b879ecf" and "b6cd2f0bc280dfddfa85a91188ebe05433eabbf8" have entirely different histories.

5 changed files with 23 additions and 45 deletions

View File

@ -5,11 +5,6 @@ import strings
import cli
import os
// tabbed_table returns a simple textual table, with tabs as separators.
pub fn tabbed_table(data [][]string) string {
return data.map(it.join('\t')).join('\n')
}
// pretty_table converts a list of string data into a pretty table. Many thanks
// to @hungrybluedev in the Vlang Discord for providing this code!
// https://ptb.discord.com/channels/592103645835821068/592106336838352923/970278787143045192

View File

@ -133,9 +133,7 @@ pub fn cmd() cli.Command {
]
}
raw := cmd.flags.get_bool('raw')?
list(conf, filter, raw)?
list(conf, filter)?
}
},
cli.Command{
@ -169,31 +167,27 @@ pub fn cmd() cli.Command {
}
// print_log_list prints a list of logs.
fn print_log_list(logs []BuildLog, raw bool) ? {
fn print_log_list(logs []BuildLog) ? {
data := logs.map([it.id.str(), it.target_id.str(), it.start_time.local().str(),
it.exit_code.str()])
if raw {
println(console.tabbed_table(data))
} else {
println(console.pretty_table(['id', 'target', 'start time', 'exit code'], data)?)
}
println(console.pretty_table(['id', 'target', 'start time', 'exit code'], data)?)
}
// list prints a list of all build logs.
fn list(conf Config, filter BuildLogFilter, raw bool) ? {
fn list(conf Config, filter BuildLogFilter) ? {
c := client.new(conf.address, conf.api_key)
logs := c.get_build_logs(filter)?.data
print_log_list(logs, raw)?
print_log_list(logs)?
}
// list prints a list of all build logs for a given target.
fn list_for_target(conf Config, target_id int, raw bool) ? {
fn list_for_target(conf Config, target_id int) ? {
c := client.new(conf.address, conf.api_key)
logs := c.get_build_logs_for_target(target_id)?.data
print_log_list(logs, raw)?
print_log_list(logs)?
}
// info print the detailed info for a given build log.

View File

@ -60,9 +60,7 @@ pub fn cmd() cli.Command {
filter.repo = repo
}
raw := cmd.flags.get_bool('raw')?
list(conf, filter, raw)?
list(conf, filter)?
}
},
cli.Command{
@ -195,16 +193,12 @@ pub fn cmd() cli.Command {
// ID. If multiple or none are found, an error is raised.
// list prints out a list of all repositories.
fn list(conf Config, filter TargetFilter, raw bool) ? {
fn list(conf Config, filter TargetFilter) ? {
c := client.new(conf.address, conf.api_key)
repos := c.get_targets(filter)?
data := repos.map([it.id.str(), it.kind, it.url, it.repo])
if raw {
println(console.tabbed_table(data))
} else {
println(console.pretty_table(['id', 'kind', 'url', 'repo'], data)?)
}
println(console.pretty_table(['id', 'kind', 'url', 'repo'], data)?)
}
// add adds a new repository to the server's list.

View File

@ -24,13 +24,6 @@ fn main() {
global: true
default_value: [os.expand_tilde_to_home('~/.vieterrc')]
},
cli.Flag{
flag: cli.FlagType.bool
name: 'raw'
abbrev: 'r'
description: 'Only output minimal information (no formatted tables, etc.)'
global: true
},
]
commands: [
server.cmd(),

View File

@ -1,6 +1,8 @@
module server
import web
import net.http
import web.response { new_response }
// delete_package tries to remove the given package.
['/:repo/:arch/:pkg'; auth; delete]
@ -8,17 +10,17 @@ fn (mut app App) delete_package(repo string, arch string, pkg string) web.Result
res := app.repo.remove_pkg_from_arch_repo(repo, arch, pkg, true) or {
app.lerror('Error while deleting package: $err.msg()')
return app.status(.internal_server_error)
return app.json(http.Status.internal_server_error, new_response('Failed to delete package.'))
}
if res {
app.linfo("Removed package '$pkg' from '$repo/$arch'")
return app.status(.ok)
return app.json(http.Status.ok, new_response('Package removed.'))
} else {
app.linfo("Tried removing package '$pkg' from '$repo/$arch', but it doesn't exist.")
return app.status(.not_found)
return app.json(http.Status.not_found, new_response('Package not found.'))
}
}
@ -28,17 +30,17 @@ fn (mut app App) delete_arch_repo(repo string, arch string) web.Result {
res := app.repo.remove_arch_repo(repo, arch) or {
app.lerror('Error while deleting arch-repo: $err.msg()')
return app.status(.internal_server_error)
return app.json(http.Status.internal_server_error, new_response('Failed to delete arch-repo.'))
}
if res {
app.linfo("Removed arch-repo '$repo/$arch'")
app.linfo("Removed '$repo/$arch'")
return app.status(.ok)
return app.json(http.Status.ok, new_response('Arch-repo removed.'))
} else {
app.linfo("Tried removing '$repo/$arch', but it doesn't exist.")
return app.status(.not_found)
return app.json(http.Status.not_found, new_response('Arch-repo not found.'))
}
}
@ -48,16 +50,16 @@ fn (mut app App) delete_repo(repo string) web.Result {
res := app.repo.remove_repo(repo) or {
app.lerror('Error while deleting repo: $err.msg()')
return app.status(.internal_server_error)
return app.json(http.Status.internal_server_error, new_response('Failed to delete repo.'))
}
if res {
app.linfo("Removed repo '$repo'")
app.linfo("Removed '$repo'")
return app.status(.ok)
return app.json(http.Status.ok, new_response('Repo removed.'))
} else {
app.linfo("Tried removing '$repo', but it doesn't exist.")
return app.status(.not_found)
return app.json(http.Status.not_found, new_response('Repo not found.'))
}
}