diff options
author | noname <[email protected]> | 2025-02-27 15:08:15 +1100 |
---|---|---|
committer | noname <[email protected]> | 2025-03-03 22:06:48 +1100 |
commit | bfceeb515a928de6ad901a1435b8e5bbc26eb64d (patch) | |
tree | c8513f519ec15345c3dd95dca9be873da43248f6 /lib/sway/cli.vala | |
parent | 4b283b0045c0752c36c6e8306fc137f2c9f244a4 (diff) |
test
Diffstat (limited to 'lib/sway/cli.vala')
-rw-r--r-- | lib/sway/cli.vala | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/sway/cli.vala b/lib/sway/cli.vala new file mode 100644 index 0000000..c51264b --- /dev/null +++ b/lib/sway/cli.vala @@ -0,0 +1,50 @@ +static bool help; +static bool version; +static bool monitor; + +const OptionEntry[] options = { + { "version", 'v', OptionFlags.NONE, OptionArg.NONE, ref version, null, null }, + { "help", 'h', OptionFlags.NONE, OptionArg.NONE, ref help, null, null }, + { "monitor", 'm', OptionFlags.NONE, OptionArg.NONE, ref monitor, 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("Usage:\n"); + print(" %s [flags]\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"); + print(" -m, --monitor Monitor property changes\n"); + return 0; + } + + if (version) { + print(AstalBattery.VERSION); + return 0; + } + + var battery = AstalBattery.get_default(); + print("%s\n", Json.gobject_to_data(battery, null)); + + if (monitor) { + battery.notify.connect(() => { + print("%s\n", Json.gobject_to_data(battery, null)); + }); + new GLib.MainLoop(null, false).run(); + } + + return 0; +} |