forked from vieter-v/vieter
Compare commits
4 Commits
e29c188f76
...
5991b09528
| Author | SHA1 | Date |
|---|---|---|
|
|
5991b09528 | |
|
|
7c451d04c6 | |
|
|
341c94669c | |
|
|
1caccceda2 |
|
|
@ -1,56 +1 @@
|
||||||
module console
|
module console
|
||||||
|
|
||||||
import arrays
|
|
||||||
import strings
|
|
||||||
|
|
||||||
// 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
|
|
||||||
pub fn pretty_table(header []string, data [][]string) ?string {
|
|
||||||
column_count := header.len
|
|
||||||
|
|
||||||
mut column_widths := []int{len: column_count, init: header[it].len}
|
|
||||||
|
|
||||||
for values in data {
|
|
||||||
for col, value in values {
|
|
||||||
if column_widths[col] < value.len {
|
|
||||||
column_widths[col] = value.len
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
single_line_length := arrays.sum(column_widths)? + (column_count + 1) * 3 - 4
|
|
||||||
|
|
||||||
horizontal_line := '+' + strings.repeat(`-`, single_line_length) + '+'
|
|
||||||
mut buffer := strings.new_builder(data.len * single_line_length)
|
|
||||||
|
|
||||||
buffer.writeln(horizontal_line)
|
|
||||||
|
|
||||||
buffer.write_string('| ')
|
|
||||||
for col, head in header {
|
|
||||||
if col != 0 {
|
|
||||||
buffer.write_string(' | ')
|
|
||||||
}
|
|
||||||
buffer.write_string(head)
|
|
||||||
buffer.write_string(strings.repeat(` `, column_widths[col] - head.len))
|
|
||||||
}
|
|
||||||
buffer.writeln(' |')
|
|
||||||
|
|
||||||
buffer.writeln(horizontal_line)
|
|
||||||
|
|
||||||
for values in data {
|
|
||||||
buffer.write_string('| ')
|
|
||||||
for col, value in values {
|
|
||||||
if col != 0 {
|
|
||||||
buffer.write_string(' | ')
|
|
||||||
}
|
|
||||||
buffer.write_string(value)
|
|
||||||
buffer.write_string(strings.repeat(` `, column_widths[col] - value.len))
|
|
||||||
}
|
|
||||||
buffer.writeln(' |')
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer.writeln(horizontal_line)
|
|
||||||
|
|
||||||
return buffer.str()
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import cli
|
||||||
import env
|
import env
|
||||||
import cron.expression { parse_expression }
|
import cron.expression { parse_expression }
|
||||||
import client
|
import client
|
||||||
import console
|
|
||||||
|
|
||||||
struct Config {
|
struct Config {
|
||||||
address string [required]
|
address string [required]
|
||||||
|
|
@ -123,9 +122,10 @@ pub fn cmd() cli.Command {
|
||||||
fn list(conf Config) ? {
|
fn list(conf Config) ? {
|
||||||
c := client.new(conf.address, conf.api_key)
|
c := client.new(conf.address, conf.api_key)
|
||||||
repos := c.get_git_repos()?
|
repos := c.get_git_repos()?
|
||||||
data := repos.map([it.id.str(), it.url, it.branch, it.repo])
|
|
||||||
|
|
||||||
println(console.pretty_table(['id', 'url', 'branch', 'repo'], data)?)
|
for repo in repos {
|
||||||
|
println('$repo.id\t$repo.url\t$repo.branch\t$repo.repo')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add adds a new repository to the server's list.
|
// add adds a new repository to the server's list.
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import cli
|
||||||
import env
|
import env
|
||||||
import client
|
import client
|
||||||
import db
|
import db
|
||||||
import console
|
|
||||||
|
|
||||||
struct Config {
|
struct Config {
|
||||||
address string [required]
|
address string [required]
|
||||||
|
|
@ -67,11 +66,10 @@ pub fn cmd() cli.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
// print_log_list prints a list of logs.
|
// print_log_list prints a list of logs.
|
||||||
fn print_log_list(logs []db.BuildLog) ? {
|
fn print_log_list(logs []db.BuildLog) {
|
||||||
data := logs.map([it.id.str(), it.repo_id.str(), it.start_time.str(),
|
for log in logs {
|
||||||
it.exit_code.str()])
|
println('$log.id\t$log.start_time\t$log.exit_code')
|
||||||
|
}
|
||||||
println(console.pretty_table(['id', 'repo', 'start time', 'exit code'], data)?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// list prints a list of all build logs.
|
// list prints a list of all build logs.
|
||||||
|
|
@ -79,7 +77,7 @@ fn list(conf Config) ? {
|
||||||
c := client.new(conf.address, conf.api_key)
|
c := client.new(conf.address, conf.api_key)
|
||||||
logs := c.get_build_logs()?.data
|
logs := c.get_build_logs()?.data
|
||||||
|
|
||||||
print_log_list(logs)?
|
print_log_list(logs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// list prints a list of all build logs for a given repo.
|
// list prints a list of all build logs for a given repo.
|
||||||
|
|
@ -87,7 +85,7 @@ fn list_for_repo(conf Config, repo_id int) ? {
|
||||||
c := client.new(conf.address, conf.api_key)
|
c := client.new(conf.address, conf.api_key)
|
||||||
logs := c.get_build_logs_for_repo(repo_id)?.data
|
logs := c.get_build_logs_for_repo(repo_id)?.data
|
||||||
|
|
||||||
print_log_list(logs)?
|
print_log_list(logs)
|
||||||
}
|
}
|
||||||
|
|
||||||
// info print the detailed info for a given build log.
|
// info print the detailed info for a given build log.
|
||||||
|
|
|
||||||
|
|
@ -50,8 +50,6 @@ pub fn (mut d DockerDaemon) send_request_with_json<T>(method string, url urllib.
|
||||||
|
|
||||||
// read_response_head consumes the socket's contents until it encounters
|
// read_response_head consumes the socket's contents until it encounters
|
||||||
// '\r\n\r\n', after which it parses the response as an HTTP response.
|
// '\r\n\r\n', after which it parses the response as an HTTP response.
|
||||||
// Importantly, this function never consumes past the HTTP separator, so the
|
|
||||||
// body can be read fully later on.
|
|
||||||
pub fn (mut d DockerDaemon) read_response_head() ?http.Response {
|
pub fn (mut d DockerDaemon) read_response_head() ?http.Response {
|
||||||
mut c := 0
|
mut c := 0
|
||||||
mut buf := []u8{len: 4}
|
mut buf := []u8{len: 4}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +0,0 @@
|
||||||
module docker
|
|
||||||
|
|
||||||
import io
|
|
||||||
|
|
||||||
struct ChunkedResponseStream {
|
|
||||||
reader io.Reader
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue