summaryrefslogtreecommitdiff
path: root/src/cli.vala.in
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-05-21 12:14:29 +0200
committerAylur <[email protected]>2024-05-21 12:14:29 +0200
commit76036a1adbd29235620020f524d0709f3cefe168 (patch)
treed851b1b4fb40bf67cb04c0cacff39a38c8074987 /src/cli.vala.in
init 0.1.0
Diffstat (limited to 'src/cli.vala.in')
-rw-r--r--src/cli.vala.in47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/cli.vala.in b/src/cli.vala.in
new file mode 100644
index 0000000..056a69d
--- /dev/null
+++ b/src/cli.vala.in
@@ -0,0 +1,47 @@
+private static bool version;
+private static bool help;
+
+private const OptionEntry[] options = {
+ { "version", 'v', OptionFlags.NONE, OptionArg.NONE, ref version, null, null },
+ { "help", 'h', OptionFlags.NONE, OptionArg.NONE, ref help, null, null },
+ { null },
+};
+
+int main(string[] argv) {
+ try {
+ var opts = new OptionContext();
+ opts.add_main_entries(options, null);
+ opts.set_help_enabled(false);
+ opts.set_ignore_unknown_options(false);
+ opts.parse(ref argv);
+ } catch (OptionError err) {
+ printerr (err.message);
+ return 1;
+ }
+
+ if (help) {
+ print("Cli client for astal-notifd\n\n");
+ print("Usage:\n");
+ print(" %s [flags] message\n\n", argv[0]);
+ print("Flags:\n");
+ print(" -h, --help Print this help and exit\n");
+ print(" -v, --version Print version number and exit\n");
+ return 0;
+ }
+
+ if (version) {
+ print("@VERSION@");
+ return 0;
+ }
+
+ var notifd = new AstalNotifd.Notifd();
+ notifd.notified.connect((id) => {
+ stdout.printf("%s\n", notifd.get_notification_json(id));
+ });
+ notifd.active.connect(() => {
+ foreach (var n in notifd.notifications)
+ stdout.printf("%s\n", n.to_json_string());
+ });
+ new MainLoop().run();
+ return 0;
+}