# #
#############################################################################*/
+#include <errno.h>
+#include <getopt.h>
#include <stdio.h>
+#include <unistd.h>
#include <systemd/sd-bus.h>
-int main(int argc, char** argv) {
+static int version(void) {
+ printf("networkctl %s\n", PACKAGE_VERSION);
+
+ return 0;
+}
+
+static int help(void) {
+ printf(
+ "%s [OPTIONS...] COMMAND\n\n"
+ "Options:\n"
+ " -h --help Show help\n"
+ " --version Show version\n",
+ program_invocation_short_name
+ );
+
+ return 0;
+}
+
+static int parse_argv(int argc, char* argv[]) {
+ enum {
+ ARG_VERSION,
+ };
+
+ static const struct option options[] = {
+ { "help", no_argument, NULL, 'h' },
+ { "version", no_argument, NULL, ARG_VERSION },
+ { NULL },
+ };
+ int c;
+
+ for (;;) {
+ c = getopt_long(argc, argv, "h", options, NULL);
+ if (c < 0)
+ break;
+
+ switch (c) {
+ case 'h':
+ return help();
+
+ case ARG_VERSION:
+ return version();
+
+ case '?':
+ return -EINVAL;
+
+ default:
+ break;
+ }
+ }
+
+ return 0;
+}
+
+int main(int argc, char* argv[]) {
sd_bus* bus = NULL;
int r;
+ // Parse command line arguments
+ r = parse_argv(argc, argv);
+ if (r)
+ goto ERROR;
+
// Connect to system bus
r = sd_bus_open_system(&bus);
if (r < 0) {