mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 18:48:33 -04:00
refactor(odin): ported deps command, added utilities (features, tty, table).
This commit is contained in:
1
cli.odin
1
cli.odin
@@ -13,6 +13,7 @@ Command :: struct {
|
|||||||
|
|
||||||
IMPLEMENTED_COMMANDS := []string{
|
IMPLEMENTED_COMMANDS := []string{
|
||||||
"version",
|
"version",
|
||||||
|
"deps",
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_args :: proc() -> (cmd: Command, ok: bool) {
|
parse_args :: proc() -> (cmd: Command, ok: bool) {
|
||||||
|
|||||||
@@ -97,6 +97,7 @@
|
|||||||
gotools
|
gotools
|
||||||
cobra-cli
|
cobra-cli
|
||||||
|
|
||||||
|
age
|
||||||
unstable.odin
|
unstable.odin
|
||||||
unstable.ols
|
unstable.ols
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ main :: proc() {
|
|||||||
switch cmd.name {
|
switch cmd.name {
|
||||||
case "version":
|
case "version":
|
||||||
cmd_version(&cmd)
|
cmd_version(&cmd)
|
||||||
|
case "deps":
|
||||||
|
cmd_deps(&cmd)
|
||||||
case:
|
case:
|
||||||
fmt.printf("Unknown command: %s\n", cmd.name)
|
fmt.printf("Unknown command: %s\n", cmd.name)
|
||||||
print_usage()
|
print_usage()
|
||||||
|
|||||||
18
table.odin
18
table.odin
@@ -9,14 +9,15 @@ render_table :: proc(headers: []string, rows: [][]string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
col_widths := make([dynamic]int, len(headers))
|
col_widths := make([dynamic]int, 0, len(headers))
|
||||||
for i in 0..<len(headers) {
|
for i in 0..<len(headers) {
|
||||||
append(&col_widths, len(headers[i]))
|
append(&col_widths, strings.rune_count(headers[i]))
|
||||||
}
|
}
|
||||||
for r in rows {
|
for r in rows {
|
||||||
for i in 0..<len(r) {
|
for i in 0..<len(r) {
|
||||||
if i < len(col_widths) && len(r[i]) > col_widths[i] {
|
w := strings.rune_count(r[i])
|
||||||
col_widths[i] = len(r[i])
|
if i < len(col_widths) && w > col_widths[i] {
|
||||||
|
col_widths[i] = w
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,9 +45,14 @@ render_table :: proc(headers: []string, rows: [][]string) {
|
|||||||
|
|
||||||
hline(&b, "\u250c", "\u252c", "\u2510", col_widths)
|
hline(&b, "\u250c", "\u252c", "\u2510", col_widths)
|
||||||
|
|
||||||
|
cell :: proc(b: ^strings.Builder, s: string, width: int) {
|
||||||
|
extra := len(s) - strings.rune_count(s)
|
||||||
|
fmt.sbprintf(b, " %-*s \u2502", width + extra, s)
|
||||||
|
}
|
||||||
|
|
||||||
strings.write_string(&b, "\u2502")
|
strings.write_string(&b, "\u2502")
|
||||||
for i in 0..<len(headers) {
|
for i in 0..<len(headers) {
|
||||||
fmt.sbprintf(&b, " %-*s \u2502", col_widths[i], headers[i])
|
cell(&b, headers[i], col_widths[i])
|
||||||
}
|
}
|
||||||
fmt.println(strings.to_string(b))
|
fmt.println(strings.to_string(b))
|
||||||
strings.builder_reset(&b)
|
strings.builder_reset(&b)
|
||||||
@@ -56,7 +62,7 @@ render_table :: proc(headers: []string, rows: [][]string) {
|
|||||||
for r in rows {
|
for r in rows {
|
||||||
strings.write_string(&b, "\u2502")
|
strings.write_string(&b, "\u2502")
|
||||||
for i in 0..<len(r) {
|
for i in 0..<len(r) {
|
||||||
fmt.sbprintf(&b, " %-*s \u2502", col_widths[i], r[i])
|
cell(&b, r[i], col_widths[i])
|
||||||
}
|
}
|
||||||
fmt.println(strings.to_string(b))
|
fmt.println(strings.to_string(b))
|
||||||
strings.builder_reset(&b)
|
strings.builder_reset(&b)
|
||||||
|
|||||||
Reference in New Issue
Block a user