Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
cablehead committed Jun 8, 2024
1 parent 9e39dd8 commit 9d7bddc
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions xs.nu
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@ alias ?? = ? else { return }
def build-query [params] {
$params | columns | each { |x|
let value = ($params | get $x)
let key = $x | str replace "_" "-"
match ( $value | describe ) {
"string" => $"($x)=($value)",
"bool" => (if $value { $x }),
"string" => $"($key)=($value)",
"bool" => (if $value { $key }),
}
} | and-then { $"?($in | str join "&")" }
}

def flatten-params [params] {
$params | columns | each {|name|
$params | get $name | and-then {
let value = $in
if $value == true {
[$name]
} else {
[$name, $value]
}

}
} | flatten
export def _cat [ store: string, flags: record ] {
let path = "/"
let query = ( build-query $flags )
let url = $"localhost($path)($query)"
curl -sN --unix-socket $"($store)/sock" $url | lines | each { from json }
}

export def cat [
Expand All @@ -32,10 +26,7 @@ export def cat [
--follow
--tail
] {
let path = "/"
let query = ( build-query { "last-id": $last_id, follow: $follow, tail: $tail } )
let url = $"localhost($path)($query)"
curl -sN --unix-socket $"($store)/sock" $url | lines | each { from json }
_cat $store { last_id: $last_id, follow: $follow, tail: $tail }
}

export def process [
Expand Down

0 comments on commit 9d7bddc

Please sign in to comment.