You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nu-scripts/cntfy.nu

75 lines
1.5 KiB
Plaintext

#!/usr/bin/env nu
def main [
subcommand: string@subcommands
] {
if $subcommand == "help" {
print $"cntfy <subcommand>",
print ""
print "Subcommands: "
for subcommand in ( subcommands ) {
print ""
print $"(ansi {attr: b})($subcommand)(ansi reset)"
print ( help $"main ($subcommand)" )
}
} else {
let span = (metadata $subcommand).span;
error make {
msg: $"Unknown subcommand ($subcommand)",
label: {
text: "Unknown subcommand",
start: $span.start,
end: $span.end
}
}
}
}
def subcommands [] {
["publish"]
}
# Publishes a message
export def `main publish` [
topic: string
message: string
--title: string
--priority: number
--tags: list<string>
--actions: list<any>
--icon: string
] {
let cfg = ( get_config )
let request_body = ({
topic: $topic
title: $title
message: $message
tags: ( $tags | append ( hostname ) )
priority: $priority
actions: $actions
icon: $icon
} | to json )
http put -u $cfg.username -p $cfg.password $cfg.url $request_body
}
def get_config [] {
let cfg_path = ( $env.HOME | path join ".config/cntfy/config.toml" )
if ($cfg_path | path exists ) == false {
let span = (metadata $cfg_path).span
error make {
msg: $"Config file ($cfg_path) does not exist",
label: {
text: "This file does not exist",
start: $span.start,
end: $span.end
}
}
}
( $cfg_path | open )
}