Update scripts to use cntfy as a library

main
trivernis 1 year ago
parent 0606d3fed9
commit 45ecf8c376
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

46
cntfy

@ -0,0 +1,46 @@
#!/usr/bin/env nu
use ./cntfy.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 with certain properties
def `main publish` [
topic: string
message: string
--title: string
--priority: number
--tags: list<string>
--actions: list<any>
--icon: string
] {
cntfy publish $topic $message --title $title --priority $priority --tags $tags --actions $actions --icon $icon
}

@ -1,37 +1,5 @@
#!/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 # Publishes a message
export def `main publish` [ export def publish [
topic: string topic: string
message: string message: string
--title: string --title: string

@ -11,6 +11,8 @@ def main [
msg: "This script needs to be run as root" msg: "This script needs to be run as root"
} }
} }
pacman -Sy
let updates = ( checkupdates | split row "\n" ) let updates = ( checkupdates | split row "\n" )
let update_count = ( $updates | length ) let update_count = ( $updates | length )
@ -28,7 +30,7 @@ def main [
} else { } else {
$update_msg = ( $updates | str join "\n" ) $update_msg = ( $updates | str join "\n" )
} }
cntfy main publish --title $"($update_count) package[s] need to be updated" updates $update_msg cntfy publish --title $"($update_count) package[s] need to be updated" updates $update_msg
} }
} }
} }
Loading…
Cancel
Save